Jump to content
IGNORED

2 Player Mode Incredibly Slow


Primordial Ooze

Recommended Posts

For some reason when 2 player mode is enabled, the game runs much slower then usual. I have determined the cause to be the extra drawscreen required to track both paddle controllers. I really don't see why this is happening as many games use more then 1 paddle controller with no noticibly slow down. Any one have Any Ideas?

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

  rem setup all the game variables
  
  rem set the rom size
  set romsize 2k
  
  rem turn on smartbranching
  set smartbranching on

  rem define the number of player scores
  const playerscores = 2
  
  rem define noscores constant
  const noscore = 1
  
  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 set an alias to determine if sound effects
  rem should be playing
  dim soundplaying = d
  
  rem set an alias to keep track of how many frames the
  rem sound effects have played
  dim soundtimer = e
  
  rem color the background green
  COLUBK = 198

  rem set the color of the playfield to white
  COLUPF = 14

  rem set player 2's score color to his sprite color
  player0scorecolor = $1C
  
  rem set player 1's score color to his sprite color
  player1scorecolor = $8C
  
  rem clear the playfield
  pfclear
  
  rem draw the top border of the playfield
  pfhline 0 0 31 on
  
  rem draw the bottom border of the playfield
  pfhline 0 10 31 on
  
  rem bla
  
  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 finished seting up the game variables
  
  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 if the left switch is set to B, paddle 1 controls the
  rem computers paddle, otherwise paddle controller 2 controlls
  rem it
  if !switchleftb then playervsplayer = 1 else playervsplayer = 0
  
  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 reset player 1's score
  player0score = $00

  rem reset player 1's score
  player1score = $00
  
  rem reset the sound playing boolean to 0
  soundplaying = 0
  
  rem reset the sound effects timer
  soundtimer = 0

  rem turn off all sound effects from the previous game
  AUDV0 = 0
 
  rem set the Audio Control for Channel 0 to a pure tone
  AUDC0 = 12
  
  rem finished reseting all the game variables changed during
  rem the course of the game
  
  rem start of the game loop
gameLoop
  rem if the user presses the reset switch, start a new game
  if switchreset then startNewGame
  
  rem if the colorswitch is in the black/white position pause
  rem the game
pauseloop
  if switchbw then COLUP0 = 140 : COLUP1 = 28 : drawscreen : goto pauseloop

  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
  rem color player 1's paddle
  rem color player 2's paddle
  rem read paddle 1, use it to position player 2's paddle across the screen
  rem draw the game screen
  rem set player 2's y position to the paddle 2's control's axis
  rem plus 8
  rem otherwise set player 2's y position to the balls y position
  if playervsplayer = 1 then COLUP0 = 140 : COLUP1 = 28 : currentpaddle = 1 : drawscreen : player1y = paddle + 8 else player1y = bally + 1
  
  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 player 1's paddle
  rem play the pure tone with a frequency of 4 and volume of 10
  rem move the ball a bit so it doesn't stick
  rem and reverse its x velocity
  if collision(player0, ball) then soundplaying = 1 : AUDF0 = 4 : AUDV0 = 10 : ballx = ballx - 3 : ballxvelocity = 0 - ballxvelocity

  rem if the ball collides with player 2's paddle
  rem play the pure tone with a frequency of 5 and volume of 10
  rem move the ball a bit so it doesn't stick
  rem and reverse its x velocity
  if collision(player1, ball) then soundplaying = 1 : AUDF0 = 5 : AUDV0 = 10 : ballx = ballx + 3 : ballxvelocity = 0 - ballxvelocity
  
  rem if the a effect is playing update the sound timer
  if soundplaying = 1 then soundtimer = soundtimer + 1
  
  rem if the sound effect timer is 60 frames, stop the sound effect
  if soundtimer = 60 then soundplaying = 0 : soundtimer = 0 : AUDV0 = 0
  
  rem if the ball goes past player 1's paddle
  rem increase player 2's score by 1
  rem have the player serve the ball
  rem reverse the balls x velocity
  if ballx > 160 then player0score = addbcd(player0score,1) : ballx = player0x - 3 : bally = player0y - 5 : ballxvelocity = 0 - ballxvelocity
  
  rem if the ball goes past the computer paddle
  rem increase player 1's score by 1
  rem have the computer serve the ball
  rem reverse the balls x velocity
  if ballx < 1 then player1score = addbcd(player1score,1) : ballx = player1x + 3 : bally = player1y - 5 : ballxvelocity = 0 - ballxvelocity
  
  rem if player 1 scores 11 points then its game
  if player0score > $10 then goto gameover
  
  rem if player 2 scores 11 points then its game
  if player1score > $10 then goto gameover
  
  goto gameLoop
  
  rem end of the game loop code, restart the game loop
  
  rem code for handling when either players score  reaches 11
  rem and its gameover
gameover
  rem if the user presses the reset switch, start a new game
  if switchreset then 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 startNewGame
  
  rem otherwise just keep looping
  goto gameover

  rem inline bcd math helper
  inline bcd_math.asm

  rem inline for player scores multikernel
  inline playerscores.asm

 

Sincerely,

 

Open Source Pong

Link to comment
Share on other sites

I noticed 100+ users have viewed the topic and no one seems to has an answer, strange. Anyways i'm still trying to figure out whats wrong, so if anyone could enlighten me please feel free to post a reply below.

 

Sincerely,

 

Open Source Pong

You are calling two drawscreens when there should be one. In two player mode, you need to alternate each section of code. A simple check will help to determine which one to call. I've taken a segment of code and modified it so it should work.

 

  rem read paddle 0, use it to position player 1 across the screen
  if playervsplayer <> 1 then currentpaddle=0:goto firstpaddle
  currentpaddle=currentpaddle ^ 1: rem this alternates paddles per frame
  if currentpaddle=1 then secondpaddle

firstpaddle
 
  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
  goto donereadingpaddle

secondpaddle  
  rem if the 2 player mode is activated then paddle 1 controls the
  rem second paddle
  rem color player 1's paddle
  rem color player 2's paddle
  rem read paddle 1, use it to position player 2's paddle across the screen
  rem draw the game screen
  rem set player 2's y position to the paddle 2's control's axis
  rem plus 8
  rem otherwise set player 2's y position to the balls y position
  COLUP0 = 140 : COLUP1 = 28 : currentpaddle = 1 : drawscreen : player1y = paddle + 8 else player1y = bally + 1
 
  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

donereadingpaddle

Link to comment
Share on other sites

doesn't quite work, now the second paddle doesn't move in a 1 player game.

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

  rem setup all the game variables
  
  rem set the rom size
  set romsize 2k
  
  rem turn on smartbranching
  set smartbranching on

  rem define the number of player scores
  const playerscores = 2
  
  rem define noscores constant
  const noscore = 1
  
  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 set an alias to determine if sound effects
  rem should be playing
  dim soundplaying = d
  
  rem set an alias to keep track of how many frames the
  rem sound effects have played
  dim soundtimer = e
  
  rem color the background green
  COLUBK = 198

  rem set the color of the playfield to white
  COLUPF = 14

  rem set player 2's score color to his sprite color
  player0scorecolor = $1C
  
  rem set player 1's score color to his sprite color
  player1scorecolor = $8C
  
  rem clear the playfield
  pfclear
  
  rem draw the top border of the playfield
  pfhline 0 0 31 on
  
  rem draw the bottom border of the playfield
  pfhline 0 10 31 on
  
  rem bla
  
  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 finished seting up the game variables
  
  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 if the left switch is set to B, paddle 1 controls the
  rem computers paddle, otherwise paddle controller 2 controlls
  rem it
  if !switchleftb then playervsplayer = 1 else playervsplayer = 0
  
  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 reset player 1's score
  player0score = $00

  rem reset player 1's score
  player1score = $00
  
  rem reset the sound playing boolean to 0
  soundplaying = 0
  
  rem reset the sound effects timer
  soundtimer = 0

  rem turn off all sound effects from the previous game
  AUDV0 = 0
 
  rem set the Audio Control for Channel 0 to a pure tone
  AUDC0 = 12
  
  rem finished reseting all the game variables changed during
  rem the course of the game
  
  rem start of the game loop
gameLoop
  rem if the user presses the reset switch, start a new game
  if switchreset then startNewGame
  
  rem if the colorswitch is in the black/white position pause
  rem the game
pauseloop
  if switchbw then COLUP0 = 140 : COLUP1 = 28 : drawscreen : goto pauseloop

  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
  if playervsplayer <> 1 then currentpaddle=0:goto firstpaddle
  
  rem this alternates paddles per frame
  currentpaddle=currentpaddle ^ 1
  
  rem if currentpaddle equals 2 then position the second paddle
  if currentpaddle = 1 then secondpaddle

firstpaddle
 
  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
  goto donereadingpaddle

secondpaddle  
  rem if the 2 player mode is activated then paddle 1 controls the
  rem second paddle
  
  rem color player 1's paddle
  COLUP0 = 140
  
  rem color player 2's paddle
  COLUP1 = 28
  
  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
  
  rem otherwise set player 2's y position to the balls y position
  rem player1y = bally + 1
 
  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

donereadingpaddle
  
  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 player 1's paddle
  rem play the pure tone with a frequency of 4 and volume of 10
  rem move the ball a bit so it doesn't stick
  rem and reverse its x velocity
  if collision(player0, ball) then soundplaying = 1 : AUDF0 = 4 : AUDV0 = 10 : ballx = ballx - 3 : ballxvelocity = 0 - ballxvelocity

  rem if the ball collides with player 2's paddle
  rem play the pure tone with a frequency of 5 and volume of 10
  rem move the ball a bit so it doesn't stick
  rem and reverse its x velocity
  if collision(player1, ball) then soundplaying = 1 : AUDF0 = 5 : AUDV0 = 10 : ballx = ballx + 3 : ballxvelocity = 0 - ballxvelocity
  
  rem if the a effect is playing update the sound timer
  if soundplaying = 1 then soundtimer = soundtimer + 1
  
  rem if the sound effect timer is 60 frames, stop the sound effect
  if soundtimer = 60 then soundplaying = 0 : soundtimer = 0 : AUDV0 = 0
  
  rem if the ball goes past player 1's paddle
  rem increase player 2's score by 1
  rem have the player serve the ball
  rem reverse the balls x velocity
  if ballx > 160 then player0score = addbcd(player0score,1) : ballx = player0x - 3 : bally = player0y - 5 : ballxvelocity = 0 - ballxvelocity
  
  rem if the ball goes past the computer paddle
  rem increase player 1's score by 1
  rem have the computer serve the ball
  rem reverse the balls x velocity
  if ballx < 1 then player1score = addbcd(player1score,1) : ballx = player1x + 3 : bally = player1y - 5 : ballxvelocity = 0 - ballxvelocity
  
  rem if player 1 scores 11 points then its game
  if player0score > $10 then goto gameover
  
  rem if player 2 scores 11 points then its game
  if player1score > $10 then goto gameover
  
  goto gameLoop
  
  rem end of the game loop code, restart the game loop
  
  rem code for handling when either players score  reaches 11
  rem and its gameover
gameover
  rem if the user presses the reset switch, start a new game
  if switchreset then 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 startNewGame
  
  rem otherwise just keep looping
  goto gameover

  rem inline bcd math helper
  inline bcd_math.asm

  rem inline for player scores multikernel
  inline playerscores.asm

Edited by Open Source Pong
Link to comment
Share on other sites

Took a while to get the code built (due to the two asm files) and took a while to figure out that you need to set left difficulty to A, then press RESET to enable 2 players, and in Stella, I had to set the mouse to paddle 1 to test the second player. But after I did all that, it works fine on my end. If your binary is not working for whatever reason, you can post it or PM it to me and I'll take a look.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...