-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpong.bb
More file actions
161 lines (148 loc) · 3.16 KB
/
Copy pathpong.bb
File metadata and controls
161 lines (148 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
SeedRnd(MilliSecs())
timebegin = MilliSecs()
timeElapsed = MilliSecs()
playTo = 5
;Image Loading
bg = LoadImage("bg.bmp")
bgWin = LoadImage("backgroundWinner.bmp")
paddle1= LoadImage("playerone.bmp")
paddle2 = LoadImage("playertwo.bmp")
ball = LoadImage("ball.bmp")
blip = LoadSound("blip.wav")
blip2 = LoadSound("blip2.wav")
score = LoadSound("score.wav")
victory = LoadSound("victory.wav")
Graphics 800,600,32,2
SetBuffer BackBuffer()
;Variables
p1y = 200
p2y = 200
bx = 375
by = 275
dx = 4
dy = 4
;Loading Screen
While KeyDown(28)=0
Cls
If (KeyHit(1)) Then End
Text 300,200,"Welcome to pong!"
Text 300,300,"Score Selected: " + Str(playTo)
Text 220,350,"Use UP and DOWN to change goal score"
Text 300,375,"Press ENTER to play!"
If(KeyHit(200)=1) And playTo >= 1 Then
playTo = playTo + 1
EndIf
If(KeyHit(208)) And playTo >1 Then
playTo = playTo - 1
EndIf
Flip
Wend
playerOneScore = 0
playerTwoScore = 0
While KeyDown(1) = 0
DrawImage bg,0,0
DrawImage paddle1,0,p1y
DrawImage paddle2,775,p2y
DrawImage ball,bx,by
Text 200,50,"Player One: " + Str(playerOneScore)
Text 500,50,"Player Two: " + Str(playerTwoScore)
Text 375,50,"Speed: " + Str(dx)
Text 350,500,"Time Elapsed: " + Str((MilliSecs() - timeElapsed) / 1000)
;ball movement code
bx = bx + dx
by = by + dy
;Timecheck
If(MilliSecs() - timebegin) >= 5000
If dx < 0 Then
dx = dx - 1
ElseIf dx > 0 Then
dx = dx + 1
EndIf
If dy < 0 Then
dy = dy - 1
ElseIf dy > 0 Then
dy = dy + 1
EndIf
timebegin = MilliSecs()
EndIf
;ball collision code
If by <= 0 Or by >= 575 Then
dy = - dy
PlaySound blip2
EndIf
If bx <= 0 Then
playerTwoScore = playerTwoScore + 1
If dx < 0 Then
dx = -4
ElseIf dx > 0 Then
dx = 4
EndIf
If dy < 0 Then
dy = -4
ElseIf dy > 0 Then
dy = 4
EndIf
timebegin = MilliSecs()
If playerTwoScore >= playTop Then
bg = bgWin
DrawImage bg,0,0
Text 300,300,"Congrats, Player Two!"
PlaySound victory
Flip
Delay 5000
End
EndIf
bx = 375
by = 275
PlaySound score
dx = -dx
DrawImage ball,bx,by
Flip
Delay 2000
EndIf
If bx >= 775 Then
playerOneScore = playerOneScore + 1
If dx < 0 Then
dx = -4
ElseIf dx > 0 Then
dx = 4
EndIf
If dy < 0 Then
dy = -4
ElseIf dy > 0 Then
dy = 4
EndIf
timebegin = MilliSecs()
If playerOneScore >= playTo Then
bg = bgWin
DrawImage bg,0,0
Text 300,300,"Congrats, Player One!"
PlaySound victory
Flip
Delay 5000
End
EndIf
bx = 375
by = 275
PlaySound score
dx = -dx
DrawImage ball,bx,by
Flip
Delay 2000
EndIf
;Paddle Collision Code
If ImagesCollide(ball,bx,by,0,paddle1,0,p1y,0) Then
dx = -dx
PlaySound blip
EndIf
If ImagesCollide(ball,bx,by,0,paddle2,775,p2y,0) Then
dx = -dx
PlaySound blip
EndIf
;Keychecks!
If KeyDown(30) And p1y >= 5 Then p1y = p1y - 5
If KeyDown(44) And p1y <= 500 Then p1y = p1y + 5
If KeyDown(200) And p2y >= 5 Then p2y = p2y - 5
If KeyDown(208) And p2y <= 500 Then p2y = p2y + 5
Flip ;refresh the screen
Wend