Re: [stella] bouncing ball

Subject: Re: [stella] bouncing ball
From: Jeff Johnston <jeffryj@xxxxxxxxxxxxx>
Date: Sat, 6 Jul 2002 12:33:26 -0700 (MST)
It worked!  I had to add a little debounce routine (I wonder if this is
where they got the word), it would sometimes hit the paddle then detect
another hit and so it would keep going in the same direction :P ..  with
the debounce it ignores any new hits for a couple frames afterward.

Now I need to figure out how to draw the score properly.  Grafting in the
Combat score code didn't seem to work for some reason.  The score lines
were completely distorted.  I don't want a high tech looking score, the
old combat/asteroids score will look better for pong :)  I'm gonna keep
working at it, but if there is a ready-made example somewhere, please
point it out to me.

Thanks,
calamari


On Sat, 6 Jul 2002, Jeff  Johnston wrote:

>
> I think I may have figure out an easy way to compute this without the
> polar code (although that demo sure is cool :):
>
> When a ball hits the paddle, it's hitting a round object, but we can
> pretend that it is hitting a flat object.  The slope of the
> flat line that the ball is hitting is going to be equal to the angle of
> that point of the circle (angle 0-255).
>
> My understanding of the result of a ball bouncing against a flat object is
> that the ball's exit angle is reflected around the angle of the object it
> hits.
>
> Example:
> Ball direction, 128 degrees (256 "degrees" per circle)
> Paddle angle, 144 degrees
> So the difference in angles is 144-128=16 degrees
> 144+16=160 degrees.
> But the ball also needs to change direction "180" (128) degrees, so:
> 160+128=288=>32 degrees
> The ball goes in at 128 degrees, comes back at 32 degrees.
>
> To draw the ball traveling at a certain angle could be hard without the
> polar code, except if we construct a primitive line algorithm (here is my
> qbasic version for proof of concept).. none of the math involved is hard
> for the 6502 to do:
>
> SCREEN 13
> FOR ANGLE=0 TO TO 255
>   GOSUB TRACE
> NEXT ANGLE
> DO:LOOP WHILE INKEY$=""
> SCREEN 0:WIDTH 80
> END
>
> TRACE:
>   DEVIATION=0:BALLX=100:BALLY=100
>   FOR A=1 TO 100 'in the real game there wouldn't be a set distance
>     'find the best angle for now (out of 0, 32, 64, 96, 128, 160, 192, 224)
>     BEST=ANGLE+DEVIATIO
>     BEST=INT(BEST/32) 'same as shifting right
>     'CINT would have been more accurate above, but that's harder
>     BEST=BEST*32 'same as shifting left
>     'update the deviation from our desired angle
>     DEVIATION=ANGLE+DEVIATION-BEST
>     'move ball
>     IF BEST>=32 AND BEST<=96 THEN BALLX=BALLX+1
>     IF BEST>=96 AND BEST<=160 THEN BALLY=BALLY-1
>     IF BEST>=160 AND BEST<=224 THEN BALLX=BALLX-1
>     IF BEST>=224 OR BEST<=32 THEN BALLY=BALLY+1
>     'draw ball
>     PSET (BALLX,BALLY)
>   NEXT A
> RETURN
>
> Now I'm going to put this in.. we'll see how it goes :)
> calamari
>
> ----------------------------------------------------------------------------------------------
> Archives (includes files) at http://www.biglist.com/lists/stella/archives/
> Unsub & more at http://www.biglist.com/lists/stella/
>

----------------------------------------------------------------------------------------------
Archives (includes files) at http://www.biglist.com/lists/stella/archives/
Unsub & more at http://www.biglist.com/lists/stella/


Current Thread