Restored from previous forum. Originally posted by Frankie.
I gotten pretty far on my pong game but i have only one problem
i want it when the ball hit any side of the screen the ball will bounce in the opposite direction so it have the bounce effect like pong put some reason when it hit at at the bottom it slides right and when it hit the right wall it just stops there and i dont know what is wrong i took at the sprite for the player movement so that you dont get any error so can any one help me
////////////////////////////
InitSprite()
InitSound()
InitMouse()
InitKeyboard()
OpenScreen(800,600,32,"Extreme Pong")
Global Player1x.f
Global Player1y.f
Global Player2x.f
Global Player2y.f
Global Ballx.l
Global Bally.l
Global Speedx.f
Global Speedy.f
Player1x = 0
Player1y = 0
Player2x = 790
Player2y = 0
Ballx = 0
Bally = 0
Speedx = 0
Speedy = 0
LoadSprite(1,"Paddle1.bmp")
LoadSprite(2,"Paddle2.bmp")
Procedure Bounce()
If Ballx 800
Ballx = 0 - Ballx
EndIf
If Bally 600
Bally = 0 - Bally
EndIf
EndProcedure
Procedure Move()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Up)
Player1y = Player1y -6
EndIf
If Player1y = 0
Player1y = Player1y + 6
EndIf
If KeyboardPushed(#PB_Key_Down)
Player1y = Player1y +6
EndIf
If Player1y >= 540
Player1y = Player1y - 6
EndIf
If KeyboardPushed(#PB_Key_Q)
Player2y = Player2y -6
EndIf
If Player2y = 0
Player2y = Player2y + 6
EndIf
If KeyboardPushed(#PB_Key_A)
Player2y = Player2y + 6
EndIf
If Player2y >= 540
Player2y = Player2y - 6
EndIf
Ballx = Speedx + Ballx
Bally = Speedy + Bally
EndProcedure
Procedure Draw()
StartDrawing(ScreenOutput())
Circle(Ballx,Bally,8,RGB(255,0,0))
DrawText("X"+Str(Ballx))
DrawText("Y"+Str(Bally))
StopDrawing()
FlipBuffers()
ClearScreen(0,0,0)
EndProcedure
Speedx = Speedx + 2
Speedy = Speedy + 2
Repeat
ExamineKeyboard()
Move()
Bounce()
Draw()
Until KeyboardPushed(#PB_Key_Escape)
Help With Pong
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by TheBeck.
I hope this helps.
I hope this helps.
Code: Select all
InitSprite()
InitSound()
InitMouse()
InitKeyboard()
OpenScreen(800,600,32,"Extreme Pong")
Global Player1x.f
Global Player1y.f
Global Player2x.f
Global Player2y.f
Global Ballx.l
Global Bally.l
Global Speedx.f
Global Speedy.f
Player1x = 0
Player1y = 0
Player2x = 790
Player2y = 0
Ballx = 0
Bally = 0
Speedx = 0
Speedy = 0
LoadSprite(1,"Paddle1.bmp")
LoadSprite(2,"Paddle2.bmp")
Procedure Bounce()
If Ballx 800
SpeedX = -1
EndIf
If Bally 600
Speedy = -1
EndIf
EndProcedure
Procedure Move()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Up)
Player1y = Player1y -6
EndIf
If Player1y = 0
Player1y = Player1y + 6
EndIf
If KeyboardPushed(#PB_Key_Down)
Player1y = Player1y +6
EndIf
If Player1y >= 540
Player1y = Player1y - 6
EndIf
If KeyboardPushed(#PB_Key_Q)
Player2y = Player2y -6
EndIf
If Player2y = 0
Player2y = Player2y + 6
EndIf
If KeyboardPushed(#PB_Key_A)
Player2y = Player2y + 6
EndIf
If Player2y >= 540
Player2y = Player2y - 6
EndIf
Ballx = Speedx + Ballx
Bally = Speedy + Bally
EndProcedure
Procedure Draw()
StartDrawing(ScreenOutput())
Circle(Ballx,Bally,8,RGB(255,0,0))
DrawText("X"+Str(Ballx))
DrawText("Y"+Str(Bally))
StopDrawing()
FlipBuffers()
ClearScreen(0,0,0)
EndProcedure
Speedx = Speedx + 2
Speedy = Speedy + 2
Repeat
ExamineKeyboard()
Move()
Bounce()
Draw()
Until KeyboardPushed(#PB_Key_Escape)-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Pupil.
Please format(indent)your code, makes it so much easier to read!! Use the forum commands to preserve the formating "(code)" and "(/code)", where the paranthesis is changed to square brackets "[" and "]".....
Anyway, change your bounce procedure to this and it will work:
Please format(indent)your code, makes it so much easier to read!! Use the forum commands to preserve the formating "(code)" and "(/code)", where the paranthesis is changed to square brackets "[" and "]".....
Anyway, change your bounce procedure to this and it will work:
Code: Select all
Procedure Bounce()
If Ballx 800
Speedx = - Speedx
EndIf
If Bally 600
Speedy = - Speedy
EndIf
EndProcedure
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Paul.
You could always look at the Pong Game example on the Resources Site to see how it was done
(in the Code Archive under 'Games in PB')
Of course it's more of a 'Breakout' than 'Pong' but has the same ideas.
----------
Visit the PB Resources Site at http://www.reelmediaproductions.com/pb
You could always look at the Pong Game example on the Resources Site to see how it was done
(in the Code Archive under 'Games in PB')
Of course it's more of a 'Breakout' than 'Pong' but has the same ideas.
----------
Visit the PB Resources Site at http://www.reelmediaproductions.com/pb