Jump to content



2

Pong


8 replies to this topic

#1 SuperNESFreak OFFLINE  

SuperNESFreak

    Space Invader

  • 24 posts

Posted Tue Jan 4, 2011 3:16 PM

1500 bytes of Pong and I can't even get that to work. Oh, boy.

Okay, my problem is that not only does the enemy not move, I get an error message about ' if joy0fire then g=1'. (which starts/unpauses a game)

There a couple of things which aren't causing errors but I think could be improved. For one, the paddles are both the same sprite (flipped for the second one) is it possible to address them both at the same time?

Also, the collision is quite messy, but I don't know how to make an if statement do more than one code - how do you do this?

Finally, the playfield is just two bars, so is there a way to cut down on that code?

Thanks very much.

PS. It's unrelated to this game, but I've been having little success doing smooth movement, like in Reactor or Defender. Is there a way to increase these variables little by little?

 rem Pong, by SuperNESFreak, 2-1-11
 set romsize 2k

 playfield:
 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 ................................
 ................................
 ................................
 ................................
 ................................
 ................................
 ................................
 ................................
 ................................
 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
end

 player0:
 000011
 000011
 000011
 000011
 000011
 000011
 000011
 000011
end

 player1:
 000011
 000011
 000011
 000011
 000011
 000011
 000011
 000011
end
ready
 a = 75 : rem playery
 b = 75 : rem opponenty
 c = 75 : rem ballx
 d = 75 : rem bally
 e = 255 : rem ballhspeed
 f = 255 : rem ballvspeed
 g = 0 : rem pause

gamea
 player0x = 16
 player1x = 140
 player0y = a
 player1y = b
 ballx = c
 bally = d
 COLUBK = 0
 COLUPF = 14
 COLUP0 = 14
 COLUP1 = 14
 REFP1 = 8
 scorecolor = 14

 if joy0fire then g=1
 if g = 0 then goto ready
 if switchreset then reboot

gameb
 if joy0up then a=a-1
 if joy0down then a=a+1
 if a<16 then a=16
 if a>80 then a=80
 if b<d then b=b-1
 if b>d then b=b+1
 if b<1 then b=1
 if b>88 then B=88
 if collision(ball,playfield) then f=0-f
 if collision(ball,player0) then e=0-e
 if collision(ball,player1) then e=0-e
 if collision(ball,player0) then f=0-f
 if collision(ball,player1) then f=0-f
 if c<4 then score=score-1
 if c>251 then score=score+1
 if c<4 | c>251 then goto game

 drawscreen
 goto game


#2 jbs30000 OFFLINE  

jbs30000

    Moonsweeper

  • 459 posts

Posted Tue Jan 4, 2011 5:38 PM

One thing right off of the bat just looking over your code. At the end you have
 if c<4 | c>251 then goto game

 drawscreen
 goto game
Yet, I don't see a "game" label. I see gamea and gameb, but no game.

#3 Arkhan OFFLINE  

Arkhan

    Dragonstomper

  • 801 posts
  • Thug Life.
  • Location:Atlantis

Posted Tue Jan 4, 2011 6:29 PM

you have a capital B instead of a lowercase b in the middle of the gameb section.

#4 jrok OFFLINE  

jrok

    Stargunner

  • 1,108 posts

Posted Tue Jan 4, 2011 7:34 PM

View PostSuperNESFreak, on Tue Jan 4, 2011 3:16 PM, said:

1500 bytes of Pong and I can't even get that to work. Oh, boy.

Okay, my problem is that not only does the enemy not move, I get an error message about ' if joy0fire then g=1'. (which starts/unpauses a game)

There a couple of things which aren't causing errors but I think could be improved. For one, the paddles are both the same sprite (flipped for the second one) is it possible to address them both at the same time?

Also, the collision is quite messy, but I don't know how to make an if statement do more than one code - how do you do this?

Finally, the playfield is just two bars, so is there a way to cut down on that code?

Thanks very much.

PS. It's unrelated to this game, but I've been having little success doing smooth movement, like in Reactor or Defender. Is there a way to increase these variables little by little?

 rem Pong, by SuperNESFreak, 2-1-11
 set romsize 2k

 playfield:
 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 ................................
 ................................
 ................................
 ................................
 ................................
 ................................
 ................................
 ................................
 ................................
 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
end

 player0:
 000011
 000011
 000011
 000011
 000011
 000011
 000011
 000011
end

 player1:
 000011
 000011
 000011
 000011
 000011
 000011
 000011
 000011
end

ready
 a = 75 : rem playery
 b = 75 : rem opponenty
 c = 75 : rem ballx
 d = 75 : rem bally
 e = 255 : rem ballhspeed
 f = 255 : rem ballvspeed
 g = 0 : rem pause

gamea
 player0x = 16
 player1x = 140
 player0y = a
 player1y = b
 ballx = c
 bally = d
 COLUBK = 0
 COLUPF = 14
 COLUP0 = 14
 COLUP1 = 14
 REFP1 = 8
 scorecolor = 14

 if joy0fire then g=1
 if g = 0 then goto ready
 if switchreset then reboot

gameb
 if joy0up then a=a-1
 if joy0down then a=a+1
 if a<16 then a=16
 if a>80 then a=80
 if b<d then b=b-1
 if b>d then b=b+1
 if b<1 then b=1
 if b>88 then B=88
 if collision(ball,playfield) then f=0-f
 if collision(ball,player0) then e=0-e
 if collision(ball,player1) then e=0-e
 if collision(ball,player0) then f=0-f
 if collision(ball,player1) then f=0-f
 if c<4 then score=score-1
 if c>251 then score=score+1
 if c<4 | c>251 then goto game

 drawscreen
 goto game

There were a few things wrong with the code. First, you have an endless loop without drawing the screen ("if g=0 then goto ready") and then you send to a label that doesn't exist ("game"). You also forgot to separate your sprite lines with "%." You also didn't include updates for sprite positions in your "gameb" loop (which wasn't a loop, since it was trying to jump to "game", which didn't exist). I'm actually not sure why you assigned "player0y" and "player1y" to "a" and "b", since player0x,player0y,player1x and player1y are already themselves assigned to RAM addresses, so I changed that.

There were also some other weird things about the way it was set up, and certain stuff where I wasn't sure what you intended. Anyway, try compiling the following code and then compare it to yours. You press fire to begin the gameb loop (I'm thinking that's what you intended?)


 rem Pong, by SuperNESFreak, 2-1-11
 set romsize 2k

 playfield:
 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 ................................
 ................................
 ................................
 ................................
 ................................
 ................................
 ................................
 ................................
 ................................
 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
end

 player0:
 0011
 0011
 0011
 0011
 0011
 0011
 0011
 0011
end

 player1:
 0011
 0011
 0011
 0011
 0011
 0011
 0011
 0011
end

ready
 COLUBK = 0
 COLUPF = 14
 COLUP0 = 14
 COLUP1 = 14
 player0y = 75 : rem playery
 player1y = 75 : rem opponenty
 ballx = 75 : rem ballx
 bally = 75 : rem bally
 e = 255 : rem ballhspeed
 f = 255 : rem ballvspeed
 g = 0 : rem pause
 player0x = 16
 player1x = 140
 ballx = 75
 bally = 75
 scorecolor = 14

gamea
 if switchreset then reboot
 if joy0fire then goto gameb
 REFP1 = 8
 player0y = 75 : rem playery
 player1y = 75 : rem opponenty
 ballx = 75 : rem ballx
 bally = 75 : rem bally
 e = 255 : rem ballhspeed
 f = 255 : rem ballvspeed
 player0x = 16
 player1x = 140
 ballx = 75
 bally = 75
 drawscreen
 goto gamea

gameb
 if joy0up then player0y=player0y-1
 if joy0down then player0y=player0y+1
 if player0y<16 then player0y=16
 if player0y>80 then player0y=80
 if player1y<bally then player1y=player1y-1
 if player1y>bally then player1y=player1y+1
 if player1y<1 then player1y=1
 if player1y>88 then player1y=88
 if collision(ball,playfield) then f=0-f
 if collision(ball,player0) then e=0-e
 if collision(ball,player1) then e=0-e
 if collision(ball,player0) then f=0-f
 if collision(ball,player1) then f=0-f
 ballx = ballx + e + f
 if ballx<4 then score=score-1 : goto gamea
 if ballx>251 then score=score+1 : goto gamea
 REFP1 = 8
 drawscreen
 goto gameb
Attached File  pong_fix.bas   1.93K   29 downloads

Edited by jrok, Tue Jan 4, 2011 9:46 PM.


#5 SuperNESFreak OFFLINE  

SuperNESFreak

    Space Invader

  • 24 posts

Posted Wed Jan 5, 2011 8:58 AM

Thanks alot.

Yeah, I wasn't aware you could directly change the player0y variables - I thought they were like COLU variables.

One more question - which pixel is considered the centre of the sprite?

#6 Pong OFFLINE  

Pong

    Chopper Commander

  • 172 posts
  • Location:Canada

Posted Wed Jan 5, 2011 10:38 AM

Is it that hard to get me down? :D

Honestly, everything that the posters above me said.

#7 SuperNESFreak OFFLINE  

SuperNESFreak

    Space Invader

  • 24 posts

Posted Wed Jan 5, 2011 12:59 PM

Got a problem. Batari doesn't like ' if ballx<8 | ballx>155 then goto gamea' I'm guessing I've got the wrong or statement?

#8 jrok OFFLINE  

jrok

    Stargunner

  • 1,108 posts

Posted Wed Jan 5, 2011 2:14 PM

View PostSuperNESFreak, on Wed Jan 5, 2011 12:59 PM, said:

Got a problem. Batari doesn't like ' if ballx<8 | ballx>155 then goto gamea' I'm guessing I've got the wrong or statement?

The syntax for OR is "||"

#9 Mark loves Stella OFFLINE  

Mark loves Stella

    Combat Commando

  • 2 posts

Posted Wed Mar 23, 2011 7:33 PM

I wrote a pong type game back in december. I called it Tennis. You can look at my code to see how I got the ball physics.

Attached Thumbnails

  • tennis.png
  • tennis_2.png

Attached Files


Edited by Mark loves Stella, Fri May 20, 2011 6:58 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users