After seeing a comment on another thread about not knowing how to perform smooth acceleration of objects, I decided to throw together a quick demo of how I implement such things.
This may not be the most idiomatic IntyBASIC code. But, looking at the compiled output, it's not too bad.
nanochess: If you think this is worth including in the contrib directory, be my guest.
The heart of the code is the UpdatePhysics procedure. It implements some really straightforward equations:
Velocity1 = Velocity0 + Acceleration
Position1 = Position0 + Velocity1
The devil, of course, is in the details: Shifting, rounding, handling signed vs. unsigned values, and of course, handling wraparound on the screen.
'' ======================================================================== '' '' UpdatePhysics '' '' '' '' This computes the new position and velocity given the current velocity '' '' and acceleration. '' '' '' '' AX, AY give the new acceleration input for the selected object. '' '' The acceleration inputs are zero for all other objects. '' '' ======================================================================== '' UpdatePhysics: PROCEDURE ' Compute new velocity for selected object. #V = VX(SEL) + AX IF #V > 127 THEN #V = 127 IF #V < -127 THEN #V = -127 VX(SEL) = #V #V = VY(SEL) + AY IF #V > 127 THEN #V = 127 IF #V < -127 THEN #V = -127 VY(SEL) = #V ' Compute new position for all 8 objects. FOR I = 0 to 7 #V = VX(I) * 4 #PX(I) = #V + #PX(I) ' Stay on visible display by keeping X in [0, 168]. IF #PX(I) >= 168*256 THEN #PX(I) = (168*256 XOR (#V > 0)) + #PX(I) #V = VY(I) * 4 #PY(I) = #V + #PY(I) ' Stay on visible display by keeping Y in [0, 104]. IF #PY(I) >= 104*256 THEN #PY(I) = (104*256 XOR (#V > 0)) + #PY(I) NEXT I END
Also, the code implements its own 16-direction disc direction decoder, since I didn't see how to do that with IntyBASIC's built-in primitives. I wanted to be sure I clearly separated each input into keypad vs. action vs. disc, while also supporting all 16 directions. So, I sample CONT once (ok, technically twice), and do the rest of the decode myself. This gave more consistent results than when I sampled CONT multiple times.