Jump to content



0

Strange Behavior


7 replies to this topic

#1 Primordial Ooze OFFLINE  

Primordial Ooze

    Dragonstomper

  • 504 posts
  • Quacker Blaster Lead Programmer
  • Location:United States of America

Posted Thu Feb 28, 2008 10:39 AM

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

#2 Primordial Ooze OFFLINE  

Primordial Ooze

    Dragonstomper

  • 504 posts
  • Quacker Blaster Lead Programmer
  • Location:United States of America

Posted Thu Feb 28, 2008 1:27 PM

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

#3 SeaGtGruff OFFLINE  

SeaGtGruff

    River Patroller

  • 4,543 posts
  • Location:Georgia, USA

Posted Thu Feb 28, 2008 4:01 PM

   **** 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

#4 Primordial Ooze OFFLINE  

Primordial Ooze

    Dragonstomper

  • 504 posts
  • Quacker Blaster Lead Programmer
  • Location:United States of America

Posted Thu Feb 28, 2008 4:26 PM

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


#5 batari OFFLINE  

batari

    )66]U('=I;B$*

  • 6,236 posts
  • begin 644 contest

Posted Thu Feb 28, 2008 7:07 PM

I suspect the problem is that you're using labels beginning with "player." I think that confuses the compiler.

#6 SeaGtGruff OFFLINE  

SeaGtGruff

    River Patroller

  • 4,543 posts
  • Location:Georgia, USA

Posted Fri Feb 29, 2008 12:08 AM

View PostOpen Source Pong, on Thu Feb 28, 2008 5:26 PM, said:

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

#7 SeaGtGruff OFFLINE  

SeaGtGruff

    River Patroller

  • 4,543 posts
  • Location:Georgia, USA

Posted Fri Feb 29, 2008 12:09 AM

View Postbatari, on Thu Feb 28, 2008 8:07 PM, said:

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

#8 Primordial Ooze OFFLINE  

Primordial Ooze

    Dragonstomper

  • 504 posts
  • Quacker Blaster Lead Programmer
  • Location:United States of America

Posted Fri Feb 29, 2008 9:14 AM

Wow, that worked thanks.

Sincerely,

Open Source Pong




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users