I have totally messed up my pong game, me and my friend has been programming for 6 hours straight.
The problem is somewhere in the incredibly messy collision code, theres lots of stuff that's not even needed.
I am asking for someone to look at it if you have time.
the comments are in danish, dont mind them.
Thank you!
Global playerBat
Global PlayerBatposY = 250
Global PlayerBatposX = 0
Global opBat
Global opBatposY = 250
Global opBatposX = 760
Global Bold
Global BoldposY = 300
Global BoldposX = 400
Global BoldYdir = 4
Global BoldXdir = 4
Global BoldYdirPlayer
Global BoldXdirPlayer
Global BoldYdirOp
Global BoldXdirOp
Global Walltop
Global wallbottom
Graphics 800,600,16
SetBuffer BackBuffer()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Image loading /preloop stuff;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
playerBat=LoadImage("bat1.bmp")
MaskImage playerBat,221,121,192
opBat=LoadImage("Bat2.bmp")
MaskImage opBat,221,121,192
;Background=LoadImage("Background.bmp")
Bold=LoadImage("bold.bmp")
MaskImage Bold,221,121,192
Walltop=LoadImage("wall.bmp")
Wallbottom=LoadImage("wall.bmp")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Loop ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
While Not KeyHit(1)
Cls
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Drawing stuff etc... ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;TileImage Background,800,600
DrawImage playerBat,PlayerBatposX,PlayerBatposY
DrawImage opBat,opBatposX,opBatposY
DrawImage Bold,BoldposX,BoldposY
DrawImage Walltop,0,0
DrawImage Wallbottom,0,570
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Player-Movement stuff ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
If KeyDown(200) Then
PlayerBatposY = PlayerBatposY -10
EndIf
If KeyDown(208) Then
PlayerBatposY = PlayerBatposY +10
EndIf
;If PlayerBatposY < 0 Then
;PlayerBatposY = PlayerBatposY +10
;EndIf
;If PlayerBatposY > 500 Then
;PlayerBatposY = PlayerBatposY -10
;EndIf
;If PlayerBatposY > 495 Then
;BoldposY = BoldposY -boldYdir
;EndIf
;If PlayerBatposY < 0 Then
;BoldposY = BoldposY +BoldYdir
;EndIf
;If PlayerBatposY > 495 Then
;BoldposY = BoldposY -boldYdirPlayer
;EndIf
;If PlayerBatposY < 0 Then
;BoldposY = BoldposY +BoldYdirPlayer
;EndIf
;If PlayerBatposY > 495 Then
;BoldposY = BoldposY -boldYdirOp
;EndIf
;If PlayerBatposY < 0 Then
;BoldposY = BoldposY +BoldYdirOp
;EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Opponent-Player ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
opBatposY = BoldposY
;If opBatposY > 500 Then
;opBatposY = opBatposY +4
;EndIf
;If opBatposY < 0 Then
;opBatposY = opBatposY -4
;EndIf
;If opBatposY > 495 Then
;BoldposY = BoldposY -4
;EndIf
;If opBatposY < 0 Then
;BoldposY = BoldposY +4
;EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Ball Movement ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
BoldposY = BoldposY+BoldYdir+boldYdirPlayer+BoldYdirOp
BoldposX = BoldposX+BoldXdir+BoldXdirPlayer+BoldXdirOp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Collisions ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
If ImagesCollide (Bold,BoldposX,BoldposY,0,opBat,opBatposX,opBatposY,0) Then ;bold / modstanders bat kollision
BoldYdirOp = 0
BoldXdirOp = 0
BoldYdir = 0
BoldXdir = 0
BoldXdirPlayer = 0
BoldXdirPlayer = 0
Gosub opball
EndIf
If ImagesCollide (Bold,BoldposX,BoldposY,0,PlayerBat,PlayerBatposX,PlayerBatposY,0) Then ;bold / spillers bat kollision
BoldYdirOp = 0
BoldXdirOp = 0
BoldYdir = 0
BoldXdir = 0
BoldXdirPlayer = 0
BoldXdirPlayer = 0
Gosub playerball
EndIf
If ImagesCollide (opBat,opBatposX,opBatposY,0,Walltop,0,0,0) Then ;modstanders bat / overvæg kollision
Gosub ball
EndIf
If ImagesCollide (opBat,opBatposX,opBatposY,0,Wallbottom,0,570,0) Then ; Modstanders bat / undervæg kollision
Gosub ball
EndIf
If ImagesCollide (PlayerBat,PlayerBatposX,PlayerbatposY,0,Walltop,0,0,0) Then ; spillers bat / overvæg kollision
Gosub ball
EndIf
If ImagesCollide (PlayerBat,PlayerBatposX,PlayerbatposY,0,Wallbottom,0,0,0) Then ; spillers bat / undervæg kollision
Gosub ball
EndIf
If ImagesCollide (Bold,BoldposX,BoldposY,0,Walltop,0,0,0) Then ; bold / overvæg kollision
BoldYdirOp = 0
BoldXdirOp = 0
BoldYdir = 0
BoldXdir = 0
BoldXdirPlayer = 0
BoldXdirPlayer = 0
Gosub ball
EndIf
If ImagesCollide (Bold,BoldposX,BoldposY,0,Wallbottom,0,0,0) Then ; bold / undervæg kollision
BoldYdirOp = 0
BoldXdirOp = 0
BoldYdir = 0
BoldXdir = 0
BoldXdirPlayer = 0
BoldXdirPlayer = 0
Gosub ball
EndIf
Flip
Wend
End
.ball
BoldYdir = 0
BoldXdir = 0
BoldYdir = Rnd(-5,+5)
BoldXdir = Rnd(-5,+5)
Return
.playerball
BoldYdirPlayer = Rnd(0,+5)
BoldXdirPlayer = Rnd(0,+5)
Return
.opball
BoldYdirOp = Rnd(-5,0)
BoldXdirOp = Rnd(-5,0)
Return
The problem is somewhere in the incredibly messy collision code, theres lots of stuff that's not even needed.
I am asking for someone to look at it if you have time.
the comments are in danish, dont mind them.
Thank you!
Global playerBat
Global PlayerBatposY = 250
Global PlayerBatposX = 0
Global opBat
Global opBatposY = 250
Global opBatposX = 760
Global Bold
Global BoldposY = 300
Global BoldposX = 400
Global BoldYdir = 4
Global BoldXdir = 4
Global BoldYdirPlayer
Global BoldXdirPlayer
Global BoldYdirOp
Global BoldXdirOp
Global Walltop
Global wallbottom
Graphics 800,600,16
SetBuffer BackBuffer()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Image loading /preloop stuff;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
playerBat=LoadImage("bat1.bmp")
MaskImage playerBat,221,121,192
opBat=LoadImage("Bat2.bmp")
MaskImage opBat,221,121,192
;Background=LoadImage("Background.bmp")
Bold=LoadImage("bold.bmp")
MaskImage Bold,221,121,192
Walltop=LoadImage("wall.bmp")
Wallbottom=LoadImage("wall.bmp")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Loop ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
While Not KeyHit(1)
Cls
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Drawing stuff etc... ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;TileImage Background,800,600
DrawImage playerBat,PlayerBatposX,PlayerBatposY
DrawImage opBat,opBatposX,opBatposY
DrawImage Bold,BoldposX,BoldposY
DrawImage Walltop,0,0
DrawImage Wallbottom,0,570
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Player-Movement stuff ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
If KeyDown(200) Then
PlayerBatposY = PlayerBatposY -10
EndIf
If KeyDown(208) Then
PlayerBatposY = PlayerBatposY +10
EndIf
;If PlayerBatposY < 0 Then
;PlayerBatposY = PlayerBatposY +10
;EndIf
;If PlayerBatposY > 500 Then
;PlayerBatposY = PlayerBatposY -10
;EndIf
;If PlayerBatposY > 495 Then
;BoldposY = BoldposY -boldYdir
;EndIf
;If PlayerBatposY < 0 Then
;BoldposY = BoldposY +BoldYdir
;EndIf
;If PlayerBatposY > 495 Then
;BoldposY = BoldposY -boldYdirPlayer
;EndIf
;If PlayerBatposY < 0 Then
;BoldposY = BoldposY +BoldYdirPlayer
;EndIf
;If PlayerBatposY > 495 Then
;BoldposY = BoldposY -boldYdirOp
;EndIf
;If PlayerBatposY < 0 Then
;BoldposY = BoldposY +BoldYdirOp
;EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Opponent-Player ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
opBatposY = BoldposY
;If opBatposY > 500 Then
;opBatposY = opBatposY +4
;EndIf
;If opBatposY < 0 Then
;opBatposY = opBatposY -4
;EndIf
;If opBatposY > 495 Then
;BoldposY = BoldposY -4
;EndIf
;If opBatposY < 0 Then
;BoldposY = BoldposY +4
;EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Ball Movement ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
BoldposY = BoldposY+BoldYdir+boldYdirPlayer+BoldYdirOp
BoldposX = BoldposX+BoldXdir+BoldXdirPlayer+BoldXdirOp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Collisions ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
If ImagesCollide (Bold,BoldposX,BoldposY,0,opBat,opBatposX,opBatposY,0) Then ;bold / modstanders bat kollision
BoldYdirOp = 0
BoldXdirOp = 0
BoldYdir = 0
BoldXdir = 0
BoldXdirPlayer = 0
BoldXdirPlayer = 0
Gosub opball
EndIf
If ImagesCollide (Bold,BoldposX,BoldposY,0,PlayerBat,PlayerBatposX,PlayerBatposY,0) Then ;bold / spillers bat kollision
BoldYdirOp = 0
BoldXdirOp = 0
BoldYdir = 0
BoldXdir = 0
BoldXdirPlayer = 0
BoldXdirPlayer = 0
Gosub playerball
EndIf
If ImagesCollide (opBat,opBatposX,opBatposY,0,Walltop,0,0,0) Then ;modstanders bat / overvæg kollision
Gosub ball
EndIf
If ImagesCollide (opBat,opBatposX,opBatposY,0,Wallbottom,0,570,0) Then ; Modstanders bat / undervæg kollision
Gosub ball
EndIf
If ImagesCollide (PlayerBat,PlayerBatposX,PlayerbatposY,0,Walltop,0,0,0) Then ; spillers bat / overvæg kollision
Gosub ball
EndIf
If ImagesCollide (PlayerBat,PlayerBatposX,PlayerbatposY,0,Wallbottom,0,0,0) Then ; spillers bat / undervæg kollision
Gosub ball
EndIf
If ImagesCollide (Bold,BoldposX,BoldposY,0,Walltop,0,0,0) Then ; bold / overvæg kollision
BoldYdirOp = 0
BoldXdirOp = 0
BoldYdir = 0
BoldXdir = 0
BoldXdirPlayer = 0
BoldXdirPlayer = 0
Gosub ball
EndIf
If ImagesCollide (Bold,BoldposX,BoldposY,0,Wallbottom,0,0,0) Then ; bold / undervæg kollision
BoldYdirOp = 0
BoldXdirOp = 0
BoldYdir = 0
BoldXdir = 0
BoldXdirPlayer = 0
BoldXdirPlayer = 0
Gosub ball
EndIf
Flip
Wend
End
.ball
BoldYdir = 0
BoldXdir = 0
BoldYdir = Rnd(-5,+5)
BoldXdir = Rnd(-5,+5)
Return
.playerball
BoldYdirPlayer = Rnd(0,+5)
BoldXdirPlayer = Rnd(0,+5)
Return
.opball
BoldYdirOp = Rnd(-5,0)
BoldXdirOp = Rnd(-5,0)
Return