Jump to content



0

Paddle output isn't changing


9 replies to this topic

#1 Primordial Ooze OFFLINE  

Primordial Ooze

    Dragonstomper

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

Posted Wed Mar 19, 2008 11:39 AM

I am trying to set it so if the left switch is set to A, the second paddle controller controls the left(player 2) paddle. However when i try that in the emulator i get the following results:

Quote

Switch B - 1 Player
Mouse is Paddle 0
*Normal*

Switch A - 2 Player
Mouse is Paddle 0
*Error* Paddle 0 doesn't work

Switch A - 2 Player
Mouse is Paddle 1
*Error* Paddle 1 controls both paddles

I have checked my code for errors, and i can see no errors on my part. Here is my code:

   rem Open Source Pong
   rem an Open Source Pong Remake
   rem Updated: March 17, 2008
   rem Website: http://opensourcepong.freepgs.com

   goto setup
   
   rem setup all the game variables
setup
   rem include for multiplication
   include div_mul.asm
   
   rem include for lives counter
   include 6lives.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 troggling the 2 player mode
   dim playervsplayer = c
   
   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 set the lives counter layout to compact
   rem dim lives_compact = 1

   rem set the player live counter to blue
   lifecolor = 140
   
   rem finished seting up the game variables
   
   rem start the game loop
   goto startNewGame
   
   rem start a new game and reset everything that was changed during
   rem the course of the game
startNewGame
   rem set player 1's inital x positon
   player0x = 140

   rem set player 1's inital y positon
   player0y = 45

   rem set a default value for the 2 player troggle
   playervsplayer = 0
   
   rem if the left switch is set to B, paddle 1 controls the
   rem computers paddle
   if !switchleftb then playervsplayer = 1
   
   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 set the lives counter to 3
   lives = 96
   
   rem setup the lives counter
   rem needs to be setup everytime the lives are SET
   lives:
   %00011000
   %00011000
   %00011000
   %00011000
   %00011000
   %00011000
   %00011000
   %00011000
end
   
   rem reset the score
   score = 0

   rem finished reseting all the game variables changed during
   rem the course of the game
   
   rem go to the game loop
   goto gameLoop
   
   rem start of the game loop
gameLoop
   rem if the user presses the reset switch, start a new game
   if switchreset then goto startNewGame

   rem color player 1's paddle
   COLUP0 = 140

   rem color player 2's paddle
   COLUP1 = 28

   rem draw the game screen
   drawscreen

   rem read paddle 0, use it to position player 1 across the screen
   currentpaddle = 0
   
   rem set player1's y position to the paddle control's axis
   rem plus 8
   player0y = paddle + 8
   
   rem make sure player 1 doesn't go off the top screen
   if player0y < 16 then player0y = 16
   
   rem make sure player 1 doesn't go off the bottom screen
   if player0y > 79 then player0y = 79
   
   rem if the 2 player mode is activated then paddle 1 controls the
   rem second paddle
   if playervsplayer = 1 then gosub player2controls
   
   rem otherwise set player 2's y position to the balls y position
   if playervsplayer = 0 then player1y = bally
   
   rem make sure player 2 doesn't go off the top screen
   if player1y < 16 then player1y = 16
   
   rem make sure player 2 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 gosub playercollision

   rem if the ball collides with the computer paddle
   if collision(player1, ball) then gosub playerscores
   
   rem if the ball goes past the player paddle
   if ballx > 160 then gosub playerlostlife
   
   rem if the ball goes past the computer paddle
   if ballx < 1 then gosub playerbonus
   
   rem if player has lost all of his lives start a new game
   if lives < 32 then goto gameover
   
   goto gameLoop
   
   rem end of the game loop code, restart the game loop
   
   rem code for handling collision between player and ball
playercollision
   rem move the ball a bit so it doesn't stick
   ballx = ballx - 3
   
   rem and reverse its x velocity
   ballxvelocity = 0 - ballxvelocity
   return
   
   rem end of player collision code
   
   rem code for handling when the ball hits the computers paddle
   rem and the player scores
playerscores
   rem move the ball a bit so it doesn't stick
   ballx = ballx + 3

   rem reverse the balls x velocity
   ballxvelocity = 0 - ballxvelocity
   
   rem increase the score by 10 points
   score = score + 10
   return
   
   rem end of player scores code
   
   rem code for handling when the ball goes past the computers paddle
   rem and the player scores bonus points
playerbonus

   rem have the computer serve the ball
   ballx = player1x + 3
   bally = player1y
   
   rem reverse the balls x velocity
   ballxvelocity = 0 - ballxvelocity
   
   rem increase the score by 10 points
   score = score + 10
   
   return
   
   rem end of player bonus code
   
   rem code for handling when the 2 player troggle is enabled and
   rem the second paddle controls the computer paddle
player2controls

   rem read paddle 1, use it to position player 2's paddle across the screen
   currentpaddle = 1
   
   rem set player 2's y position to the paddle 2's control's axis
   rem plus 8
   player1y = paddle + 8
   
   return
   
   rem end of player 2 controls code
   
   rem code for handling when the player misses the ball and the
   rem player loses a life
playerlostlife
   rem dencrease the score by 50 points
   lives = lives - 32
   
   rem have the player serve the ball
   ballx = player0x - 3
   bally = player0y
   
   rem reverse the balls x velocity
   ballxvelocity = 0 - ballxvelocity
   
   return
   
   rem end of player lost life code
   
   rem code for handling when the player has lost all his/her
   rem lives and its gameover
gameover
   rem if the user presses the reset switch, start a new game
   if switchreset then goto startNewGame
   
   rem color player 1's paddle
   COLUP0 = 140

   rem color player 2's paddle
   COLUP1 = 28   

   rem draw the screen
   drawscreen
   
   rem if the user presses the fire button, start a new game
   if joy0left then goto startNewGame
   
   rem otherwise just keep looping
   goto gameover

Could someone please help me?

Thanks,

Open Source Pong

#2 Fort Apocalypse OFFLINE  

Fort Apocalypse

    Stargunner

  • 1,593 posts

Posted Wed Mar 19, 2008 8:31 PM

there is a trick to it. you have to set currentpaddle then call drawscreen. drawscreen will then set the paddle variable.

#3 Fort Apocalypse OFFLINE  

Fort Apocalypse

    Stargunner

  • 1,593 posts

Posted Wed Mar 19, 2008 8:36 PM

View PostFort Apocalypse, on Wed Mar 19, 2008 10:31 PM, said:

there is a trick to it. you have to set currentpaddle then call drawscreen. drawscreen will then set the paddle variable.

In addition, you must call Stella with argument:
-bc paddles $(FilePath).bin
(that is the exact copied and pasted value I have for the "argument" field value in the paddles user tool I created in crimson editor)

#4 Primordial Ooze OFFLINE  

Primordial Ooze

    Dragonstomper

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

Posted Wed Mar 19, 2008 9:23 PM

I already have a drawscreen inside my main loop, are you saying i need another one inside my player2controls label after i set currentpaddle to 1? Thank you for the advice on the "-bc paddles" command line for Stella.

Sincerely,

Open Source Pong

#5 Fort Apocalypse OFFLINE  

Fort Apocalypse

    Stargunner

  • 1,593 posts

Posted Thu Mar 20, 2008 5:22 AM

View PostOpen Source Pong, on Wed Mar 19, 2008 11:23 PM, said:

I already have a drawscreen inside my main loop, are you saying i need another one inside my player2controls label after i set currentpaddle to 1? Thank you for the advice on the "-bc paddles" command line for Stella.

Sincerely,

Open Source Pong


Yes, basically it doesn't set the paddle variable until you call drawscreen, so if you change the currentpaddle and expect it to read the paddle value into "paddle" variable, you have to call drawscreen before the paddle variable will be set. In the Ultimate Indy 500 game (based on 4 paddles) I 1/2 finished (being gracious to myself by saying 1/2 finished :) ) I had four drawscreens - one after each currentpaddle set. If you have only one paddle, you need only one drawscreen, but you should set currentpaddle before you do the drawscreen, and paddle will be read during that drawscreen. I don't know if you only have a one player game whether you'd need to keep setting currentpaddle, though. But I'm assuming for 2 players, you'll need to set currentpaddle then drawscreen then do something based on paddle value that was read, then set currentpaddle then drawscreen then do something based on paddle value that was read.

#6 Primordial Ooze OFFLINE  

Primordial Ooze

    Dragonstomper

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

Posted Thu Mar 20, 2008 7:53 AM

Thanks, i added the drawscreen and that did the trick, However i am running into another probem. With the extra drawscreen both paddles flicker. I know its not a "loop is too complicated" problem because 1 my game is only about 2k, 2 when i play single player which removes the extra drawscreen the flicker doesn't happen, 3 if i start a 2 player mode game the flicker happens but, if i switch to a one player game the flicker disappears even though the if statement that leads to that sub is still being called 4, if i remove the extra drawscreen the flicker disappears and 5 i've seen 8k games that i bet have bigger game loops that i have. If someoneone could help me out it would be greatly appreciated. Here is the code:

   rem Open Source Pong
   rem an Open Source Pong Remake
   rem Updated: March 17, 2008
   rem Website: http://opensourcepong.freepgs.com

   goto setup
   
   rem setup all the game variables
setup
   rem include for multiplication
   include div_mul.asm
   
   rem include for lives counter
   include 6lives.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 troggling the 2 player mode
   dim playervsplayer = c
   
   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 set the lives counter layout to compact
   rem dim lives_compact = 1

   rem set the player live counter to blue
   lifecolor = 140
   
   rem finished seting up the game variables
   
   rem start the game loop
   goto startNewGame
   
   rem start a new game and reset everything that was changed during
   rem the course of the game
startNewGame
   rem set player 1's inital x positon
   player0x = 140

   rem set player 1's inital y positon
   player0y = 45

   rem set a default value for the 2 player troggle
   playervsplayer = 0
   
   rem if the left switch is set to B, paddle 1 controls the
   rem computers paddle
   if !switchleftb then playervsplayer = 1
   
   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 set the lives counter to 3
   lives = 96
   
   rem setup the lives counter
   rem needs to be setup everytime the lives are SET
   lives:
   %00011000
   %00011000
   %00011000
   %00011000
   %00011000
   %00011000
   %00011000
   %00011000
end
   
   rem reset the score
   score = 0

   rem finished reseting all the game variables changed during
   rem the course of the game
   
   rem go to the game loop
   goto gameLoop
   
   rem start of the game loop
gameLoop
   rem if the user presses the reset switch, start a new game
   if switchreset then goto startNewGame

   rem color player 1's paddle
   COLUP0 = 140

   rem color player 2's paddle
   COLUP1 = 28

   rem read paddle 0, use it to position player 1 across the screen
   currentpaddle = 0
   
   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 player 1 doesn't go off the top screen
   if player0y < 16 then player0y = 16
   
   rem make sure player 1 doesn't go off the bottom screen
   if player0y > 79 then player0y = 79
   
   rem if the 2 player mode is activated then paddle 1 controls the
   rem second paddle
   if playervsplayer = 1 then gosub player2controls
   
   rem otherwise set player 2's y position to the balls y position
   if playervsplayer = 0 then player1y = bally
   
   rem make sure player 2 doesn't go off the top screen
   if player1y < 16 then player1y = 16
   
   rem make sure player 2 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 gosub playercollision

   rem if the ball collides with the computer paddle
   if collision(player1, ball) then gosub playerscores
   
   rem if the ball goes past the player paddle
   if ballx > 160 then gosub playerlostlife
   
   rem if the ball goes past the computer paddle
   if ballx < 1 then gosub playerbonus
   
   rem if player has lost all of his lives start a new game
   if lives < 32 then goto gameover
   
   goto gameLoop
   
   rem end of the game loop code, restart the game loop
   
   rem code for handling collision between player and ball
playercollision
   rem move the ball a bit so it doesn't stick
   ballx = ballx - 3
   
   rem and reverse its x velocity
   ballxvelocity = 0 - ballxvelocity
   return
   
   rem end of player collision code
   
   rem code for handling when the ball hits the computers paddle
   rem and the player scores
playerscores
   rem move the ball a bit so it doesn't stick
   ballx = ballx + 3

   rem reverse the balls x velocity
   ballxvelocity = 0 - ballxvelocity
   
   rem increase the score by 10 points
   score = score + 10
   return
   
   rem end of player scores code
   
   rem code for handling when the ball goes past the computers paddle
   rem and the player scores bonus points
playerbonus

   rem have the computer serve the ball
   ballx = player1x + 3
   bally = player1y
   
   rem reverse the balls x velocity
   ballxvelocity = 0 - ballxvelocity
   
   rem increase the score by 10 points
   score = score + 10
   
   return
   
   rem end of player bonus code
   
   rem code for handling when the 2 player troggle is enabled and
   rem the second paddle controls the computer paddle
player2controls

   rem read paddle 1, use it to position player 2's paddle across the screen
   currentpaddle = 1
   
   rem draw the game screen
   drawscreen
   
   rem set player 2's y position to the paddle 2's control's axis
   rem plus 8
   player1y = paddle + 8
   
   return
   
   rem end of player 2 controls code
   
   rem code for handling when the player misses the ball and the
   rem player loses a life
playerlostlife
   rem dencrease the score by 50 points
   lives = lives - 32
   
   rem have the player serve the ball
   ballx = player0x - 3
   bally = player0y
   
   rem reverse the balls x velocity
   ballxvelocity = 0 - ballxvelocity
   
   return
   
   rem end of player lost life code
   
   rem code for handling when the player has lost all his/her
   rem lives and its gameover
gameover
   rem if the user presses the reset switch, start a new game
   if switchreset then goto startNewGame
   
   rem color player 1's paddle
   COLUP0 = 140

   rem color player 2's paddle
   COLUP1 = 28   

   rem draw the screen
   drawscreen
   
   rem if the user presses the fire button, start a new game
   if joy0left then goto startNewGame
   
   rem otherwise just keep looping
   goto gameover

Sincerely,

Open Source Pong

#7 Fort Apocalypse OFFLINE  

Fort Apocalypse

    Stargunner

  • 1,593 posts

Posted Thu Mar 20, 2008 6:04 PM

Hmm... I'm not getting any flickering. You may want to try the latest bB kernel from the bB bugs thread in the bB forum.

It plays great! You may want to make it 2-player optional and use the player scores minikernel. (search for that thread and you'll find it- works great.)

Note: there is one bug, which is when the ball gets stuck going back and forth in basically a straight line at the very bottom of the screen. I think it is either validly going straight across or is getting stuck somehow in playfield collision stuff. It is probably fairly hard to reproduce.

#8 Primordial Ooze OFFLINE  

Primordial Ooze

    Dragonstomper

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

Posted Thu Mar 20, 2008 8:09 PM

It happen when in a two player game, the paddles go from color to grey. The two player mode is optional and is activated by setting the left difficult switch to A. To reproduce the bug you reported just have your paddle rest on the top or bottom of the screen and lose a ball. Its colliding with the top and bottom border causing the ball to callide rapidly to change velocity. It will be fix most likely in the next update, but thanks for reporting it anyways.

Sincerely,

Open Source Pong

#9 Fort Apocalypse OFFLINE  

Fort Apocalypse

    Stargunner

  • 1,593 posts

Posted Fri Mar 21, 2008 5:29 AM

View PostOpen Source Pong, on Thu Mar 20, 2008 10:09 PM, said:

It happen when in a two player game, the paddles go from color to grey. The two player mode is optional and is activated by setting the left difficult switch to A. To reproduce the bug you reported just have your paddle rest on the top or bottom of the screen and lose a ball. Its colliding with the top and bottom border causing the ball to callide rapidly to change velocity. It will be fix most likely in the next update, but thanks for reporting it anyways.

Sincerely,

Open Source Pong

You have to set COLUP0 and COLUP1 before every drawscreen. See "Ephemeral Variables and Registers (short-lived)" in http://www.randomter....html#ephvarreg

I think that might help you.

#10 Primordial Ooze OFFLINE  

Primordial Ooze

    Dragonstomper

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

Posted Fri Mar 21, 2008 8:23 AM

Ok, Thank You i will go read it right now.

Sincerely,

Open Source Pong




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users