Hello everybody,
many of you will know the Pong like game tutorial over at NA. After a long break, I am now continuing those lessons by creating my own pong game.
I created a nice playing field where my ball bounces around. I also managed to add the functionality of increasing the speed. But here is where the problem lies. I also asked this over at NA, but it doesn't hurt to also ask here.
I changed the ball speed to 2/3/4/5/6 to make it go faster. So instead of moving 1 pixel a time, I move 2/3/4/5/6 pixels a time.
But at these higher speeds, the ball will change direction before or after the "walls" I programmed.
They seem to have an offset. For the right and top wall it will change direction before it should hit the wall. And for the left and bottom wall it will change direction after it should hit the wall. (I think) I know why it does this ==> If the ball is, for example, 1 pixel before the wall ==> No collision ==> Increase the position of the ball with 5 (speed of the ball). This means that the ball will be bounced and shown 4 pixels beyond the wall. But I don't know why the ball will change direction before hitting the right and top wall, but it will most likely have something to do with the difference in subtracting (right/top wall) and adding (left and bottom wall) the speed ?
So to sum up ==> ball bounces on offset walls at higher speeds.
I used the BCC and BCS instructions after a CMP. So they will branch if greater/less than (and thus register a hit, although too late/soon)
CheckCollisionRight:
LDA boxRightX
CMP #RIGHTWALL
BCC CheckCollisionRightSkipper ; if A < RIGHTWALL ==> Carry is set to 0 ==>jump to label and skip over the direction change. If A >= RIGHTWALL ==> Carry = 1 ==> No jump to label and run change direction code
LDA #$00
STA ballright
LDA #$01
STA ballleft
CheckCollisionRightSkipper:
JMP CheckCollisionRightDone
CheckCollisionLeft:
LDA boxLeftX
CMP #LEFTWALL
BCS CheckCollisionLeftSkipper ; if A >= RIGHTWALL ==> Carry is set to 1 ==>jump to label and skip over the direction change. If A < RIGHTWALL ==> Carry = 0 ==> No jump to label and run change direction code
LDA #$01
STA ballright
LDA #$00
STA ballleft
CheckCollisionLeftSkipper:
JMP CheckCollisionLeftDone
Because I did the BCC and BCS the ball always bounces. But at the higher speeds, it often bounces to soon or to late. I'm thinking that it's impossible to eliminate this problem as it only updates at 50/60 Hz.
If the ball is 1 pixel before the wall in frame 1 ==> no hit ==> no change of direction.
In the next frame the ball will be 4 pixels behind the wall ==> it will branch ==> change direction. But it will still update the sprite for that frame and it will show it 4 pixels behind the wall.
I was thinking of creating a loop which will update the location of the ball one pixel a time. But this probably will slow down my ball :
==> frame 1 ==> loop 1 ==> 1 pixel moved
==> frame 2 ==> loop 2 ==> 1 pixel moved
==> frame 3 ==> loop 3 ==> 1 pixel moved
==> frame 4 ==> loop 4 ==> 1 pixel moved
==> frame 5 ==> loop 5 ==> 1 pixel moved
So in the end we still need 5 frames to perform 5 loops and we move only 5 pixels ==> which is exactly the same as moving 1 pixel a frame (or at a speed of 1 instead of 5).
Does anyone know a solution to this ? Or point me in the right direction ? Updating the sprite of the ball more often then 50/60 Hz is not possible.
many of you will know the Pong like game tutorial over at NA. After a long break, I am now continuing those lessons by creating my own pong game.
I created a nice playing field where my ball bounces around. I also managed to add the functionality of increasing the speed. But here is where the problem lies. I also asked this over at NA, but it doesn't hurt to also ask here.
I changed the ball speed to 2/3/4/5/6 to make it go faster. So instead of moving 1 pixel a time, I move 2/3/4/5/6 pixels a time.
But at these higher speeds, the ball will change direction before or after the "walls" I programmed.
They seem to have an offset. For the right and top wall it will change direction before it should hit the wall. And for the left and bottom wall it will change direction after it should hit the wall. (I think) I know why it does this ==> If the ball is, for example, 1 pixel before the wall ==> No collision ==> Increase the position of the ball with 5 (speed of the ball). This means that the ball will be bounced and shown 4 pixels beyond the wall. But I don't know why the ball will change direction before hitting the right and top wall, but it will most likely have something to do with the difference in subtracting (right/top wall) and adding (left and bottom wall) the speed ?
So to sum up ==> ball bounces on offset walls at higher speeds.
I used the BCC and BCS instructions after a CMP. So they will branch if greater/less than (and thus register a hit, although too late/soon)
CheckCollisionRight:
LDA boxRightX
CMP #RIGHTWALL
BCC CheckCollisionRightSkipper ; if A < RIGHTWALL ==> Carry is set to 0 ==>jump to label and skip over the direction change. If A >= RIGHTWALL ==> Carry = 1 ==> No jump to label and run change direction code
LDA #$00
STA ballright
LDA #$01
STA ballleft
CheckCollisionRightSkipper:
JMP CheckCollisionRightDone
CheckCollisionLeft:
LDA boxLeftX
CMP #LEFTWALL
BCS CheckCollisionLeftSkipper ; if A >= RIGHTWALL ==> Carry is set to 1 ==>jump to label and skip over the direction change. If A < RIGHTWALL ==> Carry = 0 ==> No jump to label and run change direction code
LDA #$01
STA ballright
LDA #$00
STA ballleft
CheckCollisionLeftSkipper:
JMP CheckCollisionLeftDone
Because I did the BCC and BCS the ball always bounces. But at the higher speeds, it often bounces to soon or to late. I'm thinking that it's impossible to eliminate this problem as it only updates at 50/60 Hz.
If the ball is 1 pixel before the wall in frame 1 ==> no hit ==> no change of direction.
In the next frame the ball will be 4 pixels behind the wall ==> it will branch ==> change direction. But it will still update the sprite for that frame and it will show it 4 pixels behind the wall.
I was thinking of creating a loop which will update the location of the ball one pixel a time. But this probably will slow down my ball :
==> frame 1 ==> loop 1 ==> 1 pixel moved
==> frame 2 ==> loop 2 ==> 1 pixel moved
==> frame 3 ==> loop 3 ==> 1 pixel moved
==> frame 4 ==> loop 4 ==> 1 pixel moved
==> frame 5 ==> loop 5 ==> 1 pixel moved
So in the end we still need 5 frames to perform 5 loops and we move only 5 pixels ==> which is exactly the same as moving 1 pixel a frame (or at a speed of 1 instead of 5).
Does anyone know a solution to this ? Or point me in the right direction ? Updating the sprite of the ball more often then 50/60 Hz is not possible.