Hello, All
I've got yet another problem. :(, I've been trying to make my own Breakout clone, i've got a pad that can move left and right and a ball that bounces around. Now if i leave the pad alone the ball bounces around without any lag or slow down...but soon as i start moving the pad both the pad and the ball slows down. this is very frustrating as i've just got everything working...
Source:
AppTitle "BreakIn!"
Local ScreenHeight = 165
Local ScreenWidth = 165
Graphics ScreenWidth,ScreenHeight
Local Pad = LoadImage("Pad.bmp")
Local PadX = ScreenWidth / 2 - ImageWidth(Pad) / 2
Local PadY = 128
Local PadSpeed = 15
Local Ball = LoadImage("Ball.bmp")
Local BallX = ScreenWidth / 2 - ImageWidth(Ball) / 2
Local BallY = PadY - ImageHeight(Ball)
Local BallSpeed = 0
Local BallDirection = 1
MaskImage Pad,250,250,250
MaskImage Ball,250,250,250
SetBuffer BackBuffer()
ClsColor 250,250,250
While Not KeyDown(1)
Cls
DrawImage Pad,PadX,PadY
DrawImage Ball,BallX,BallY
Flip
If KeyDown(203) And PadX => 1 Then PadX = PadX - 1: Delay PadSpeed ; Move Pad Left
If KeyDown(205) And PadX <= ScreenWidth - ImageWidth(Pad)-1 Then PadX = PadX + 1: Delay PadSpeed ; Move Pad Right
;;;;; If Ball Hits Sides Of Screen ;;;;;
; Collision Detection: Wall:Left
If BallX <= 0 And BallDirection = 1 Then BallDirection = 2
If BallX <= 0 And BallDirection = 4 Then BallDirection = 3
; Collision Detection: Wall:Top
If BallY <= 0 And BallDirection = 1 Then BallDirection = 4
If BallY <= 0 And BallDirection = 2 Then BallDirection = 3
; Collision Detection: Wall:Right
If BallX => ScreenWidth - ImageWidth(Ball) And BallDirection = 3 Then BallDirection = 4
If BallX => ScreenWidth - ImageWidth(Ball) And BallDirection = 2 Then BallDirection = 1
; Collision Detection: Wall:Bottom
If BallY => ScreenHeight - ImageHeight(Ball) And BallDirection = 3 Then BallDirection = 2
If BallY => ScreenHeight - ImageHeight(Ball) And BallDirection = 4 Then BallDirection = 1
;;;;; If Ball Hits Pad ;;;;;
If BallDirection = 4 And BallY => PadY - ImageHeight(Pad)+1 And BallY <= PadY And BallX <= PadX + ImageWidth(Pad)-1 And BallX => PadX - ImageWidth(Ball)+1 Then BallDirection = 1
If BallDirection = 3 And BallY => PadY - ImageHeight(Pad)+1 And BallY <= PadY And BallX <= PadX + ImageWidth(Pad)-1 And BallX => PadX - ImageWidth(Ball)+1 Then BallDirection = 2
; Collision Detection: Pad:Bottom
If BallDirection = 2 And BallY <= PadY + ImageHeight(Pad)-1 And BallY => PadY And BallX <= PadX + ImageWidth(Pad)-1 And BallX => PadX - ImageWidth(Ball)+1 Then BallDirection = 3
If BallDirection = 1 And BallY <= PadY + ImageHeight(Pad)-1 And BallY => PadY And BallX <= PadX + ImageWidth(Pad)-1 And BallX => PadX - ImageWidth(Ball)+1 Then BallDirection = 4
; Collision Detection: Pad:Right
If BallDirection = 4 And BallX <= PadX + ImageWidth(Ball)-1 And BallX => PadX And BallY => PadY - ImageHeight(Pad)+1 And BallY <= PadY + ImageHeight(Pad)-1 Then BallDirection = 2
If BallDirection = 1 And BallX <= PadX + ImageWidth(Ball)-1 And BallX => PadX And BallY => PadY - ImageHeight(Pad)+1 And BallY <= PadY + ImageHeight(Pad)-1 Then BallDirection = 3
; Collision Detection: Pad:Left
If BallDirection = 2 And BallX => PadX - ImageWidth(Ball)+1 And BallX <= PadX And BallY => PadY - ImageHeight(Pad)+1 And BallY <= PadY + ImageHeight(Pad)-1 Then BallDirection = 1
If BallDirection = 4 And BallX => PadX - ImageWidth(Ball)+1 And BallX <= PadX And BallY => PadY - ImageHeight(Pad)+1 And BallY <= PadY + ImageHeight(Pad)-1 Then BallDirection = 3
; Move Ball Around The Screen
If BallSpeed > 0 And BallDirection = 1 Then BallX = BallX - 2: BallY = BallY - 2: Delay BallSpeed ; Move Ball Top:Left
If BallSpeed > 0 And BallDirection = 2 Then BallX = BallX + 2: BallY = BallY - 2: Delay BallSpeed ; Move Ball Top:Right
If BallSpeed > 0 And BallDirection = 3 Then BallX = BallX + 2: BallY = BallY + 2: Delay BallSpeed ; Move Ball Bottom:Right
If BallSpeed > 0 And BallDirection = 4 Then BallX = BallX - 2: BallY = BallY + 2: Delay BallSpeed ; Move Ball Bottom:Left
; Start Ball Moving If It's Not
If BallSpeed = 0 And KeyDown(57) Then BallSpeed = 10
Wend
End
Could it be due to the fact i've got to many IF statements?
I've got yet another problem. :(, I've been trying to make my own Breakout clone, i've got a pad that can move left and right and a ball that bounces around. Now if i leave the pad alone the ball bounces around without any lag or slow down...but soon as i start moving the pad both the pad and the ball slows down. this is very frustrating as i've just got everything working...
Source:
AppTitle "BreakIn!"
Local ScreenHeight = 165
Local ScreenWidth = 165
Graphics ScreenWidth,ScreenHeight
Local Pad = LoadImage("Pad.bmp")
Local PadX = ScreenWidth / 2 - ImageWidth(Pad) / 2
Local PadY = 128
Local PadSpeed = 15
Local Ball = LoadImage("Ball.bmp")
Local BallX = ScreenWidth / 2 - ImageWidth(Ball) / 2
Local BallY = PadY - ImageHeight(Ball)
Local BallSpeed = 0
Local BallDirection = 1
MaskImage Pad,250,250,250
MaskImage Ball,250,250,250
SetBuffer BackBuffer()
ClsColor 250,250,250
While Not KeyDown(1)
Cls
DrawImage Pad,PadX,PadY
DrawImage Ball,BallX,BallY
Flip
If KeyDown(203) And PadX => 1 Then PadX = PadX - 1: Delay PadSpeed ; Move Pad Left
If KeyDown(205) And PadX <= ScreenWidth - ImageWidth(Pad)-1 Then PadX = PadX + 1: Delay PadSpeed ; Move Pad Right
;;;;; If Ball Hits Sides Of Screen ;;;;;
; Collision Detection: Wall:Left
If BallX <= 0 And BallDirection = 1 Then BallDirection = 2
If BallX <= 0 And BallDirection = 4 Then BallDirection = 3
; Collision Detection: Wall:Top
If BallY <= 0 And BallDirection = 1 Then BallDirection = 4
If BallY <= 0 And BallDirection = 2 Then BallDirection = 3
; Collision Detection: Wall:Right
If BallX => ScreenWidth - ImageWidth(Ball) And BallDirection = 3 Then BallDirection = 4
If BallX => ScreenWidth - ImageWidth(Ball) And BallDirection = 2 Then BallDirection = 1
; Collision Detection: Wall:Bottom
If BallY => ScreenHeight - ImageHeight(Ball) And BallDirection = 3 Then BallDirection = 2
If BallY => ScreenHeight - ImageHeight(Ball) And BallDirection = 4 Then BallDirection = 1
;;;;; If Ball Hits Pad ;;;;;
If BallDirection = 4 And BallY => PadY - ImageHeight(Pad)+1 And BallY <= PadY And BallX <= PadX + ImageWidth(Pad)-1 And BallX => PadX - ImageWidth(Ball)+1 Then BallDirection = 1
If BallDirection = 3 And BallY => PadY - ImageHeight(Pad)+1 And BallY <= PadY And BallX <= PadX + ImageWidth(Pad)-1 And BallX => PadX - ImageWidth(Ball)+1 Then BallDirection = 2
; Collision Detection: Pad:Bottom
If BallDirection = 2 And BallY <= PadY + ImageHeight(Pad)-1 And BallY => PadY And BallX <= PadX + ImageWidth(Pad)-1 And BallX => PadX - ImageWidth(Ball)+1 Then BallDirection = 3
If BallDirection = 1 And BallY <= PadY + ImageHeight(Pad)-1 And BallY => PadY And BallX <= PadX + ImageWidth(Pad)-1 And BallX => PadX - ImageWidth(Ball)+1 Then BallDirection = 4
; Collision Detection: Pad:Right
If BallDirection = 4 And BallX <= PadX + ImageWidth(Ball)-1 And BallX => PadX And BallY => PadY - ImageHeight(Pad)+1 And BallY <= PadY + ImageHeight(Pad)-1 Then BallDirection = 2
If BallDirection = 1 And BallX <= PadX + ImageWidth(Ball)-1 And BallX => PadX And BallY => PadY - ImageHeight(Pad)+1 And BallY <= PadY + ImageHeight(Pad)-1 Then BallDirection = 3
; Collision Detection: Pad:Left
If BallDirection = 2 And BallX => PadX - ImageWidth(Ball)+1 And BallX <= PadX And BallY => PadY - ImageHeight(Pad)+1 And BallY <= PadY + ImageHeight(Pad)-1 Then BallDirection = 1
If BallDirection = 4 And BallX => PadX - ImageWidth(Ball)+1 And BallX <= PadX And BallY => PadY - ImageHeight(Pad)+1 And BallY <= PadY + ImageHeight(Pad)-1 Then BallDirection = 3
; Move Ball Around The Screen
If BallSpeed > 0 And BallDirection = 1 Then BallX = BallX - 2: BallY = BallY - 2: Delay BallSpeed ; Move Ball Top:Left
If BallSpeed > 0 And BallDirection = 2 Then BallX = BallX + 2: BallY = BallY - 2: Delay BallSpeed ; Move Ball Top:Right
If BallSpeed > 0 And BallDirection = 3 Then BallX = BallX + 2: BallY = BallY + 2: Delay BallSpeed ; Move Ball Bottom:Right
If BallSpeed > 0 And BallDirection = 4 Then BallX = BallX - 2: BallY = BallY + 2: Delay BallSpeed ; Move Ball Bottom:Left
; Start Ball Moving If It's Not
If BallSpeed = 0 And KeyDown(57) Then BallSpeed = 10
Wend
End
Could it be due to the fact i've got to many IF statements?