Posted: Fri Feb 14, 2003 10:47 pm
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)
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)