SHOW:
|
|
- or go back to the newest paste.
1 | This is a basic maze game I created using the Assembler. | |
2 | ||
3 | TITLE Maze Game INCLUDE Irvine32.inc | |
4 | ;Wall = 35 | |
5 | ;Exit = 88 | |
6 | ;Player = 42 | |
7 | ;Prize = 80 | |
8 | ;Blank = 00 | |
9 | .data Maze | |
10 | DWORD 35,35,35,35,35,35,35,35,35,35,35,35,88,35,35,35,35,35,35,35 | |
11 | rowSize = ($ - Maze) | |
12 | DWORD 35,35,35,35,35,35,35,35,00,00,00,00,00,35,35,35,35,00,80,35 | |
13 | DWORD 35,35,35,35,35,35,35,35,00,35,35,35,35,35,35,35,35,00,35,35 | |
14 | DWORD 35,35,00,00,00,00,00,00,00,35,00,35,35,35,35,35,35,00,35,35 | |
15 | DWORD 35,35,00,35,35,35,35,35,35,35,00,35,35,35,35,35,35,00,35,35 | |
16 | DWORD 35,35,00,35,35,35,00,35,35,35,00,00,00,00,00,00,35,00,35,35 | |
17 | DWORD 35,35,00,00,00,00,00,35,35,35,00,35,35,35,35,00,00,00,35,35 | |
18 | DWORD 35,35,35,35,35,35,00,00,00,00,00,35,80,00,35,35,35,00,00,35 | |
19 | DWORD 35,35,35,35,35,35,35,35,35,35,35,35,35,00,35,35,35,35,00,35 | |
20 | DWORD 35,80,00,00,00,00,00,00,00,35,35,35,35,00,35,35,35,00,00,35 | |
21 | DWORD 35,35,35,35,35,00,35,35,00,00,00,00,00,00,35,35,35,00,35,35 | |
22 | DWORD 35,35,35,00,00,00,35,35,00,35,35,35,35,00,35,35,35,00,00,35 | |
23 | DWORD 35,35,35,00,35,35,35,35,00,35,35,35,35,00,35,35,35,35,00,35 | |
24 | DWORD 35,00,00,00,35,35,35,35,00,00,35,35,35,00,00,00,00,35,00,35 | |
25 | DWORD 35,00,35,35,00,00,00,35,35,35,35,35,35,35,35,35,00,35,00,35 | |
26 | DWORD 35,00,35,35,00,35,00,00,35,35,35,35,35,80,35,35,00,35,00,35 | |
27 | DWORD 35,00,00,35,00,35,35,00,35,35,35,35,35,00,35,35,00,00,00,35 | |
28 | DWORD 35,35,00,00,00,35,35,00,00,00,00,00,00,00,35,35,35,00,35,35 | |
29 | DWORD 35,35,35,35,80,35,35,35,35,35,42,35,35,35,35,35,35,80,35,35 | |
30 | DWORD 35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35 | |
31 | timer DWORD 100 | |
32 | score DWORD 100 | |
33 | playerPosition DWORD 1480 | |
34 | UPDOWN DWORD 80 | |
35 | LEFTRIGHT DWORD 4 | |
36 | messageDirections BYTE "Use the arrow keys to move", 0dh, 0ah, 0 | |
37 | messageTime BYTE "Time Past", 0dh, 0ah, 0 | |
38 | messageScore BYTE "Your Score is ", 0dh, 0ah, 0 | |
39 | startTime DWORD ? | |
40 | divisor DWORD ? | |
41 | timeTaken DWORD ? | |
42 | difference DWORD ? | |
43 | scoreStart DWORD ? | |
44 | prizeScore DWORD 0 | |
45 | .code | |
46 | ;************************************************************************* ;********************************START**MAIN****************************** ;************************************************************************* | |
47 | main PROC mov edx, 0 ;Register to end game | |
48 | INVOKE GetTickCount | |
49 | mov startTime, eax | |
50 | GameLoop: | |
51 | cmp edx, 99 ;End game value equals 99 | |
52 | je EndGame | |
53 | call TimerScore | |
54 | call ReadKey | |
55 | jz GameLoop | |
56 | cmp ah, 72 ;Up arrow key | |
57 | je Up | |
58 | cmp ah, 80 ;Down arrow key | |
59 | je Down | |
60 | cmp ah, 75 ;Left arrow key | |
61 | je Left | |
62 | cmp ah, 77 ;Right arrow key | |
63 | je Right | |
64 | Up: | |
65 | call UpMove | |
66 | call Next Down: | |
67 | call DownMove | |
68 | call Next Left: | |
69 | call LeftMove | |
70 | call Next Right: | |
71 | call RightMove | |
72 | call Next Next: | |
73 | jmp GameLoop | |
74 | EndGame: | |
75 | call TimerCount | |
76 | call Crlf | |
77 | call WaitMsg | |
78 | exit main | |
79 | ENDP | |
80 | ;************************************************************************* ;********************************END**MAIN******************************** ;************************************************************************* ;--------------------------------------------------------------------------- ;========================================================================= ;========================================================================= | |
81 | TimerScore PROC | |
82 | call TimerCount | |
83 | mov scoreStart, 99 | |
84 | mov score, eax | |
85 | mov ebx, ScoreStart | |
86 | mov ecx, timeTaken ;get incrementing time | |
87 | sub ebx, ecx | |
88 | mov edx, prizeScore | |
89 | add edx, score | |
90 | mov score, ebx | |
91 | add ebx, prizeScore | |
92 | mov score, ebx | |
93 | call Draw | |
94 | mov edx,OFFSET MessageScore | |
95 | call WriteString ;Call Write String procdure | |
96 | mov eax, score | |
97 | call WriteInt | |
98 | call Crlf | |
99 | ret TimerScore | |
100 | ENDP | |
101 | UpMove PROC | |
102 | mov esi, OFFSET Maze | |
103 | add esi, playerPosition | |
104 | sub esi, UPDOWN | |
105 | ;Move up | |
106 | mov eax, [esi] | |
107 | cmp eax, 00 | |
108 | ;Open Spot | |
109 | je ValidUp | |
110 | cmp eax, 35 | |
111 | ;Wall | |
112 | je Wall | |
113 | cmp eax, 80 ;Prize | |
114 | je PrizeJump | |
115 | cmp eax, 88 ;Exit | |
116 | je ExitGame | |
117 | ValidUp: | |
118 | mov eax, playerPosition ;Move the indirect value of ebx postion 1 into eax | |
119 | mov eax, 42 ;move the player charater into eax | |
120 | mov [esi], eax ;move the character into the 2D array | |
121 | add esi, UPDOWN ;add the constant number 80 to the 2D array | |
122 | mov eax, 00 ;Move the charater into eax | |
123 | mov [esi], eax ;move the character into the 2D array | |
124 | mov eax, playerPosition ;Move the player position into eax | |
125 | sub eax, UPDOWN ;subtract 80 from the player position | |
126 | mov playerPosition, eax ;Save the new player position | |
127 | jmp MoveDone | |
128 | PrizeJump: | |
129 | mov eax, playerPosition ;Move the indirect value of ebx postion 1 into eax | |
130 | mov eax, 42 ;Move the player charater into eax | |
131 | mov [esi], eax ;Move the character into the 2D array | |
132 | add esi, UPDOWN ;Add the constant number 80 to the 2D array | |
133 | mov eax, 00 ;Move the charater into eax | |
134 | mov [esi], eax ;Move the character into the 2D array | |
135 | mov eax, playerPosition ;Move the player position into eax | |
136 | sub eax, UPDOWN ;Subtract 80 from the player position | |
137 | mov playerPosition, eax ;Save the new player position | |
138 | mov ebx, prizeScore | |
139 | add prizeScore, 25 ;Add 25 to the score | |
140 | jmp MoveDone ;Move to done | |
141 | Wall: | |
142 | jmp MoveDone | |
143 | ExitGame: | |
144 | mov edx, 99 ;exit game | |
145 | MoveDone: | |
146 | ret UpMove | |
147 | ENDP | |
148 | ;========================================================================= ;========================================================================= | |
149 | DownMove PROC | |
150 | mov esi, OFFSET Maze | |
151 | add esi, playerPosition | |
152 | add esi, UPDOWN ;Move up | |
153 | mov eax, [esi] | |
154 | cmp eax, 00 ;Open Spot | |
155 | je ValidDown | |
156 | cmp eax, 35 ;Wall | |
157 | je Wall | |
158 | cmp eax, 80 ;Prize | |
159 | je PrizeJump | |
160 | cmp eax, 88 ;Exit | |
161 | je ExitGame | |
162 | ValidDown: | |
163 | mov eax, playerPosition ;Move the indirect value of ebx postion 1 into eax | |
164 | mov eax, 42 | |
165 | mov [esi], eax | |
166 | sub esi, UPDOWN | |
167 | mov eax, 00 | |
168 | mov [esi], eax | |
169 | mov eax, playerPosition | |
170 | add eax, UPDOWN | |
171 | mov PlayerPosition, eax | |
172 | jmp MoveDone | |
173 | PrizeJump: | |
174 | mov eax, playerPosition ;Move the indirect value of ebx postion 1 into eax | |
175 | mov eax, 42 ;Move the player character into eax | |
176 | mov [esi], eax ;Move the character into the 2D array | |
177 | sub esi, UPDOWN ;Add the constant number 80 to the 2D array | |
178 | mov eax, 00 ;Move the character into eax | |
179 | mov [esi], eax ;Move the character into the 2D array | |
180 | mov eax, playerPosition ;Move the player position into eax | |
181 | add eax, UPDOWN ;Subtract 80 from the player position | |
182 | mov playerPosition, eax ;Save the new player position | |
183 | mov ebx, prizeScore | |
184 | add prizeScore, 25 ;Add 25 to the score | |
185 | jmp MoveDone ;Move to done | |
186 | Wall: | |
187 | jmp MoveDone | |
188 | ExitGame: | |
189 | mov edx, 99 | |
190 | MoveDone: | |
191 | ret DownMove | |
192 | ENDP | |
193 | ;========================================================================= | |
194 | ;========================================================================= | |
195 | LeftMove PROC | |
196 | mov esi, OFFSET Maze | |
197 | add esi, playerPosition | |
198 | sub esi, LEFTRIGHT ;Move Left | |
199 | mov eax, [esi] | |
200 | cmp eax, 00 ;Open Spot | |
201 | je ValidLeft | |
202 | cmp eax, 35 | |
203 | ;Wall | |
204 | je Wall | |
205 | cmp eax, 80 ;Prize | |
206 | je PrizeJump | |
207 | cmp eax, 88 ;Exit | |
208 | je ExitGame | |
209 | ValidLeft: | |
210 | mov eax, playerPosition ;Move the indirect value of ebx postion 1 into eax | |
211 | mov eax, 42 | |
212 | mov [esi], eax | |
213 | add esi, LEFTRIGHT | |
214 | mov eax, 00 | |
215 | mov [esi], eax | |
216 | mov eax, playerPosition | |
217 | sub eax, LEFTRIGHT | |
218 | mov PlayerPosition, eax | |
219 | jmp MoveDone | |
220 | PrizeJump: | |
221 | mov eax, playerPosition ;Move the indirect value of ebx postion 1 into eax | |
222 | mov eax, 42 ;Move the player charater into eax | |
223 | mov [esi], eax | |
224 | ;Move the character into the 2D array | |
225 | add esi, LEFTRIGHT ;Add the constant number 80 to the 2D array | |
226 | mov eax, 00 ;Move the charater into eax | |
227 | mov [esi], eax ;Move the character into the 2D array | |
228 | mov eax, playerPosition ;Move the player position into eax | |
229 | sub eax, LEFTRIGHT ;Subtract 80 from the player position | |
230 | mov playerPosition, eax ;Save the new player position | |
231 | mov ebx, prizeScore | |
232 | add prizeScore, 25 ;Add 25 to the score | |
233 | jmp MoveDone ;Move to done | |
234 | Wall: | |
235 | jmp MoveDone | |
236 | ExitGame: | |
237 | mov edx, 99 | |
238 | MoveDone: | |
239 | ret LeftMove | |
240 | ENDP | |
241 | ;========================================================================= ;========================================================================= | |
242 | RightMove PROC | |
243 | mov esi, OFFSET Maze | |
244 | add esi, playerPosition | |
245 | add esi, LEFTRIGHT | |
246 | ;Move Left | |
247 | mov eax, [esi] | |
248 | cmp eax, 00 | |
249 | ;Open Spot | |
250 | je ValidRight | |
251 | cmp eax, 35 ;Wall | |
252 | je Wall | |
253 | cmp eax, 80 ;Prize | |
254 | je PrizeJump | |
255 | cmp eax, 88 ;Exit | |
256 | je ExitGame | |
257 | ValidRight: | |
258 | mov eax, playerPosition ;Move the indirect value of ebx postion 1 into eax | |
259 | mov eax, 42 | |
260 | mov [esi], eax | |
261 | sub esi, LEFTRIGHT | |
262 | mov eax, 00 | |
263 | mov [esi], eax | |
264 | mov eax, playerPosition | |
265 | add eax, LEFTRIGHT | |
266 | mov playerPosition, eax | |
267 | jmp MoveDone | |
268 | PrizeJump: | |
269 | mov eax, playerPosition ;Move the indirect value of ebx postion 1 into eax | |
270 | mov eax, 42 ;Move the player charater into eax | |
271 | mov [esi], eax ;Move the character into the 2D array | |
272 | sub esi, LEFTRIGHT ;Add the constant number 80 to the 2D array | |
273 | mov eax, 00 ;Move the charater into eax | |
274 | mov [esi], eax ;Move the character into the 2D array | |
275 | mov eax, playerPosition ;Move the player position into eax | |
276 | add eax, LEFTRIGHT ;Subtract 80 from the player position | |
277 | mov playerPosition, eax ;Save the new player position | |
278 | mov ebx, prizeScore ;Move the score to the register | |
279 | add prizeScore, 25 ;Add 25 to the score | |
280 | jmp MoveDone ;Move to done | |
281 | Wall: | |
282 | jmp MoveDone | |
283 | ExitGame: | |
284 | mov edx, 99 | |
285 | MoveDone: | |
286 | ret RightMove | |
287 | ENDP | |
288 | ;========================================================================= ;========================================================================= | |
289 | Draw PROC | |
290 | mov dh, 0 ;Set maze position X | |
291 | mov dl, 0 ;Set maze position Y | |
292 | call Gotoxy ;Call Go to X Y | |
293 | mov ebx, OFFSET Maze ;Move the maze 2D array into ebx | |
294 | mov ecx, 0 ;intialize the counter | |
295 | PrintLoop: | |
296 | mov eax, [ebx] ;Move the indirect value of ebx postion 1 into eax | |
297 | add ebx, 4 ;Move to the next offset position | |
298 | inc ecx ;Increment the counter | |
299 | call WriteChar ;Write Character | |
300 | cmp ecx, 20 ;Compare for end of row for each 20 positions | |
301 | je NextLine | |
302 | cmp ecx, 40 | |
303 | je NextLine | |
304 | cmp ecx, 60 | |
305 | je NextLine | |
306 | cmp ecx, 80 | |
307 | je NextLine | |
308 | cmp ecx, 100 | |
309 | je NextLine | |
310 | cmp ecx, 120 | |
311 | je NextLine | |
312 | cmp ecx, 140 | |
313 | je NextLine | |
314 | cmp ecx, 160 | |
315 | je NextLine | |
316 | cmp ecx, 180 | |
317 | je NextLine | |
318 | cmp ecx, 200 | |
319 | je NextLine | |
320 | cmp ecx, 220 | |
321 | je NextLine | |
322 | cmp ecx, 240 | |
323 | je NextLine | |
324 | cmp ecx, 260 | |
325 | je NextLine | |
326 | cmp ecx, 280 | |
327 | je NextLine | |
328 | cmp ecx, 300 | |
329 | je NextLine | |
330 | cmp ecx, 320 | |
331 | je NextLine | |
332 | cmp ecx, 340 | |
333 | je NextLine | |
334 | cmp ecx, 360 | |
335 | je NextLine | |
336 | cmp ecx, 380 | |
337 | je NextLine | |
338 | cmp ecx, 400 | |
339 | jne PrintLoop | |
340 | jmp Print | |
341 | NextLine: | |
342 | call Crlf | |
343 | jmp PrintLoop | |
344 | Print: | |
345 | call Crlf | |
346 | mov edx,OFFSET MessageDirections | |
347 | call WriteString ;Call Write String procdure ret Draw ENDP | |
348 | ;========================================================================= ;========================================================================= | |
349 | TimerCount PROC | |
350 | INVOKE GetTickCount | |
351 | sub eax, startTime | |
352 | mov divisor, 1000 ;milisecs div divisor | |
353 | mov edx,OFFSET messageTime | |
354 | call WriteString | |
355 | mov timeTaken, eax | |
356 | call WriteInt ;Call Write String procdure | |
357 | ret TimerCount ENDP | |
358 | ;========================================================================= ;========================================================================= | |
359 | END main |