rem Open Source Pong rem an Open Source Pong Remake rem Updated: Feburary 10, 2008 rem Website: http://opensourcepong.freepgs.com goto setup setup rem include for multiplication include div_mul.asm rem set the rom size set romsize 4k rem set kernel options rem readpaddle - set it so the paddle controlers are read set kernel_options no_blank_lines readpaddle rem set an alias for the ball's x velocity dim ballxvelocity = a rem set an alias for the ball's y velocity dim ballyvelocity = b rem set an alias for the player1's score dim player1score = c rem set an alias for the player2's x score dim player2score = d rem set player1's inital x positon player0x = 140 rem set player1's inital y positon player0y = 45 rem set player2's inital x positon player1x = 15 rem set player2's inital y positon player1y = 45 rem set ball's inital x positon ballx = 80 rem set ball's inital y positon bally = 45 rem set the ball's initial x velocity ballxvelocity = 1 rem set the ball's initial x velocity ballyvelocity = 1 rem color the background green COLUBK = 198 rem set the color of the playfield to white COLUPF = 14 rem define the playfield playfield: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ................................ ................................ ................................ ................................ ................................ ................................ ................................ ................................ ................................ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX end rem define player 1's sprite player0: %00011000 %00011000 %00011000 %00011000 %00011000 %00011000 %00011000 %00011000 end rem define player 2's sprite player1: %00011000 %00011000 %00011000 %00011000 %00011000 %00011000 %00011000 %00011000 end rem read paddle 0, use it to position player0x across the screen currentpaddle = 0 rem gamesetup is done start the game loop goto gameLoop rem start of the game loop gameLoop rem color player 1's paddle COLUP0 = 140 rem color player 2's paddle COLUP1 = 28 rem draw the game screen drawscreen rem set player1's y position to the paddle control's axis rem plus 8 player0y = paddle + 8 rem make sure the player doesn't go off the top screen if player0y < 16 then player0y = 16 rem make sure the player doesn't go off the bottom screen if player0y > 79 then player0y = 79 rem set the computer's y position to the balls y position player1y = bally rem make sure the computer doesn't go off the top screen if player1y < 16 then player1y = 16 rem make sure the computer doesn't go off the bottom screen if player1y > 79 then player1y = 79 rem move the ball ballx = ballx + ballxvelocity bally = bally + ballyvelocity rem make sure the ball doesn't go off the top screen if bally < 9 then ballyvelocity = -ballyvelocity rem make sure the ball doesn't go off the bottom screen if bally > 77 then ballyvelocity = -ballyvelocity rem if the ball collides with the player paddle if collision(player0, ball) then goto playercollision rem if the ball collides with the computer paddle if collision(player1, ball) then goto playerscores rem if the ball goes past the player paddle if ballx > 160 then goto computerscores goto gameLoop playercollision rem move the ball a bit so it doesn't stick ballx = ballx - 15 rem and reverse its x velocity ballxvelocity = -ballxvelocity return playerscores rem move the ball a bit so it doesn't stick ballx = ballx + 15 rem reverse the balls x velocity ballxvelocity = -ballxvelocity rem increase the score by 10 points score = score + 10 return computerscores rem dencrease the score by 50 points score = score - 50 rem and reset the ball ballx = 80 bally = 45 return
If you compile the game you will see that even though the player0 to ball collision happens and the ball is moved, the balls x velocity is never changed even though theres code to do it. The code in question is:
playercollision rem move the ball a bit so it doesn't stick ballx = ballx - 15 **** this line never gets called **** rem and reverse its x velocity ballxvelocity = -ballxvelocity return
Which gets called here:
rem if the ball collides with the player paddle if collision(player0, ball) then goto playercollision
Any idea?
Sincerely,
Open Source Pong














