forked from daedalus2097/AIPong
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAIPong-Complete.asc
276 lines (193 loc) · 6.01 KB
/
AIPong-Complete.asc
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
; *** Introduction to Coding Workshop ***
; *** Amiga Ireland, January 2018 ***
WBStartup ; Directive, means executable can be started from Workbench
; Set up 320x256, 32-colour bitmap
BitMap 0, 320, 256, 5
NPrint "Loading assets..."
LoadPalette 0, "Assets/background.iff"
LoadSound 0, "Assets/boing.8svx"
LoadBitMap 0, "Assets/background.iff"
LoadShape 0, "Assets/player1.iff"
LoadShape 1, "Assets/player2.iff"
; This loop loads 14 different ball images with names ball1.iff to ball14.iff
; These are placed in Shape objects 2 to 15
For i = 1 To 14
LoadShape i + 1, "Assets/ball" + Str$(i) + ".iff"
Next i
NPrint "Creating sprites..."
For i = 0 To 15
MidHandle i
GetaSprite i, i
Next i
NPrint "Drawing borders..."
Boxf 0, 0, 319, 3, 10
Boxf 0, 252, 319, 255, 10
NPrint "Setting up display..."
; Set up Copper list with these parameters:
; - Y position = 44, roughly top of standard screen
; - 256 pixels high
; - 5 bitplanes, Low res standard display
; - 8 sprites activated
; - 32 colours
; - 0 space for custom instructions
InitCopList 0, 44, 256, $5, 8, 32, 0
NPrint "Setting up variables..."
NEWTYPE .player
yposition.w
score.w
End NEWTYPE
NEWTYPE .ball
xposition.w
yposition.w
xspeed.w
yspeed.w
animframe.w
End NEWTYPE
Dim players.player(1)
DEFTYPE .ball ball
quit.b = False
players(0)\yposition = 128
players(1)\yposition = 128
ball\xposition = 160
ball\yposition = 128
ball\xspeed = 2000
ball\yspeed = 2000
ball\animframe = 2
playerspeed.w = 4
Statement drawscores{player.w, score.w}
; This procedure draws the score required to the bitmap
BitMapOutput 0
If player = 0
Colour 18
;Boxf 23, 15, 63, 23, 0
Locate 3, 2
Else
Colour 22
;Boxf 23, 15, 63, 23, 0
Locate 36, 3
End If
NPrint score
DisplayBitMap 0, 0
End Statement
Statement flashplayer{player.w}
SHARED players()
If player = 0
playerx.w = 10
Else
playerx.w = 309
End If
BLITZ ; Required for debugger
For i = 1 To 3
DisplaySprite 0, player, playerx, 400, player * 2
VWait 15
DisplaySprite 0, player, playerx, players(player)\yposition, player * 2
VWait 15
Next i
End Statement
AMIGA ; required for debugger
; *** Setup complete, now it's time to take over the system and start our game
NPrint "Entering BLITZ mode..."
VWait 25
BLITZ
AGAPalRGB 0, 30, 0, 0, 255
CreateDisplay 0
DisplayPalette 0, 0
drawscores{0, 0}
drawscores{1, 0}
DisplayBitMap 0, 0
Repeat
VWait
.graphics_updates
; *** Update graphics section
DisplaySprite 0, 0, 10, players(0)\yposition, 0
DisplaySprite 0, 1, 309, players(1)\yposition, 2
DisplaySprite 0, ball\animframe, ball\xposition, ball\yposition, 4
ball\animframe + 1
If ball\animframe = 16 Then ball\animframe = 2
; *** End of Update graphics section
.player_movement
; *** Player movement section
; Players can move up or down. Player 1 (0) is controlled by the player 1 joystick port
; Player 2 (1) is controlled by the arrow keys
If Joyy(1) = 1
; This happens when player 1 pushes down
players(0)\yposition + playerspeed
If players(0)\yposition > 232 Then players(0)\yposition = 232
End If
If Joyy(1) = -1
; This happens when player 1 pushes up
players(0)\yposition - playerspeed
If players(0)\yposition < 24 Then players(0)\yposition = 24
End If
If RawStatus($4D)
; This happens when player 2 pushes down
players(1)\yposition + playerspeed
If players(1)\yposition > 232 Then players(1)\yposition = 232
End If
If RawStatus($4C)
; This happens when player 2 pushes up
players(1)\yposition - playerspeed
If players(1)\yposition < 24 Then players(1)\yposition = 24
End If
; *** End of Player movement section
.ball_movement
; *** Ball movement section
ball\xposition + (ball\xspeed / 1000)
ball\yposition + (ball\yspeed / 1000)
If ball\xposition <= 0
; This happens when the ball hits the very left of the screen
players(1)\score + 1
ball\xposition = 160
ball\yposition = 128
ball\xspeed = Sgn(ball\xspeed) * 2000
ball\yspeed = Sgn(ball\yspeed) * 2000
flashplayer{0}
drawscores{1, players(1)\score}
;VWait 50
End If
If ball\xposition >= 319
; This happens when the ball hits the very right of the screen
players(0)\score + 1
ball\xposition = 160
ball\yposition = 128
ball\xspeed = Sgn(ball\xspeed) * 2000
ball\yspeed = Sgn(ball\yspeed) * 2000
flashplayer{1}
drawscores{0, players(0)\score}
;VWait 50
End If
If ball\yposition <= 16
ball\yspeed = Abs(ball\yspeed)
Sound 0, %0101
End If
If ball\yposition >= 239
ball\yspeed = Abs(ball\yspeed) * -1
Sound 0, %0101
End If
ball\xspeed + 5 * Sgn(ball\xspeed)
ball\yspeed + 5 * Sgn(ball\yspeed)
; *** End of ball movement section
.collision_detection
; *** Collision detection section
If ball\xposition < 32 AND ball\xposition > 20
; Ball is in batting zone
If ball\yposition > players(0)\yposition - 24 AND ball\yposition < players(0)\yposition + 24
; Player 1 has hit the ball, set speed to positive value
ball\xspeed = Abs(ball\xspeed)
Sound 0, %0101
End If
End If
If ball\xposition > 287 AND ball\xposition < 299
; Ball is in batting zone
If ball\yposition > players(1)\yposition - 24 AND ball\yposition < players(1)\yposition + 24
; Player 2 has hit the ball, set speed to negative value
ball\xspeed = Abs(ball\xspeed) * -1
Sound 0, %0101
End If
End If
; *** End of collision detection section
If RawStatus($45) ; Escape key pressed
quit = True
End If
Until quit = True
End