Primordial Ooze Posted February 28, 2008 Share Posted February 28, 2008 For some reason 1 line from my code is not being runned even though the line that precedes it is. Here is my code: 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 Quote Link to comment Share on other sites More sharing options...
Primordial Ooze Posted February 28, 2008 Author Share Posted February 28, 2008 UPDATE: I have determined with 100% certainty that the above is is in fact not getting called. I am uncertain as to why. Any help would be greatly appreciated. Sincerely, Open Source Pong Quote Link to comment Share on other sites More sharing options...
SeaGtGruff Posted February 28, 2008 Share Posted February 28, 2008 **** this line never gets called **** rem and reverse its x velocity ballxvelocity = -ballxvelocity Change it to the following: **** this line never gets called **** rem and reverse its x velocity ballxvelocity = 0 - ballxvelocity I think that should do it. bB doesn't have negative integer byte values per se, but if you subtract a byte from 0, you will get the equivalent of the negative value. For example, 0 - 1 = 255, since 0 is equivalent to 256, and 256 - 1 = 255. And if you add 255 to a byte, the result will be the same as if you had subtracted 1 from it. Likewise, 254 = -2, 253 = -3, etc. Michael Quote Link to comment Share on other sites More sharing options...
Primordial Ooze Posted February 28, 2008 Author Share Posted February 28, 2008 Nope, it still exibits the same behavior. Any other ideas? Updated Code: 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 = 0 - ballyvelocity rem make sure the ball doesn't go off the bottom screen if bally > 77 then ballyvelocity = 0 - 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 - 10 rem and reverse its x velocity ballxvelocity = 0 - ballxvelocity return playerscores rem move the ball a bit so it doesn't stick ballx = ballx + 10 rem reverse the balls x velocity ballxvelocity = 0 - 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 Quote Link to comment Share on other sites More sharing options...
+batari Posted February 29, 2008 Share Posted February 29, 2008 I suspect the problem is that you're using labels beginning with "player." I think that confuses the compiler. Quote Link to comment Share on other sites More sharing options...
SeaGtGruff Posted February 29, 2008 Share Posted February 29, 2008 Nope, it still exibits the same behavior. Any other ideas? Okay, I see what the problem is. playercollision, playerscores, and computerscores are subroutines that end with return, but in your if statements you're doing a goto them. Change those three goto statements to gosub statements, and you'll be back in business! Michael Quote Link to comment Share on other sites More sharing options...
SeaGtGruff Posted February 29, 2008 Share Posted February 29, 2008 I suspect the problem is that you're using labels beginning with "player." I think that confuses the compiler. Nope, the compiler is hunky dory with that. Michael Quote Link to comment Share on other sites More sharing options...
Primordial Ooze Posted February 29, 2008 Author Share Posted February 29, 2008 Wow, that worked thanks. Sincerely, Open Source Pong Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.