Browse Source

adding in ecen427 space invaders final lab

Derek McQuay 2 years ago
parent
commit
110f83b420

+ 337
- 0
ecen427/alien.c View File

@@ -0,0 +1,337 @@
1
+#include "alien.h"
2
+
3
+int leftLim;
4
+int rightLim;
5
+
6
+void renderAlien(unsigned int* framePointer) {
7
+	if(getGuise() == 0) {
8
+		setGuise(1);
9
+		renderAlien1(framePointer);
10
+	}else {
11
+		setGuise(0);
12
+		renderAlien2(framePointer);
13
+	}
14
+}
15
+
16
+void renderAlien1(unsigned int* framePointer) {
17
+	short alienx, alieny;
18
+	alienx = getAlienBlockPositionX();
19
+	alieny = getAlienBlockPositionY();
20
+	short row=0, col=0;
21
+	short line = 0;
22
+	short position = 0;
23
+	short* aliens = getAliens();
24
+	for(line = 0; line < 10; line++) {
25
+		if(line % 2 == 1) {
26
+			alieny += 10;
27
+		}
28
+		else {
29
+			if(line == 0) {
30
+				for(row=0; row<16; row++) {
31
+					short position_helper = -1;
32
+					for(col=0; col<352; col++) {
33
+						if (((topAlien1[row%16] & (1<<(32-1-col)))) && aliens[position+position_helper] == 1) {
34
+							framePointer[alieny*640 + alienx] = 0x00FFFFFF;
35
+						}
36
+//						else if(aliens[position+position_helper] == 0) {
37
+//
38
+//						}
39
+						else {
40
+							framePointer[alieny*640 + alienx] = 0x00000000;
41
+						}
42
+						if(col % 32 == 0) {
43
+							position_helper++;
44
+						}
45
+						alienx++;
46
+					}
47
+					alienx=getAlienBlockPositionX();
48
+					alieny++;
49
+				}
50
+			}
51
+			if(line == 2 || line == 4) {
52
+				position += 11;
53
+				for(row=0; row<16; row++) {
54
+					short position_helper = -1;
55
+					for(col=0; col<352; col++) {
56
+						if (((middleAlien1[row%16] & (1<<(32-1-col)))) && aliens[position+position_helper] == 1) {
57
+							framePointer[alieny*640 + alienx] = 0x00FFFFFF;
58
+						}
59
+//						else if(aliens[position+position_helper] == 0) {
60
+//
61
+//						}
62
+						else {
63
+							framePointer[alieny*640 + alienx] = 0x00000000;
64
+						}
65
+						if(col % 32 == 0) {
66
+							position_helper++;
67
+						}
68
+						alienx++;
69
+					}
70
+					alienx=getAlienBlockPositionX();
71
+					alieny++;
72
+				}
73
+			}
74
+			if(line == 6 || line == 8) {
75
+				position += 11;
76
+				for(row=0; row<16; row++) {
77
+					short position_helper = -1;
78
+					for(col=0; col<352; col++) {
79
+						if (((bottomAlien1[row%16] & (1<<(32-1-col))))&& aliens[position+position_helper] == 1) {
80
+							framePointer[alieny*640 + alienx] = 0x00FFFFFF;
81
+						}
82
+//						else if( aliens[position+position_helper] == 0) {
83
+//
84
+//						}
85
+						else {
86
+							framePointer[alieny*640 + alienx] = 0x00000000;
87
+						}
88
+						if(col % 32 == 0) {
89
+							position_helper++;
90
+						}
91
+						alienx++;
92
+					}
93
+					alienx=getAlienBlockPositionX();
94
+					alieny++;
95
+				}
96
+			}
97
+		}
98
+	}
99
+}
100
+
101
+void renderAlien2(unsigned int* framePointer) {
102
+	short alienx, alieny;
103
+	alienx = getAlienBlockPositionX();
104
+	alieny = getAlienBlockPositionY();
105
+	short row=0, col=0;
106
+	short line = 0;
107
+	short position = 0;
108
+	short* aliens = getAliens();
109
+	for(line = 0; line < 10; line++) {
110
+		if(line % 2 == 1) {
111
+			alieny += 10;
112
+		}
113
+		else {
114
+			if(line == 0) {
115
+				for(row=0; row<16; row++) {
116
+					short position_helper = -1;
117
+					for(col=0; col<352; col++) {
118
+						if (((topAlien2[row%16] & (1<<(32-1-col)))) && aliens[position+position_helper] == 1) {
119
+							framePointer[alieny*640 + alienx] = 0x00FFFFFF;
120
+						}
121
+//						else if(aliens[position+position_helper] == 0) {
122
+//
123
+//						}
124
+						else {
125
+							framePointer[alieny*640 + alienx] = 0x00000000;
126
+						}
127
+						if(col % 32 == 0) {
128
+							position_helper++;
129
+						}
130
+						alienx++;
131
+					}
132
+					alienx=getAlienBlockPositionX();
133
+					alieny++;
134
+				}
135
+			}
136
+			if(line == 2 || line == 4) {
137
+				position += 11;
138
+				for(row=0; row<16; row++) {
139
+					short position_helper = -1;
140
+					for(col=0; col<352; col++) {
141
+						if (((middleAlien2[row%16] & (1<<(32-1-col))))&& aliens[position+position_helper] == 1) {
142
+							framePointer[alieny*640 + alienx] = 0x00FFFFFF;
143
+						}
144
+//						else if(aliens[position+position_helper] == 0) {
145
+//
146
+//						}
147
+						else {
148
+							framePointer[alieny*640 + alienx] = 0x00000000;
149
+						}
150
+						if(col % 32 == 0) {
151
+							position_helper++;
152
+						}
153
+						alienx++;
154
+					}
155
+					alienx=getAlienBlockPositionX();
156
+					alieny++;
157
+				}
158
+			}
159
+			if(line == 6 || line == 8) {
160
+				position += 11;
161
+				for(row=0; row<16; row++) {
162
+					short position_helper = -1;
163
+					for(col=0; col<352; col++) {
164
+						if (((bottomAlien2[row%16] & (1<<(32-1-col))))&& aliens[position+position_helper] == 1) {
165
+							framePointer[alieny*640 + alienx] = 0x00FFFFFF;
166
+						}
167
+//						else if(aliens[position+position_helper] == 0) {
168
+//
169
+//						}
170
+						else {
171
+							framePointer[alieny*640 + alienx] = 0x00000000;
172
+						}
173
+						if(col % 32 == 0) {
174
+							position_helper++;
175
+						}
176
+						alienx++;
177
+					}
178
+					alienx=getAlienBlockPositionX();
179
+					alieny++;
180
+				}
181
+			}
182
+		}
183
+	}
184
+}
185
+
186
+void blankAlien(unsigned int* framePointer){
187
+	short alienx, alieny;
188
+	alienx = getAlienBlockPositionX();
189
+	alieny = getAlienBlockPositionY();
190
+	short row=0, col=0;
191
+	for(row = 0; row < 130; row++){
192
+		for(col = 0; col < 352; col++){
193
+			framePointer[alieny*640 + alienx] = 0x00000000;
194
+			alienx++;
195
+		}
196
+		alienx=getAlienBlockPositionX();
197
+		alieny++;
198
+	}
199
+}
200
+
201
+void dyingAlien(unsigned int* framePointer, short alienx, short alieny) {
202
+	short row=0, col=0;
203
+	for(row = 0; row < 16; row++){
204
+		for(col = 0; col < 32; col++){
205
+			if ((dying_alien[row%16] & (1<<(32-1-col)))) {
206
+				framePointer[(alieny+row)*640 + alienx+col] = 0x00FFFFFE;
207
+			} else {
208
+				framePointer[(alieny+row)*640 + alienx+col] = 0x00000000;
209
+			}
210
+		}
211
+	}
212
+}
213
+
214
+void dyingAlienHelper(unsigned int* framePointer, short alienx, short alieny) {
215
+	short row=0, col=0;
216
+	for(row = 0; row < 16; row++){
217
+		for(col = 0; col < 32; col++){
218
+				framePointer[(alieny+row)*640 + alienx+col] = 0x00000000;
219
+		}
220
+	}
221
+}
222
+
223
+int columnCheck(int value) {
224
+	short* aliens = getAliens();
225
+	if(aliens[value] == 0 && aliens[value+11] == 0 && aliens[value+22] == 0 && aliens[value+33] == 0 && aliens[value+44] == 0) {
226
+		return 0;
227
+	}
228
+	return 1;
229
+}
230
+
231
+int setRightMax() {
232
+	int max = 352;
233
+	if(!columnCheck(10)) {
234
+		max = 320;
235
+		if(!columnCheck(9)) {
236
+			max = 288;
237
+			if(!columnCheck(8)) {
238
+				max = 256;
239
+				if(!columnCheck(7)) {
240
+					max = 224;
241
+					if(!columnCheck(6)) {
242
+						max = 192;
243
+						if(!columnCheck(5)) {
244
+							max = 160;
245
+							if(!columnCheck(4)) {
246
+								max = 128;
247
+								if(!columnCheck(3)) {
248
+									max = 96;
249
+									if(!columnCheck(2)) {
250
+										max = 64;
251
+										if(!columnCheck(1)) {
252
+											max = 32;
253
+											if(!columnCheck(0)) {
254
+												max = 0;
255
+											}
256
+										}
257
+									}
258
+								}
259
+							}
260
+						}
261
+					}
262
+				}
263
+			}
264
+		}
265
+	}
266
+	return max;
267
+}
268
+
269
+int setLeftMin() {
270
+	int min = 0;
271
+		if(!columnCheck(0)) {
272
+			min = 32;
273
+			if(!columnCheck(1)) {
274
+				min = 64;
275
+				if(!columnCheck(2)) {
276
+					min = 96;
277
+					if(!columnCheck(3)) {
278
+						min = 128;
279
+						if(!columnCheck(4)) {
280
+							min = 160;
281
+							if(!columnCheck(5)) {
282
+								min = 192;
283
+								if(!columnCheck(6)) {
284
+									min = 224;
285
+									if(!columnCheck(7)) {
286
+										min = 256;
287
+										if(!columnCheck(8)) {
288
+											min = 288;
289
+											if(!columnCheck(9)) {
290
+												min = 320;
291
+												if(!columnCheck(10)) {
292
+													min = 352;
293
+												}
294
+											}
295
+										}
296
+									}
297
+								}
298
+							}
299
+						}
300
+					}
301
+				}
302
+			}
303
+		}
304
+		return min;
305
+}
306
+
307
+void moveAlien(unsigned int* framePointer) {
308
+	short dir = getDirection();
309
+	short alienx, alieny;
310
+	alienx = getAlienBlockPositionX();
311
+	alieny = getAlienBlockPositionY();
312
+	int right = setRightMax();
313
+	if((alienx+right) == 640 && dir == 0) {
314
+		setDirection(1);
315
+		blankAlien(framePointer);
316
+		alieny += 8;
317
+		setAlienBlockPosition(alienx, alieny);
318
+
319
+	}
320
+	int left = 0 - setLeftMin();
321
+	if(alienx == left && dir == 1) {
322
+		setDirection(0);
323
+		blankAlien(framePointer);
324
+		alieny += 8;
325
+		setAlienBlockPosition(alienx, alieny);
326
+
327
+	}
328
+	if(dir == 0) {
329
+		alienx += 4;
330
+		setAlienBlockPosition(alienx, alieny);
331
+	}
332
+	else {
333
+		alienx -= 4;
334
+		setAlienBlockPosition(alienx, alieny);
335
+	}
336
+}
337
+

+ 158
- 0
ecen427/alien.h View File

@@ -0,0 +1,158 @@
1
+#ifndef ALIEN_H_
2
+#define ALIEN_H_
3
+#define ALIEN_HEIGHT 16
4
+
5
+// Packs each horizontal line of the figures into a single 32 bit word.
6
+#define packWord32(b31,b30,b29,b28,b27,b26,b25,b24,b23,b22,b21,b20,b19,b18,b17,b16,b15,b14,b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,b2,b1,b0) \
7
+((b31 << 31) | (b30 << 30) | (b29 << 29) | (b28 << 28) | (b27 << 27) | (b26 << 26) | (b25 << 25) | (b24 << 24) |						  \
8
+ (b23 << 23) | (b22 << 22) | (b21 << 21) | (b20 << 20) | (b19 << 19) | (b18 << 18) | (b17 << 17) | (b16 << 16) |						  \
9
+ (b15 << 15) | (b14 << 14) | (b13 << 13) | (b12 << 12) | (b11 << 11) | (b10 << 10) | (b9  << 9 ) | (b8  << 8 ) |						  \
10
+ (b7  << 7 ) | (b6  << 6 ) | (b5  << 5 ) | (b4  << 4 ) | (b3  << 3 ) | (b2  << 2 ) | (b1  << 1 ) | (b0  << 0 ) )
11
+
12
+int topAlien1[ALIEN_HEIGHT] =
13
+{
14
+	packWord32(0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
15
+	packWord32(0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
16
+	packWord32(0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
17
+	packWord32(0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
18
+	packWord32(0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0),
19
+	packWord32(0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0),
20
+	packWord32(0,0,0,0,0,0,1,1,1,1,0,0,1,1,1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0),
21
+	packWord32(0,0,0,0,0,0,1,1,1,1,0,0,1,1,1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0),
22
+	packWord32(0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0),
23
+	packWord32(0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0),
24
+	packWord32(0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0),
25
+	packWord32(0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0),
26
+	packWord32(0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0),
27
+	packWord32(0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0),
28
+	packWord32(0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0),
29
+	packWord32(0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0),
30
+};
31
+
32
+int topAlien2[ALIEN_HEIGHT] =
33
+{
34
+	packWord32(0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
35
+	packWord32(0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
36
+	packWord32(0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
37
+	packWord32(0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
38
+	packWord32(0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0),
39
+	packWord32(0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0),
40
+	packWord32(0,0,0,0,0,0,1,1,1,1,0,0,1,1,1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0),
41
+	packWord32(0,0,0,0,0,0,1,1,1,1,0,0,1,1,1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0),
42
+	packWord32(0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0),
43
+	packWord32(0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0),
44
+	packWord32(0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
45
+	packWord32(0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
46
+	packWord32(0,0,0,0,0,0,0,0,1,1,0,0,1,1,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0),
47
+	packWord32(0,0,0,0,0,0,0,0,1,1,0,0,1,1,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0),
48
+	packWord32(0,0,0,0,0,0,1,1,0,0,1,1,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0),
49
+	packWord32(0,0,0,0,0,0,1,1,0,0,1,1,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0),
50
+};
51
+
52
+int middleAlien1[ALIEN_HEIGHT] =
53
+{
54
+	packWord32(0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0),
55
+	packWord32(0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0),
56
+	packWord32(0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0),
57
+	packWord32(0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0),
58
+	packWord32(0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0),
59
+	packWord32(0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0),
60
+	packWord32(0,0,0,0,0,0,1,1,1,1,1,0,0,1,1,1,1,1,1,0,0,1,1,1,1,1,0,0,0,0,0,0),
61
+	packWord32(0,0,0,0,0,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0,0,0,0,0),
62
+	packWord32(0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0),
63
+	packWord32(0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0),
64
+	packWord32(0,0,0,0,0,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,0,0,0,0,0),
65
+	packWord32(0,0,0,0,0,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,0,0,0,0,0),
66
+	packWord32(0,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0),
67
+	packWord32(0,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0),
68
+	packWord32(0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0),
69
+	packWord32(0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0),
70
+};
71
+
72
+int middleAlien2[ALIEN_HEIGHT] =
73
+{
74
+	packWord32(0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0),
75
+	packWord32(0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0),
76
+	packWord32(0,0,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,0),
77
+	packWord32(0,0,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,0),
78
+	packWord32(0,0,0,0,0,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,0,0,0,0,0),
79
+	packWord32(0,0,0,0,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,0,0,0,0,0),
80
+	packWord32(0,0,0,0,0,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0,0,0,0,0),
81
+	packWord32(0,0,0,0,0,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0,0,0,0,0),
82
+	packWord32(0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0),
83
+	packWord32(0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0),
84
+	packWord32(0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0),
85
+	packWord32(0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0),
86
+	packWord32(0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0),
87
+	packWord32(0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0),
88
+	packWord32(0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0),
89
+	packWord32(0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0),
90
+};
91
+
92
+int bottomAlien1[ALIEN_HEIGHT] =
93
+{
94
+	packWord32(0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0),
95
+	packWord32(0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0),
96
+	packWord32(0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0),
97
+	packWord32(0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0),
98
+	packWord32(0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0),
99
+	packWord32(0,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,0),
100
+	packWord32(0,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,0),
101
+	packWord32(0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0),
102
+	packWord32(0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0),
103
+	packWord32(0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0),
104
+	packWord32(0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0),
105
+	packWord32(0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0),
106
+	packWord32(0,0,0,0,0,0,1,1,1,1,1,0,0,0,1,1,1,1,0,0,0,1,1,1,1,1,0,0,0,0,0,0),
107
+	packWord32(0,0,0,0,0,0,1,1,1,1,1,0,0,0,1,1,1,1,0,0,0,1,1,1,1,1,0,0,0,0,0,0),
108
+	packWord32(0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0),
109
+	packWord32(0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0),
110
+};
111
+
112
+int bottomAlien2[ALIEN_HEIGHT] =
113
+{
114
+	packWord32(0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0),
115
+	packWord32(0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0),
116
+	packWord32(0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0),
117
+	packWord32(0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0),
118
+	packWord32(0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0),
119
+	packWord32(0,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,0),
120
+	packWord32(0,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,0),
121
+	packWord32(0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0),
122
+	packWord32(0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0),
123
+	packWord32(0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0),
124
+	packWord32(0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0),
125
+	packWord32(0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0),
126
+	packWord32(0,0,0,0,0,0,0,0,1,1,1,1,0,0,1,1,1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0),
127
+	packWord32(0,0,0,0,0,0,0,0,1,1,1,1,0,0,1,1,1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0),
128
+	packWord32(0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0),
129
+	packWord32(0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0),
130
+};
131
+
132
+int dying_alien[ALIEN_HEIGHT] =
133
+{
134
+	packWord32(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
135
+	packWord32(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
136
+	packWord32(0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0),
137
+	packWord32(0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0),
138
+	packWord32(0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0),
139
+	packWord32(0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0),
140
+	packWord32(0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0),
141
+	packWord32(0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0),
142
+	packWord32(0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,0,0,0,0,0,0),
143
+	packWord32(0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0),
144
+	packWord32(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0),
145
+	packWord32(0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0),
146
+	packWord32(0,0,0,0,0,0,0,0,1,1,1,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0),
147
+	packWord32(0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0),
148
+	packWord32(0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0),
149
+	packWord32(0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0),
150
+};
151
+
152
+void renderAlien(unsigned int*);
153
+void renderAlien1(unsigned int*);
154
+void renderAlien2(unsigned int*);
155
+void blankAlien(unsigned int*);
156
+void moveAlien(unsigned int*);
157
+
158
+#endif /* ALIEN_H_ */

+ 18
- 0
ecen427/alienDeathSound.c
File diff suppressed because it is too large
View File


+ 226
- 0
ecen427/bullet.c View File

@@ -0,0 +1,226 @@
1
+#include "bullet.h"
2
+
3
+void renderBullet(unsigned int* framePointer) {
4
+	if(getGuiseBullet() == 0) {
5
+		setGuiseBullet(1);
6
+		renderBullet1(framePointer);
7
+	}else {
8
+		setGuiseBullet(0);
9
+		renderBullet2(framePointer);
10
+	}
11
+}
12
+
13
+void renderBullet1(unsigned int* framePointer) {
14
+	if(getTankBulletState() == 1) {
15
+		short initial_x = getTankBulletPositionX();
16
+		short initial_y = getTankBulletPositionY();
17
+		int x, y;
18
+		for(x = 0; x < BLOCK_HEIGHT; x++) {
19
+			for(y = 0; y < BLOCK_WIDTH; y++){
20
+				if ((tankBullet[x%10] & (1<<(BLOCK_WIDTH-1-y)))) {
21
+					framePointer[(initial_y+x)*640 + initial_x+y] = 0x00FFFFFE;
22
+				} else {
23
+					framePointer[(initial_y+x)*640 + initial_x+y] = 0x00000000;
24
+				}
25
+			}
26
+		}
27
+	}
28
+	if(getAlien1BulletState() == 1) {
29
+		short initial_x = getAlien1BulletPositionX();
30
+		short initial_y = getAlien1BulletPositionY();
31
+		int x, y;
32
+		for(x = 0; x < BLOCK_HEIGHT; x++) {
33
+			for(y = 0; y < BLOCK_WIDTH; y++){
34
+				if ((alienBullet1_1[x%10] & (1<<(BLOCK_WIDTH-1-y)))) {
35
+					framePointer[(initial_y+x)*640 + initial_x+y] = 0x00FFFFFE;
36
+				} else {
37
+					framePointer[(initial_y+x)*640 + initial_x+y] = 0x00000000;
38
+				}
39
+			}
40
+		}
41
+	}
42
+	if(getAlien2BulletState() == 1) {
43
+		short initial_x = getAlien2BulletPositionX();
44
+		short initial_y = getAlien2BulletPositionY();
45
+		int x, y;
46
+		for(x = 0; x < BLOCK_HEIGHT; x++) {
47
+			for(y = 0; y < BLOCK_WIDTH; y++){
48
+				if ((alienBullet2_1[x%10] & (1<<(BLOCK_WIDTH-1-y)))) {
49
+					framePointer[(initial_y+x)*640 + initial_x+y] = 0x00FFFFFE;
50
+				} else {
51
+					framePointer[(initial_y+x)*640 + initial_x+y] = 0x00000000;
52
+				}
53
+			}
54
+		}
55
+	}
56
+	if(getAlien3BulletState() == 1) {
57
+		short initial_x = getAlien3BulletPositionX();
58
+		short initial_y = getAlien3BulletPositionY();
59
+		int x, y;
60
+		for(x = 0; x < BLOCK_HEIGHT; x++) {
61
+			for(y = 0; y < BLOCK_WIDTH; y++){
62
+				if ((alienBullet3_1[x%10] & (1<<(BLOCK_WIDTH-1-y)))) {
63
+					framePointer[(initial_y+x)*640 + initial_x+y] = 0x00FFFFFE;
64
+				} else {
65
+					framePointer[(initial_y+x)*640 + initial_x+y] = 0x00000000;
66
+				}
67
+			}
68
+		}
69
+	}
70
+	if(getAlien4BulletState() == 1) {
71
+		short initial_x = getAlien4BulletPositionX();
72
+		short initial_y = getAlien4BulletPositionY();
73
+		int x, y;
74
+		for(x = 0; x < BLOCK_HEIGHT; x++) {
75
+			for(y = 0; y < BLOCK_WIDTH; y++){
76
+				if ((alienBullet1_1[x%10] & (1<<(BLOCK_WIDTH-1-y)))) {
77
+					framePointer[(initial_y+x)*640 + initial_x+y] = 0x00FFFFFE;
78
+				} else {
79
+					framePointer[(initial_y+x)*640 + initial_x+y] = 0x00000000;
80
+				}
81
+			}
82
+		}
83
+	}
84
+}
85
+
86
+void renderBullet2(unsigned int* framePointer) {
87
+	if(getTankBulletState() == 1) {
88
+		short initial_x = getTankBulletPositionX();
89
+		short initial_y = getTankBulletPositionY();
90
+		int x, y;
91
+		for(x = 0; x < BLOCK_HEIGHT; x++) {
92
+			for(y = 0; y < BLOCK_WIDTH; y++){
93
+				if ((tankBullet[x%10] & (1<<(BLOCK_WIDTH-1-y)))) {
94
+					framePointer[(initial_y+x)*640 + initial_x+y] = 0x00FFFFFE;
95
+				} else {
96
+					framePointer[(initial_y+x)*640 + initial_x+y] = 0x00000000;
97
+				}
98
+			}
99
+		}
100
+	}
101
+	if(getAlien1BulletState() == 1) {
102
+		short initial_x = getAlien1BulletPositionX();
103
+		short initial_y = getAlien1BulletPositionY();
104
+		int x, y;
105
+		for(x = 0; x < BLOCK_HEIGHT; x++) {
106
+			for(y = 0; y < BLOCK_WIDTH; y++){
107
+				if ((alienBullet1_2[x%10] & (1<<(BLOCK_WIDTH-1-y)))) {
108
+					framePointer[(initial_y+x)*640 + initial_x+y] = 0x00FFFFFE;
109
+				} else {
110
+					framePointer[(initial_y+x)*640 + initial_x+y] = 0x00000000;
111
+				}
112
+			}
113
+		}
114
+	}
115
+	if(getAlien2BulletState() == 1) {
116
+		short initial_x = getAlien2BulletPositionX();
117
+		short initial_y = getAlien2BulletPositionY();
118
+		int x, y;
119
+		for(x = 0; x < BLOCK_HEIGHT; x++) {
120
+			for(y = 0; y < BLOCK_WIDTH; y++){
121
+				if ((alienBullet2_2[x%10] & (1<<(BLOCK_WIDTH-1-y)))) {
122
+					framePointer[(initial_y+x)*640 + initial_x+y] = 0x00FFFFFE;
123
+				} else {
124
+					framePointer[(initial_y+x)*640 + initial_x+y] = 0x00000000;
125
+				}
126
+			}
127
+		}
128
+	}
129
+	if(getAlien3BulletState() == 1) {
130
+		short initial_x = getAlien3BulletPositionX();
131
+		short initial_y = getAlien3BulletPositionY();
132
+		int x, y;
133
+		for(x = 0; x < BLOCK_HEIGHT; x++) {
134
+			for(y = 0; y < BLOCK_WIDTH; y++){
135
+				if ((alienBullet3_2[x%10] & (1<<(BLOCK_WIDTH-1-y)))) {
136
+					framePointer[(initial_y+x)*640 + initial_x+y] = 0x00FFFFFE;
137
+				} else {
138
+					framePointer[(initial_y+x)*640 + initial_x+y] = 0x00000000;
139
+				}
140
+			}
141
+		}
142
+	}
143
+	if(getAlien4BulletState() == 1) {
144
+		short initial_x = getAlien4BulletPositionX();
145
+		short initial_y = getAlien4BulletPositionY();
146
+		int x, y;
147
+		for(x = 0; x < BLOCK_HEIGHT; x++) {
148
+			for(y = 0; y < BLOCK_WIDTH; y++){
149
+				if ((alienBullet1_2[x%10] & (1<<(BLOCK_WIDTH-1-y)))) {
150
+					framePointer[(initial_y+x)*640 + initial_x+y] = 0x00FFFFFE;
151
+				} else {
152
+					framePointer[(initial_y+x)*640 + initial_x+y] = 0x00000000;
153
+				}
154
+			}
155
+		}
156
+	}
157
+}
158
+
159
+void blankTankBullet(unsigned int* framePointer){
160
+	short tankx, tanky;
161
+    tankx = getTankBulletPositionX();
162
+    tanky = getTankBulletPositionY();
163
+	short row=0, col=0;
164
+	for(row = 0; row < BLOCK_HEIGHT; row++){
165
+		for(col = 0; col < BLOCK_WIDTH; col++){
166
+			framePointer[(tanky+row)*640 + tankx+col] = 0x00000000;
167
+		}
168
+	}
169
+}
170
+
171
+void blankAlienBullet(unsigned int* framePointer, short alienx, short alieny) {
172
+	short row=0, col=0;
173
+	for(row = 0; row < BLOCK_HEIGHT; row++){
174
+		for(col = 0; col < BLOCK_WIDTH; col++){
175
+			framePointer[(alieny+row)*640 + alienx+col] = 0x00000000;
176
+		}
177
+	}
178
+}
179
+
180
+void moveBullets(unsigned int* framePointer) {
181
+	if(getTankBulletState() == 1) {
182
+		if(getTankBulletPositionY() == 30) {
183
+			blankTankBullet(framePointer);
184
+			setTankBulletState(0);
185
+		}
186
+		else {
187
+			setTankBulletPositionY(getTankBulletPositionY()-1);
188
+		}
189
+	}
190
+	if(getAlien1BulletState() == 1) {
191
+		if(getAlien1BulletPositionY() == 450) {
192
+			blankAlienBullet(framePointer, getAlien1BulletPositionX(), getAlien1BulletPositionY());
193
+			setAlien1BulletState(0);
194
+		}
195
+		else {
196
+			setAlien1BulletPositionY(getAlien1BulletPositionY()+1);
197
+		}
198
+	}
199
+	if(getAlien2BulletState() == 1) {
200
+		if(getAlien2BulletPositionY() == 450) {
201
+			blankAlienBullet(framePointer, getAlien2BulletPositionX(), getAlien2BulletPositionY());
202
+			setAlien2BulletState(0);
203
+		}
204
+		else {
205
+			setAlien2BulletPositionY(getAlien2BulletPositionY()+1);
206
+		}
207
+	}
208
+	if(getAlien3BulletState() == 1) {
209
+		if(getAlien3BulletPositionY() == 450) {
210
+			blankAlienBullet(framePointer, getAlien3BulletPositionX(), getAlien3BulletPositionY());
211
+			setAlien3BulletState(0);
212
+		}
213
+		else {
214
+			setAlien3BulletPositionY(getAlien3BulletPositionY()+1);
215
+		}
216
+	}
217
+	if(getAlien4BulletState() == 1) {
218
+		if(getAlien4BulletPositionY() == 450) {
219
+			blankAlienBullet(framePointer, getAlien4BulletPositionX(), getAlien4BulletPositionY());
220
+			setAlien4BulletState(0);
221
+		}
222
+		else {
223
+			setAlien4BulletPositionY(getAlien4BulletPositionY()+1);
224
+		}
225
+	}
226
+}

+ 109
- 0
ecen427/bullet.h View File

@@ -0,0 +1,109 @@
1
+#ifndef BULLET_H_
2
+#define BULLET_H_
3
+
4
+#define BLOCK_HEIGHT 10
5
+#define BLOCK_WIDTH 6
6
+#define packWord24(b5,b4,b3,b2,b1,b0) \
7
+((b5  << 5 ) | (b4  << 4 ) | (b3  << 3 ) | (b2  << 2 ) | (b1  << 1 ) | (b0  << 0 ))
8
+
9
+int alienBullet1_1[BLOCK_HEIGHT] =
10
+{
11
+		packWord24(0,0,0,0,0,0),
12
+		packWord24(0,0,1,1,0,0),
13
+		packWord24(0,0,1,1,0,0),
14
+		packWord24(0,0,1,1,0,0),
15
+		packWord24(0,0,1,1,0,0),
16
+		packWord24(0,0,1,1,0,0),
17
+		packWord24(1,1,1,1,1,1),
18
+		packWord24(1,1,1,1,1,1),
19
+		packWord24(0,0,1,1,0,0),
20
+		packWord24(0,0,0,0,0,0),
21
+};
22
+
23
+int alienBullet1_2[BLOCK_HEIGHT] =
24
+{
25
+		packWord24(0,0,0,0,0,0),
26
+		packWord24(0,0,1,1,0,0),
27
+		packWord24(1,1,1,1,1,1),
28
+		packWord24(1,1,1,1,1,1),
29
+		packWord24(0,0,1,1,0,0),
30
+		packWord24(0,0,1,1,0,0),
31
+		packWord24(0,0,1,1,0,0),
32
+		packWord24(0,0,1,1,0,0),
33
+		packWord24(0,0,1,1,0,0),
34
+		packWord24(0,0,0,0,0,0),
35
+};
36
+
37
+int alienBullet2_1[BLOCK_HEIGHT] =
38
+{
39
+		packWord24(0,0,0,0,0,0),
40
+		packWord24(0,0,0,0,1,1),
41
+		packWord24(0,0,0,1,1,0),
42
+		packWord24(0,0,1,1,0,0),
43
+		packWord24(0,1,1,0,0,0),
44
+		packWord24(0,1,1,0,0,0),
45
+		packWord24(0,0,1,1,0,0),
46
+		packWord24(0,0,0,1,1,0),
47
+		packWord24(0,0,0,0,1,1),
48
+		packWord24(0,0,0,0,0,0),
49
+};
50
+
51
+int alienBullet2_2[BLOCK_HEIGHT] =
52
+{
53
+		packWord24(0,0,0,0,0,0),
54
+		packWord24(0,0,1,1,0,0),
55
+		packWord24(0,0,0,1,1,0),
56
+		packWord24(0,0,1,1,0,0),
57
+		packWord24(0,0,0,1,1,0),
58
+		packWord24(0,0,0,0,1,1),
59
+		packWord24(0,0,0,1,1,0),
60
+		packWord24(0,0,1,1,0,0),
61
+		packWord24(0,1,1,0,0,0),
62
+		packWord24(0,0,0,0,0,0),
63
+};
64
+
65
+int alienBullet3_1[BLOCK_HEIGHT] =
66
+{
67
+		packWord24(0,0,0,0,0,0),
68
+		packWord24(1,1,0,0,0,0),
69
+		packWord24(0,1,1,0,0,0),
70
+		packWord24(0,0,1,1,0,0),
71
+		packWord24(0,0,0,1,1,0),
72
+		packWord24(0,0,0,1,1,0),
73
+		packWord24(0,0,1,1,0,0),
74
+		packWord24(0,1,1,0,0,0),
75
+		packWord24(1,1,0,0,0,0),
76
+		packWord24(0,0,0,0,0,0),
77
+};
78
+
79
+int alienBullet3_2[BLOCK_HEIGHT] =
80
+{
81
+		packWord24(0,0,0,0,0,0),
82
+		packWord24(1,1,0,0,0,0),
83
+		packWord24(0,1,1,0,0,0),
84
+		packWord24(0,0,1,1,0,0),
85
+		packWord24(0,1,1,0,0,0),
86
+		packWord24(1,1,0,0,0,0),
87
+		packWord24(0,1,1,0,0,0),
88
+		packWord24(0,0,1,1,0,0),
89
+		packWord24(0,0,0,1,1,0),
90
+		packWord24(0,0,0,0,0,0),
91
+};
92
+
93
+int tankBullet[BLOCK_HEIGHT] =
94
+{
95
+		packWord24(0,0,0,0,0,0),
96
+		packWord24(0,0,1,1,0,0),
97
+		packWord24(0,0,1,1,0,0),
98
+		packWord24(0,0,1,1,0,0),
99
+		packWord24(0,0,1,1,0,0),
100
+		packWord24(0,0,1,1,0,0),
101
+		packWord24(0,0,1,1,0,0),
102
+		packWord24(0,0,1,1,0,0),
103
+		packWord24(0,0,1,1,0,0),
104
+		packWord24(0,0,0,0,0,0),
105
+};
106
+
107
+void renderBullet(unsigned int*);
108
+void moveBullets(unsigned int*);
109
+#endif /* BULLET_H_ */

+ 638
- 0
ecen427/bunker.c View File

@@ -0,0 +1,638 @@
1
+#include "bunker.h"
2
+#include "stdlib.h"
3
+#include "xintc_l.h"        // Provides handy macros for the interrupt controller.
4
+
5
+int x_y[4] = {BUNKER1_X, BUNKER2_X, BUNKER3_X, BUNKER4_X};
6
+int initial_x = 70;
7
+int initial_y = 300;
8
+int tank_y_position = 420;
9
+
10
+void renderBunker(unsigned int* framePointer) {		// draw for the first time
11
+	short x=0, y=0;
12
+
13
+	int i,j;
14
+	for(j = 0; j < 4; j++) {
15
+		initial_x = x_y[j];
16
+		for(i=0; i<10; i++){
17
+			switch(i){
18
+			case 0:
19
+				for(x = 0; x < BLOCK_HEIGHT; x++) {
20
+					for(y = 0; y < BLOCK_WIDTH; y++){
21
+						if ((block_left0[x%16] & (1<<(BLOCK_WIDTH-1-y)))) {
22
+							framePointer[(initial_y+x)*640 + initial_x+y] = 0x0000FF00;
23
+						} else {
24
+							framePointer[(initial_y+x)*640 + initial_x+y] = 0x00000000;
25
+						}
26
+					}
27
+				}
28
+				break;
29
+			case 1:
30
+				for(x = 0; x < BLOCK_HEIGHT; x++) {
31
+					for(y = 0; y < BLOCK_WIDTH; y++){
32
+						if ((block_normal0[x%16] & (1<<(BLOCK_WIDTH-1-y)))) {
33
+							framePointer[(initial_y+x)*640 + initial_x+y+BLOCK_WIDTH] = 0x0000FF00;
34
+						} else {
35
+							framePointer[(initial_y+x)*640 + initial_x+y+BLOCK_WIDTH] = 0x00000000;
36
+						}
37
+					}
38
+				}
39
+				break;
40
+			case 2:
41
+				for(x = 0; x < BLOCK_HEIGHT; x++) {
42
+					for(y = 0; y < BLOCK_WIDTH; y++){
43
+						if ((block_normal0[x%16] & (1<<(BLOCK_WIDTH-1-y)))) {
44
+							framePointer[(initial_y+x)*640 + initial_x+y+BLOCK_WIDTH*2] = 0x0000FF00;
45
+						} else {
46
+							framePointer[(initial_y+x)*640 + initial_x+y+BLOCK_WIDTH*2] = 0x00000000;
47
+						}
48
+					}
49
+				}
50
+				break;
51
+
52
+			case 3:
53
+				for(x = 0; x < BLOCK_HEIGHT; x++) {
54
+					for(y = 0; y < BLOCK_WIDTH; y++){
55
+						if ((block_right0[x%16] & (1<<(BLOCK_WIDTH-1-y)))) {
56
+							framePointer[(initial_y+x)*640 + initial_x+y+BLOCK_WIDTH*3] = 0x0000FF00;
57
+						} else {
58
+							framePointer[(initial_y+x)*640 + initial_x+y+BLOCK_WIDTH*3] = 0x00000000;
59
+						}
60
+					}
61
+				}
62
+
63
+				break;
64
+			case 4:
65
+				for(x = 0; x < BLOCK_HEIGHT; x++) {
66
+					for(y = 0; y < BLOCK_WIDTH; y++){
67
+						if ((block_normal0[x%16] & (1<<(BLOCK_WIDTH-1-y)))) {
68
+							framePointer[(initial_y+x+BLOCK_HEIGHT)*640 + initial_x+y] = 0x0000FF00;
69
+						} else {
70
+							framePointer[(initial_y+x+BLOCK_HEIGHT)*640 + initial_x+y] = 0x00000000;
71
+						}
72
+					}
73
+				}
74
+				break;
75
+			case 5:
76
+				for(x = 0; x < BLOCK_HEIGHT; x++) {
77
+					for(y = 0; y < BLOCK_WIDTH; y++){
78
+						if ((block_center_left0[x%16] & (1<<(BLOCK_WIDTH-1-y)))) {
79
+							framePointer[(initial_y+x+BLOCK_HEIGHT)*640 + initial_x+y+BLOCK_WIDTH] = 0x0000FF00;
80
+						} else {
81
+							framePointer[(initial_y+x+BLOCK_HEIGHT)*640 + initial_x+y+BLOCK_WIDTH] = 0x00000000;
82
+						}
83
+					}
84
+				}
85
+				break;
86
+			case 6:
87
+				for(x = 0; x < BLOCK_HEIGHT; x++) {
88
+					for(y = 0; y < BLOCK_WIDTH; y++){
89
+						if ((block_center_right0[x%16] & (1<<(BLOCK_WIDTH-1-y)))) {
90
+							framePointer[(initial_y+x+BLOCK_HEIGHT)*640 + initial_x+y+BLOCK_WIDTH*2] = 0x0000FF00;
91
+						} else {
92
+							framePointer[(initial_y+x+BLOCK_HEIGHT)*640 + initial_x+y+BLOCK_WIDTH*2] = 0x00000000;
93
+						}
94
+					}
95
+				}
96
+				break;
97
+			case 7:
98
+				for(x = 0; x < BLOCK_HEIGHT; x++) {
99
+					for(y = 0; y < BLOCK_WIDTH; y++){
100
+						if ((block_normal0[x%16] & (1<<(BLOCK_WIDTH-1-y)))) {
101
+							framePointer[(initial_y+x+BLOCK_HEIGHT)*640 + initial_x+y+BLOCK_WIDTH*3] = 0x0000FF00;
102
+						} else {
103
+							framePointer[(initial_y+x+BLOCK_HEIGHT)*640 + initial_x+y+BLOCK_WIDTH*3] = 0x00000000;
104
+						}
105
+					}
106
+				}
107
+				break;
108
+
109
+			case 8:
110
+				for(x = 0; x < BLOCK_HEIGHT; x++) {
111
+					for(y = 0; y < BLOCK_WIDTH; y++){
112
+						if ((block_normal0[x%16] & (1<<(BLOCK_WIDTH-1-y)))) {
113
+							framePointer[(initial_y+x+BLOCK_HEIGHT*2)*640 + initial_x+y] = 0x0000FF00;
114
+						} else {
115
+							framePointer[(initial_y+x+BLOCK_HEIGHT*2)*640 + initial_x+y] = 0x00000000;
116
+						}
117
+					}
118
+				}
119
+				break;
120
+			case 9:
121
+				for(x = 0; x < BLOCK_HEIGHT; x++) {
122
+					for(y = 0; y < BLOCK_WIDTH; y++){
123
+						if ((block_normal0[x%16] & (1<<(BLOCK_WIDTH-1-y)))) {
124
+							framePointer[(initial_y+x+BLOCK_HEIGHT*2)*640 + initial_x+y+BLOCK_WIDTH*3] = 0x0000FF00;
125
+						} else {
126
+							framePointer[(initial_y+x+BLOCK_HEIGHT*2)*640 + initial_x+y+BLOCK_WIDTH*3] = 0x00000000;
127
+						}
128
+					}
129
+				}
130
+				break;
131
+			default :
132
+
133
+				break;
134
+			}
135
+		}
136
+	}
137
+}
138
+
139
+void erodeBunker(unsigned int* framePointer, int which_bunker, int which_block){
140
+	//	int which_block = rand()%10;
141
+	short* bunker;
142
+	int i, j;
143
+	int block_row, block_col;
144
+	switch(which_bunker){ 		// select a bunker that I want to erode
145
+	case 0:
146
+		bunker = getBunker1();
147
+		break;
148
+	case 1:
149
+		bunker = getBunker2();
150
+		break;
151
+	case 2:
152
+		bunker = getBunker3();
153
+		break;
154
+	case 3:
155
+		bunker = getBunker4();
156
+		break;
157
+	default :
158
+		break;
159
+	}
160
+
161
+	switch(which_block){ 		// 'block_row, block_col' are used to calculate to find out the position of framePointer
162
+	case 0:
163
+		block_row = 0;
164
+		block_col = 0;
165
+		blankBlock(framePointer, which_bunker, which_block, block_row, block_col);
166
+		updateBlock(framePointer, which_bunker, which_block, block_row, block_col, bunker);
167
+		break;
168
+	case 1:
169
+		block_row = 0;
170
+		block_col = 1;
171
+		blankBlock(framePointer, which_bunker, which_block, block_row, block_col);
172
+		updateBlock(framePointer, which_bunker, which_block, block_row, block_col, bunker);
173
+
174
+		break;
175
+	case 2:
176
+		block_row = 0;
177
+		block_col = 2;
178
+		blankBlock(framePointer, which_bunker, which_block, block_row, block_col);
179
+		updateBlock(framePointer, which_bunker, which_block, block_row, block_col, bunker);
180
+
181
+		break;
182
+	case 3:
183
+		block_row = 0;
184
+		block_col = 3;
185
+		blankBlock(framePointer, which_bunker, which_block, block_row, block_col);
186
+		updateBlock(framePointer, which_bunker, which_block, block_row, block_col, bunker);
187
+
188
+		break;
189
+	case 4:
190
+		block_row = 1;
191
+		block_col = 0;
192
+		blankBlock(framePointer, which_bunker, which_block, block_row, block_col);
193
+		updateBlock(framePointer, which_bunker, which_block, block_row, block_col, bunker);
194
+
195
+		break;
196
+	case 5:
197
+		block_row = 1;
198
+		block_col = 1;
199
+		blankBlock(framePointer, which_bunker, which_block, block_row, block_col);
200
+		updateBlock(framePointer, which_bunker, which_block, block_row, block_col, bunker);
201
+
202
+		break;
203
+	case 6:
204
+		block_row = 1;
205
+		block_col = 2;
206
+		blankBlock(framePointer, which_bunker, which_block, block_row, block_col);
207
+		updateBlock(framePointer, which_bunker, which_block, block_row, block_col, bunker);
208
+
209
+		break;
210
+	case 7:
211
+		block_row = 1;
212
+		block_col = 3;
213
+		blankBlock(framePointer, which_bunker, which_block, block_row, block_col);
214
+		updateBlock(framePointer, which_bunker, which_block, block_row, block_col, bunker);
215
+
216
+		break;
217
+	case 8:
218
+		block_row = 2;
219
+		block_col = 0;
220
+		blankBlock(framePointer, which_bunker, which_block, block_row, block_col);
221
+		updateBlock(framePointer, which_bunker, which_block, block_row, block_col, bunker);
222
+
223
+		break;
224
+	case 9:
225
+		block_row = 2;
226
+		block_col = 3;
227
+		blankBlock(framePointer, which_bunker, which_block, block_row, block_col);
228
+		updateBlock(framePointer, which_bunker, which_block, block_row, block_col, bunker);
229
+
230
+		break;
231
+
232
+	default :
233
+
234
+		break;
235
+	}
236
+
237
+}
238
+// This function runs first to make a block empty, and then draw an eroded block by 'updateBlock()' function
239
+void blankBlock(unsigned int* framePointer, int which_bunker, int which_block, int block_row, int block_col){
240
+	int i, j;
241
+	initial_x = x_y[which_bunker];
242
+	for(i = 0; i < BLOCK_HEIGHT; i++){
243
+		for(j = 0; j < BLOCK_WIDTH; j++){
244
+			framePointer[(initial_y+i+BLOCK_HEIGHT*block_row)*640 + initial_x+j+BLOCK_WIDTH*block_col] = 0x00000000;
245
+		}
246
+	}
247
+}
248
+
249
+void updateBlock(unsigned int* framePointer, int which_bunker, int which_block, int block_row, int block_col, short* bunker){
250
+	int i, j;
251
+	initial_x = x_y[which_bunker];
252
+
253
+	int* which_state;
254
+
255
+	if(bunker[which_block]==0){ 		// depending on the block selected and bunker status, 'which_state' points to a pre-defined eroded block
256
+		bunker[which_block] = 1;
257
+		if(which_block == 0){
258
+			which_state = block_left1;
259
+		}
260
+		else if(which_block == 1 || which_block == 2 || which_block == 4 || which_block == 7 || which_block == 8 || which_block == 9){
261
+			which_state = block_normal1;
262
+		}
263
+		else if(which_block == 3){
264
+			which_state = block_right1;
265
+		}
266
+		else if(which_block == 5){
267
+			which_state = block_center_left1;
268
+		}
269
+		else if(which_block == 6){
270
+			which_state = block_center_right1;
271
+		}
272
+	}
273
+	else if(bunker[which_block]==1){
274
+		bunker[which_block] = 2;
275
+		if(which_block == 0){
276
+			which_state = block_left2;
277
+		}
278
+		else if(which_block == 1 || which_block == 2 || which_block == 4 || which_block == 7 || which_block == 8 || which_block == 9){
279
+			which_state = block_normal2;
280
+		}
281
+		else if(which_block == 3){
282
+			which_state = block_right2;
283
+		}
284
+		else if(which_block == 5){
285
+			which_state = block_center_left2;
286
+		}
287
+		else if(which_block == 6){
288
+			which_state = block_center_right2;
289
+		}
290
+	}
291
+	else if(bunker[which_block]==2){
292
+		bunker[which_block] = 3;
293
+		if(which_block == 0){
294
+			which_state = block_left3;
295
+		}
296
+		else if(which_block == 1 || which_block == 2 || which_block == 4 || which_block == 7 || which_block == 8 || which_block == 9){
297
+			which_state = block_normal3;
298
+		}
299
+		else if(which_block == 3){
300
+			which_state = block_right3;
301
+		}
302
+		else if(which_block == 5){
303
+			which_state = block_center_left3;
304
+		}
305
+		else if(which_block == 6){
306
+			which_state = block_center_right3;
307
+		}
308
+	}
309
+	else{
310
+		bunker[which_block] = 4;
311
+		which_state = empty;
312
+	}
313
+
314
+	for(i = 0; i < BLOCK_HEIGHT; i++){
315
+		for(j = 0; j < BLOCK_WIDTH; j++){
316
+			if ((which_state[i%16] & (1<<(BLOCK_WIDTH-1-j)))) {
317
+				framePointer[(initial_y+i+BLOCK_HEIGHT*block_row)*640 + initial_x+j+BLOCK_WIDTH*block_col] = 0x0000FF00;
318
+			} else {
319
+				framePointer[(initial_y+i+BLOCK_HEIGHT*block_row)*640 + initial_x+j+BLOCK_WIDTH*block_col] = 0x00000000;
320
+			}
321
+		}
322
+	}
323
+}
324
+void selectBlock(unsigned int* framePointer, int bullet){
325
+	int bullet_x;
326
+	int bullet_y;
327
+	short hit = 0;
328
+	short* bunker;
329
+	int counter=0;
330
+	short dying = 0;
331
+	int gameover = 0;
332
+
333
+	switch(bullet){
334
+	case 1:
335
+		bullet_x = getAlien1BulletPositionX()+3;
336
+		bullet_y = getAlien1BulletPositionY()+10;
337
+		break;
338
+	case 2:
339
+		bullet_x = getAlien2BulletPositionX()+3;
340
+		bullet_y = getAlien2BulletPositionY()+10;
341
+		break;
342
+	case 3:
343
+		bullet_x = getAlien3BulletPositionX()+3;
344
+		bullet_y = getAlien3BulletPositionY()+10;
345
+		break;
346
+	case 4:
347
+		bullet_x = getAlien4BulletPositionX()+3;
348
+		bullet_y = getAlien4BulletPositionY()+10;
349
+		break;
350
+	case 5:
351
+		bullet_x = getTankBulletPositionX()+3;
352
+		bullet_y = getTankBulletPositionY();
353
+	default:
354
+		break;
355
+	}
356
+
357
+	if(bullet_x >= BUNKER1_X-3 && bullet_x < BUNKER1_X+64+3){
358
+		bunker = getBunker1();
359
+		if(bullet_y > initial_y && bullet_y < initial_y+16){
360
+			if(bullet_x >= BUNKER1_X-3 && bullet_x < BUNKER1_X+16 && bunker[0] != 4){
361
+				erodeBunker(framePointer, 0, 0);
362
+				hit = 1;
363
+			}
364
+			if(bullet_x >= BUNKER1_X+16 && bullet_x < BUNKER1_X+32 && bunker[1] != 4){
365
+				erodeBunker(framePointer, 0, 1);
366
+				hit = 1;
367
+			}
368
+			if(bullet_x >= BUNKER1_X+32 && bullet_x < BUNKER1_X+48 && bunker[2] != 4){
369
+				erodeBunker(framePointer, 0, 2);
370
+				hit = 1;
371
+			}
372
+			if(bullet_x >= BUNKER1_X+48 && bullet_x < BUNKER1_X+64+3 && bunker[3] != 4){
373
+				erodeBunker(framePointer, 0, 3);
374
+				hit = 1;
375
+			}
376
+		}
377
+		if(bullet_y>initial_y+16 && bullet_y<initial_y+32){
378
+			if(bullet_x >= BUNKER1_X-3 && bullet_x < BUNKER1_X+16 && bunker[4] != 4){
379
+				erodeBunker(framePointer, 0, 4);
380
+				hit = 1;
381
+			}
382
+			if(bullet_x >= BUNKER1_X+16 && bullet_x < BUNKER1_X+32 && bunker[5] != 4){
383
+				erodeBunker(framePointer, 0, 5);
384
+				hit = 1;
385
+			}
386
+			if(bullet_x >= BUNKER1_X+32 && bullet_x < BUNKER1_X+48 && bunker[6] != 4){
387
+				erodeBunker(framePointer, 0, 6);
388
+				hit = 1;
389
+			}
390
+			if(bullet_x >= BUNKER1_X+48 && bullet_x < BUNKER1_X+64+3 && bunker[7] != 4){
391
+				erodeBunker(framePointer, 0, 7);
392
+				hit = 1;
393
+			}
394
+		}
395
+		if(bullet_y>initial_y+32 && bullet_y<initial_y+48){
396
+			if(bullet_x >= BUNKER1_X-3 && bullet_x<BUNKER1_X+16 && bunker[8] != 4){
397
+				erodeBunker(framePointer, 0, 8);
398
+				hit = 1;
399
+			}
400
+			if(bullet_x >= BUNKER1_X+48 && bullet_x<BUNKER1_X+64+3 && bunker[9] != 4){
401
+				erodeBunker(framePointer, 0, 9);
402
+				hit = 1;
403
+			}
404
+		}
405
+
406
+	}
407
+
408
+	if(bullet_x > BUNKER2_X-3 && bullet_x < BUNKER2_X+64+3){
409
+		bunker = getBunker2();
410
+		if(bullet_y>initial_y && bullet_y<initial_y+16){
411
+			if(bullet_x >= BUNKER2_X-3 && bullet_x<BUNKER2_X+16 && bunker[0] != 4){
412
+				erodeBunker(framePointer, 1, 0);
413
+				hit = 1;
414
+			}
415
+			if(bullet_x >= BUNKER2_X+16 && bullet_x<BUNKER2_X+32 && bunker[1] != 4){
416
+				erodeBunker(framePointer, 1, 1);
417
+				hit = 1;
418
+			}
419
+			if(bullet_x >= BUNKER2_X+32 && bullet_x<BUNKER2_X+48 && bunker[2] != 4){
420
+				erodeBunker(framePointer, 1, 2);
421
+				hit = 1;
422
+			}
423
+			if(bullet_x >= BUNKER2_X+48 && bullet_x<BUNKER2_X+64+3 && bunker[3] != 4){
424
+				erodeBunker(framePointer, 1, 3);
425
+				hit = 1;
426
+			}
427
+		}
428
+		if(bullet_y>initial_y+16 && bullet_y<initial_y+32){
429
+			if(bullet_x >= BUNKER2_X-3 && bullet_x<BUNKER2_X+16 && bunker[4] != 4){
430
+				erodeBunker(framePointer, 1, 4);
431
+				hit = 1;
432
+			}
433
+			if(bullet_x >= BUNKER2_X+16 && bullet_x<BUNKER2_X+32 && bunker[5] != 4){
434
+				erodeBunker(framePointer, 1, 5);
435
+				hit = 1;
436
+			}
437
+			if(bullet_x >= BUNKER2_X+32 && bullet_x<BUNKER2_X+48 && bunker[6] != 4){
438
+				erodeBunker(framePointer, 1, 6);
439
+				hit = 1;
440
+			}
441
+			if(bullet_x >= BUNKER2_X+48 && bullet_x<BUNKER2_X+64+3 && bunker[7] != 4){
442
+				erodeBunker(framePointer, 1, 7);
443
+				hit = 1;
444
+			}
445
+		}
446
+		if(bullet_y>initial_y+32 && bullet_y<initial_y+48){
447
+			if(bullet_x >= BUNKER2_X-3 && bullet_x<BUNKER2_X+16 && bunker[8] != 4){
448
+				erodeBunker(framePointer, 1, 8);
449
+				hit = 1;
450
+			}
451
+			if(bullet_x >= BUNKER2_X+48 && bullet_x<BUNKER2_X+64+3 && bunker[9] != 4){
452
+				erodeBunker(framePointer, 1, 9);
453
+				hit = 1;
454
+			}
455
+		}
456
+
457
+	}
458
+
459
+	if(bullet_x > BUNKER3_X-3 && bullet_x < BUNKER3_X+64+3){
460
+		bunker = getBunker3();
461
+		if(bullet_y>initial_y && bullet_y<initial_y+16){
462
+			if(bullet_x >= BUNKER3_X-3 && bullet_x<BUNKER3_X+16 && bunker[0] != 4){
463
+				erodeBunker(framePointer, 2, 0);
464
+				hit = 1;
465
+			}
466
+			if(bullet_x >= BUNKER3_X+16 && bullet_x<BUNKER3_X+32 && bunker[1] != 4){
467
+				erodeBunker(framePointer, 2, 1);
468
+				hit = 1;
469
+			}
470
+			if(bullet_x >= BUNKER3_X+32 && bullet_x<BUNKER3_X+48 && bunker[2] != 4){
471
+				erodeBunker(framePointer, 2, 2);
472
+				hit = 1;
473
+			}
474
+			if(bullet_x >= BUNKER3_X+48 && bullet_x<BUNKER3_X+64+3 && bunker[3] != 4){
475
+				erodeBunker(framePointer, 2, 3);
476
+				hit = 1;
477
+			}
478
+		}
479
+		if(bullet_y>initial_y+16 && bullet_y<initial_y+32){
480
+			if(bullet_x >= BUNKER3_X-3 && bullet_x<BUNKER3_X+16 && bunker[4] != 4){
481
+				erodeBunker(framePointer, 2, 4);
482
+				hit = 1;
483
+			}
484
+			if(bullet_x >= BUNKER3_X+16 && bullet_x<BUNKER3_X+32 && bunker[5] != 4){
485
+				erodeBunker(framePointer, 2, 5);
486
+				hit = 1;
487
+			}
488
+			if(bullet_x >= BUNKER3_X+32 && bullet_x<BUNKER3_X+48 && bunker[6] != 4){
489
+				erodeBunker(framePointer, 2, 6);
490
+				hit = 1;
491
+			}
492
+			if(bullet_x >= BUNKER3_X+48 && bullet_x<BUNKER3_X+64+3 && bunker[7] != 4){
493
+				erodeBunker(framePointer, 2, 7);
494
+				hit = 1;
495
+			}
496
+		}
497
+		if(bullet_y>initial_y+32 && bullet_y<initial_y+48){
498
+			if(bullet_x >= BUNKER3_X-3 && bullet_x<BUNKER3_X+16 && bunker[8] != 4){
499
+				erodeBunker(framePointer, 2, 8);
500
+				hit = 1;
501
+			}
502
+			if(bullet_x >= BUNKER3_X+48 && bullet_x<BUNKER3_X+64+3 && bunker[9] != 4){
503
+				erodeBunker(framePointer, 2, 9);
504
+				hit = 1;
505
+			}
506
+		}
507
+	}
508
+
509
+	if(bullet_x > BUNKER4_X-3 && bullet_x < BUNKER4_X+64+3){
510
+		bunker = getBunker4();
511
+		if(bullet_y>initial_y && bullet_y<initial_y+16){
512
+			if(bullet_x >= BUNKER4_X-3 && bullet_x<BUNKER4_X+16 && bunker[0] != 4){
513
+				erodeBunker(framePointer, 3, 0);
514
+				hit = 1;
515
+			}
516
+			if(bullet_x >= BUNKER4_X+16 && bullet_x<BUNKER4_X+32 && bunker[1] != 4){
517
+				erodeBunker(framePointer, 3, 1);
518
+				hit = 1;
519
+			}
520
+			if(bullet_x >= BUNKER4_X+32 && bullet_x<BUNKER4_X+48 && bunker[2] != 4){
521
+				erodeBunker(framePointer, 3, 2);
522
+				hit = 1;
523
+			}
524
+			if(bullet_x >= BUNKER4_X+48 && bullet_x<BUNKER4_X+64+3 && bunker[3] != 4){
525
+				erodeBunker(framePointer, 3, 3);
526
+				hit = 1;
527
+			}
528
+		}
529
+		if(bullet_y>initial_y+16 && bullet_y<initial_y+32){
530
+			if(bullet_x >= BUNKER4_X-3 && bullet_x<BUNKER4_X+16 && bunker[4] != 4){
531
+				erodeBunker(framePointer, 3, 4);
532
+				hit = 1;
533
+			}
534
+			if(bullet_x >= BUNKER4_X+16 && bullet_x<BUNKER4_X+32 && bunker[5] != 4){
535
+				erodeBunker(framePointer, 3, 5);
536
+				hit = 1;
537
+			}
538
+			if(bullet_x >= BUNKER4_X+32 && bullet_x<BUNKER4_X+48 && bunker[6] != 4){
539
+				erodeBunker(framePointer, 3, 6);
540
+				hit = 1;
541
+			}
542
+			if(bullet_x >= BUNKER4_X+48 && bullet_x<BUNKER4_X+64+3 && bunker[7] != 4){
543
+				erodeBunker(framePointer, 3, 7);
544
+				hit = 1;
545
+			}
546
+		}
547
+		if(bullet_y>initial_y+32 && bullet_y<initial_y+48){
548
+			if(bullet_x >= BUNKER4_X-3 && bullet_x<BUNKER4_X+16 && bunker[8] != 4){
549
+				erodeBunker(framePointer, 3, 8);
550
+				hit = 1;
551
+			}
552
+			if(bullet_x >= BUNKER4_X+48 && bullet_x<BUNKER4_X+64+3 && bunker[9] != 4){
553
+				erodeBunker(framePointer, 3, 9);
554
+				hit = 1;
555
+			}
556
+		}
557
+	}
558
+
559
+	if(bullet_y > tank_y_position && bullet_y < tank_y_position+16){
560
+		if(bullet_x >= getTankPositionX()-3 && bullet_x < getTankPositionX()+32+3){
561
+		    setHaveTankDeathSound(1);
562
+
563
+			counter = 0;
564
+		//	xil_printf("tank dies\r\n");
565
+
566
+			// disable interrupt to stop the whole game for little bit
567
+//			XIntc_MasterDisable(XPAR_INTC_0_BASEADDR);
568
+
569
+			setAlien1BulletState(0);
570
+			blankAlienBullet(framePointer, getAlien1BulletPositionX(), getAlien1BulletPositionY());
571
+			setAlien2BulletState(0);
572
+			blankAlienBullet(framePointer, getAlien2BulletPositionX(), getAlien2BulletPositionY());
573
+			setAlien3BulletState(0);
574
+			blankAlienBullet(framePointer, getAlien3BulletPositionX(), getAlien3BulletPositionY());
575
+			setAlien4BulletState(0);
576
+			blankAlienBullet(framePointer, getAlien4BulletPositionX(), getAlien4BulletPositionY());
577
+			setTankBulletState(0);
578
+			blankTankBullet(framePointer, getTankBulletPositionX(), getTankBulletPositionY());
579
+
580
+			gameover = tankDied(framePointer);
581
+
582
+			if(!gameover){
583
+
584
+				// for tank dying animation
585
+				while(counter < 1000){
586
+					//				if(counter%250){
587
+
588
+					if(dying == 0){
589
+						dying = 1;
590
+						blankTank(framePointer);
591
+						renderDying1(framePointer);
592
+					}
593
+					else{
594
+						dying = 0;
595
+						blankTank(framePointer);
596
+						renderDying2(framePointer);
597
+					}
598
+					//				}
599
+					counter++;
600
+				}
601
+
602
+				// reenable interrupt
603
+//				XIntc_MasterEnable(XPAR_INTC_0_BASEADDR);
604
+				renderTank(framePointer);
605
+			}
606
+		}
607
+	}
608
+
609
+	if(hit){
610
+
611
+		switch(bullet){
612
+		case 1:
613
+			setAlien1BulletState(0);
614
+			blankAlienBullet(framePointer, bullet_x-3, bullet_y-10);
615
+			break;
616
+		case 2:
617
+			setAlien2BulletState(0);
618
+			blankAlienBullet(framePointer, bullet_x-3, bullet_y-10);
619
+			break;
620
+		case 3:
621
+			setAlien3BulletState(0);
622
+			blankAlienBullet(framePointer, bullet_x-3, bullet_y-10);
623
+			break;
624
+		case 4:
625
+			setAlien4BulletState(0);
626
+			blankAlienBullet(framePointer, bullet_x-3, bullet_y-10);
627
+			break;
628
+		case 5:
629
+			setTankBulletState(0);
630
+			blankTankBullet(framePointer, bullet_x, bullet_y);
631
+			break;
632
+
633
+		default:
634
+			break;
635
+		}
636
+	}
637
+
638
+}

+ 440
- 0
ecen427/bunker.h View File

@@ -0,0 +1,440 @@
1
+#ifndef BUNKER_H_
2
+#define BUNKER_H_
3
+
4
+
5
+#define BUNKER1_X 70
6
+#define BUNKER2_X 210
7
+#define BUNKER3_X 350
8
+#define BUNKER4_X 490
9
+
10
+#define BLOCK_HEIGHT 16
11
+#define BLOCK_WIDTH 16
12
+#define packWord16(b15,b14,b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,b2,b1,b0) \
13
+		((b15 << 15) | (b14 << 14) | (b13 << 13) | (b12 << 12) | (b11 << 11) | (b10 << 10) | (b9  << 9 ) | (b8  << 8 ) |						  \
14
+				(b7  << 7 ) | (b6  << 6 ) | (b5  << 5 ) | (b4  << 4 ) | (b3  << 3 ) | (b2  << 2 ) | (b1  << 1 ) | (b0  << 0 ))
15
+
16
+
17
+
18
+int block_left0[BLOCK_HEIGHT] =		// whole block
19
+{
20
+		packWord16(0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1),
21
+		packWord16(0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1),
22
+		packWord16(0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1),
23
+		packWord16(0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1),
24
+		packWord16(0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
25
+		packWord16(0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
26
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
27
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
28
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
29
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
30
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
31
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
32
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
33
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
34
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
35
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
36
+};
37
+int block_left1[BLOCK_HEIGHT] =		// 1-hit
38
+{
39
+		packWord16(0,0,0,0,0,0,1,0,0,1,1,1,1,1,1,0),
40
+		packWord16(0,0,0,0,0,1,1,0,0,1,1,1,1,1,1,0),
41
+		packWord16(0,0,0,0,1,1,0,0,1,1,1,0,0,1,1,1),
42
+		packWord16(0,0,0,1,1,1,0,0,1,1,1,0,0,1,1,1),
43
+		packWord16(0,0,1,1,0,0,1,1,1,1,1,0,0,1,1,1),
44
+		packWord16(0,1,1,1,0,0,1,1,1,1,1,0,0,1,1,1),
45
+		packWord16(0,0,1,1,1,1,0,0,1,1,0,0,1,1,0,0),
46
+		packWord16(0,0,1,1,1,1,0,0,1,1,0,0,1,1,0,0),
47
+		packWord16(1,1,0,0,1,1,1,1,1,0,0,1,1,1,0,0),
48
+		packWord16(1,1,0,0,1,1,1,1,1,0,0,1,1,1,0,0),
49
+		packWord16(0,0,1,1,1,1,0,0,1,1,1,1,0,0,1,1),
50
+		packWord16(0,0,1,1,1,1,0,0,1,1,1,1,0,0,1,1),
51
+		packWord16(1,0,0,1,1,0,0,1,0,0,1,1,1,1,1,1),
52
+		packWord16(1,0,0,1,1,0,0,1,0,0,1,1,1,1,1,1),
53
+		packWord16(1,1,1,0,0,1,1,1,0,0,1,1,1,0,0,1),
54
+		packWord16(1,1,1,0,0,1,1,1,0,0,1,1,1,0,0,1),
55
+};
56
+int block_left2[BLOCK_HEIGHT] =		// 2-hit
57
+{
58
+		packWord16(0,0,0,0,0,0,1,0,0,1,1,0,0,1,1,0),
59
+		packWord16(0,0,0,0,0,1,1,0,0,1,1,0,0,1,1,0),
60
+		packWord16(0,0,0,0,1,1,0,0,0,0,1,0,0,1,1,0),
61
+		packWord16(0,0,0,1,1,1,0,0,0,0,1,0,0,1,1,0),
62
+		packWord16(0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0),
63
+		packWord16(0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0),
64
+		packWord16(0,0,1,0,0,1,0,0,0,0,0,0,1,1,0,0),
65
+		packWord16(0,0,1,0,0,1,0,0,0,0,0,0,1,1,0,0),
66
+		packWord16(1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0),
67
+		packWord16(1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0),
68
+		packWord16(0,0,1,1,0,0,0,0,0,0,1,1,0,0,1,0),
69
+		packWord16(0,0,1,1,0,0,0,0,0,0,1,1,0,0,1,0),
70
+		packWord16(0,0,0,0,0,0,0,1,0,0,0,0,1,1,0,0),
71
+		packWord16(0,0,0,0,0,0,0,1,0,0,0,0,1,1,0,0),
72
+		packWord16(0,0,1,0,0,0,0,0,0,0,1,1,1,0,0,1),
73
+		packWord16(0,0,1,0,0,0,0,0,0,0,1,1,1,0,0,1),
74
+};
75
+
76
+int block_left3[BLOCK_HEIGHT] =		// 3-hit
77
+{
78
+		packWord16(0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0),
79
+		packWord16(0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0),
80
+		packWord16(0,0,0,0,0,1,0,0,0,0,0,0,0,1,1,0),
81
+		packWord16(0,0,0,0,0,1,0,0,0,0,0,0,0,1,1,0),
82
+		packWord16(0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0),
83
+		packWord16(0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0),
84
+		packWord16(0,0,1,0,0,0,0,0,0,0,0,0,1,1,0,0),
85
+		packWord16(0,0,1,0,0,0,0,0,0,0,0,0,1,1,0,0),
86
+		packWord16(1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
87
+		packWord16(1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
88
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
89
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
90
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0),
91
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0),
92
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
93
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
94
+};
95
+int empty[BLOCK_HEIGHT] =		// no block
96
+{
97
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
98
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
99
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
100
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
101
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
102
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
103
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
104
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
105
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
106
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
107
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
108
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
109
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
110
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
111
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
112
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
113
+};
114
+
115
+int block_right0[BLOCK_HEIGHT] = 	// whole block
116
+{
117
+		packWord16(1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0),
118
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0),
119
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0),
120
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0),
121
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0),
122
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0),
123
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
124
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
125
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
126
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
127
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
128
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
129
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
130
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
131
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
132
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
133
+
134
+};
135
+
136
+int block_right1[BLOCK_HEIGHT] = 	// 1-hit
137
+{
138
+		packWord16(1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0),
139
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0),
140
+		packWord16(1,1,0,0,1,1,0,0,1,1,1,0,0,0,0,0),
141
+		packWord16(1,1,0,0,1,1,0,0,1,1,1,0,0,0,0,0),
142
+		packWord16(1,1,1,1,1,0,0,1,1,1,1,0,0,1,0,0),
143
+		packWord16(1,1,1,1,1,0,0,1,1,1,1,0,0,1,1,0),
144
+		packWord16(0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0),
145
+		packWord16(0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0),
146
+		packWord16(0,0,1,1,1,0,0,1,1,1,1,0,0,0,0,1),
147
+		packWord16(0,0,1,1,1,0,0,1,1,1,1,0,0,0,0,1),
148
+		packWord16(1,1,1,0,0,1,1,1,1,0,0,1,1,1,0,0),
149
+		packWord16(1,1,1,0,0,1,1,1,1,0,0,1,1,1,0,0),
150
+		packWord16(0,0,1,1,1,0,0,1,1,1,1,0,0,1,1,1),
151
+		packWord16(0,0,1,1,1,0,0,1,1,1,1,0,0,1,1,1),
152
+		packWord16(1,1,1,0,0,1,1,0,0,1,1,1,0,0,0,0),
153
+		packWord16(1,1,1,0,0,1,1,0,0,1,1,1,0,0,0,0),
154
+
155
+};
156
+
157
+int block_right2[BLOCK_HEIGHT] = 	// 2-hit
158
+{
159
+		packWord16(1,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0),
160
+		packWord16(1,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0),
161
+		packWord16(0,0,0,0,1,1,0,0,1,1,1,0,0,0,0,0),
162
+		packWord16(0,0,0,0,1,1,0,0,1,1,1,0,0,0,0,0),
163
+		packWord16(1,1,0,0,0,0,0,1,1,0,0,0,0,1,0,0),
164
+		packWord16(1,1,0,0,0,0,0,1,1,0,0,0,0,1,1,0),
165
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0),
166
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0),
167
+		packWord16(0,0,1,1,1,0,0,0,0,1,1,0,0,0,0,1),
168
+		packWord16(0,0,1,1,1,0,0,0,0,1,1,0,0,0,0,1),
169
+		packWord16(1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0),
170
+		packWord16(1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0),
171
+		packWord16(0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,1),
172
+		packWord16(0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,1),
173
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0),
174
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0),
175
+
176
+};
177
+
178
+int block_right3[BLOCK_HEIGHT] = 	// 3-hit
179
+{
180
+		packWord16(0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0),
181
+		packWord16(0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0),
182
+		packWord16(0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0),
183
+		packWord16(0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0),
184
+		packWord16(1,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0),
185
+		packWord16(1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0),
186
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0),
187
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0),
188
+		packWord16(0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0),
189
+		packWord16(0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0),
190
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
191
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
192
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1),
193
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1),
194
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
195
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
196
+
197
+};
198
+
199
+int block_center_left0[BLOCK_HEIGHT] = 	// whole block
200
+{
201
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
202
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0),
203
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0),
204
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0),
205
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0),
206
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0),
207
+		packWord16(1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0),
208
+		packWord16(1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0),
209
+		packWord16(1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0),
210
+		packWord16(1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0),
211
+		packWord16(1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0),
212
+		packWord16(1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0),
213
+		packWord16(1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0),
214
+		packWord16(1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0),
215
+		packWord16(1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
216
+		packWord16(1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
217
+};
218
+
219
+int block_center_left1[BLOCK_HEIGHT] = 	// 1-hit
220
+{
221
+		packWord16(1,1,0,0,1,1,1,1,1,1,1,0,0,1,1,1),
222
+		packWord16(1,1,0,0,1,1,1,1,1,1,1,0,0,1,1,0),
223
+		packWord16(1,1,1,1,1,1,0,0,1,1,1,1,1,1,0,0),
224
+		packWord16(1,1,1,1,1,1,0,0,1,1,1,1,1,0,0,0),
225
+		packWord16(1,1,1,0,0,1,1,1,1,1,1,1,0,0,0,0),
226
+		packWord16(1,1,1,0,0,1,1,1,1,1,1,0,0,0,0,0),
227
+		packWord16(0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0),
228
+		packWord16(0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0),
229
+		packWord16(1,1,1,0,0,1,1,1,0,0,0,0,0,0,0,0),
230
+		packWord16(1,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0),
231
+		packWord16(1,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0),
232
+		packWord16(1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0),
233
+		packWord16(1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
234
+		packWord16(1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
235
+		packWord16(1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
236
+		packWord16(1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
237
+};
238
+int block_center_left2[BLOCK_HEIGHT] = 	// 2-hit
239
+{
240
+		packWord16(1,1,0,0,1,1,1,0,0,1,1,0,0,1,1,1),
241
+		packWord16(1,1,0,0,1,1,1,0,0,1,1,0,0,1,1,0),
242
+		packWord16(0,0,1,1,1,1,0,0,1,1,0,0,1,1,0,0),
243
+		packWord16(0,0,1,1,1,1,0,0,1,1,0,0,1,0,0,0),
244
+		packWord16(1,1,1,0,0,1,1,0,0,1,1,1,0,0,0,0),
245
+		packWord16(1,1,1,0,0,1,1,0,0,1,1,0,0,0,0,0),
246
+		packWord16(0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0),
247
+		packWord16(0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0),
248
+		packWord16(1,1,1,0,0,1,1,1,0,0,0,0,0,0,0,0),
249
+		packWord16(1,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0),
250
+		packWord16(1,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0),
251
+		packWord16(1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0),
252
+		packWord16(1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
253
+		packWord16(1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
254
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
255
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
256
+};
257
+int block_center_left3[BLOCK_HEIGHT] = 	// 3-hit
258
+{
259
+		packWord16(0,0,0,0,1,1,1,0,0,1,1,0,0,0,0,0),
260
+		packWord16(0,0,0,0,1,1,1,0,0,1,1,0,0,0,0,0),
261
+		packWord16(0,0,1,0,0,1,0,0,0,0,0,0,1,1,0,0),
262
+		packWord16(0,0,1,0,0,1,0,0,0,0,0,0,1,0,0,0),
263
+		packWord16(1,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0),
264
+		packWord16(1,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0),
265
+		packWord16(0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0),
266
+		packWord16(0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0),
267
+		packWord16(1,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0),
268
+		packWord16(1,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0),
269
+		packWord16(0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0),
270
+		packWord16(0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0),
271
+		packWord16(1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
272
+		packWord16(1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
273
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
274
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
275
+};
276
+
277
+int block_center_right0[BLOCK_HEIGHT] = 	// whole block
278
+{
279
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
280
+		packWord16(0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
281
+		packWord16(0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
282
+		packWord16(0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1),
283
+		packWord16(0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1),
284
+		packWord16(0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1),
285
+		packWord16(0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1),
286
+		packWord16(0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1),
287
+		packWord16(0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1),
288
+		packWord16(0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1),
289
+		packWord16(0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1),
290
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1),
291
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1),
292
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1),
293
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1),
294
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1),
295
+};
296
+int block_center_right1[BLOCK_HEIGHT] = 	// 1-hit
297
+{
298
+		packWord16(0,0,1,1,0,0,1,1,1,1,1,0,0,1,1,1),
299
+		packWord16(0,0,1,1,0,0,1,1,1,1,1,0,0,1,1,1),
300
+		packWord16(0,0,1,1,1,1,1,0,0,1,1,1,1,1,1,1),
301
+		packWord16(0,0,0,1,1,1,1,0,0,1,1,1,1,1,1,1),
302
+		packWord16(0,0,0,0,1,0,0,1,1,1,1,0,0,1,0,0),
303
+		packWord16(0,0,0,0,0,0,0,1,1,1,1,0,0,1,0,0),
304
+		packWord16(0,0,0,0,0,0,1,1,0,0,1,1,1,1,1,1),
305
+		packWord16(0,0,0,0,0,0,0,1,0,0,1,1,1,1,1,1),
306
+		packWord16(0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0),
307
+		packWord16(0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0),
308
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1),
309
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1),
310
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1),
311
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1),
312
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1),
313
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1),
314
+};
315
+
316
+int block_center_right2[BLOCK_HEIGHT] = 	// 2-hit
317
+{
318
+		packWord16(0,0,1,1,0,0,0,0,1,1,1,0,0,1,1,1),
319
+		packWord16(0,0,1,1,0,0,0,0,1,1,1,0,0,1,1,1),
320
+		packWord16(0,0,1,1,1,1,1,0,0,1,0,0,1,1,0,0),
321
+		packWord16(0,0,0,1,1,1,1,0,0,1,0,0,1,1,0,0),
322
+		packWord16(0,0,0,0,1,0,0,1,1,1,1,0,0,1,0,0),
323
+		packWord16(0,0,0,0,0,0,0,1,1,1,1,0,0,1,0,0),
324
+		packWord16(0,0,0,0,0,0,1,1,0,0,1,1,1,0,0,1),
325
+		packWord16(0,0,0,0,0,0,0,1,0,0,1,1,1,0,0,1),
326
+		packWord16(0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0),
327
+		packWord16(0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0),
328
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1),
329
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1),
330
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
331
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
332
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1),
333
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1),
334
+};
335
+int block_center_right3[BLOCK_HEIGHT] = 	// 3-hit
336
+{
337
+		packWord16(0,0,1,1,0,0,0,0,1,1,1,0,0,0,0,0),
338
+		packWord16(0,0,1,1,0,0,0,0,1,1,1,0,0,0,0,0),
339
+		packWord16(0,0,0,0,1,1,1,0,0,0,0,0,1,1,0,0),
340
+		packWord16(0,0,0,0,1,1,1,0,0,0,0,0,1,1,0,0),
341
+		packWord16(0,0,0,0,0,0,0,1,1,0,0,0,0,1,0,0),
342
+		packWord16(0,0,0,0,0,0,0,1,1,0,0,0,0,1,0,0),
343
+		packWord16(0,0,0,0,0,0,1,1,0,0,0,0,1,0,0,1),
344
+		packWord16(0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,1),
345
+		packWord16(0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0),
346
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
347
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1),
348
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1),
349
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
350
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
351
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1),
352
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1),
353
+};
354
+
355
+int block_normal0[BLOCK_HEIGHT] = 	// whole block
356
+{
357
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
358
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
359
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
360
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
361
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
362
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
363
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
364
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
365
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
366
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
367
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
368
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
369
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
370
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
371
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
372
+		packWord16(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
373
+};
374
+int block_normal1[BLOCK_HEIGHT] = 	// 1-hit
375
+{
376
+		packWord16(1,0,0,1,1,1,1,0,0,1,1,1,1,1,1,1),
377
+		packWord16(1,0,0,1,1,1,1,0,0,1,1,1,1,1,1,1),
378
+		packWord16(1,1,1,1,0,0,1,1,0,0,1,0,0,1,1,1),
379
+		packWord16(1,1,1,1,0,0,1,1,0,0,1,0,0,1,1,1),
380
+		packWord16(1,1,0,0,1,1,0,0,1,1,1,1,1,1,0,0),
381
+		packWord16(1,1,0,0,1,1,0,0,1,1,1,1,1,1,0,0),
382
+		packWord16(0,0,1,1,1,1,1,1,1,0,0,1,0,0,1,1),
383
+		packWord16(0,0,1,1,1,1,1,1,1,0,0,1,0,0,1,1),
384
+		packWord16(1,1,1,0,0,1,1,0,0,1,1,1,1,1,0,0),
385
+		packWord16(1,1,1,0,0,1,1,0,0,1,1,1,1,1,0,0),
386
+		packWord16(0,1,1,1,1,1,1,1,1,0,0,1,0,0,1,1),
387
+		packWord16(0,1,1,1,1,1,1,1,1,0,0,1,0,0,1,1),
388
+		packWord16(1,0,0,1,1,1,0,0,1,1,1,0,0,1,1,1),
389
+		packWord16(1,0,0,1,1,1,0,0,1,1,1,0,0,1,1,1),
390
+		packWord16(1,1,1,0,0,1,1,1,0,0,1,1,1,1,0,0),
391
+		packWord16(1,1,1,0,0,1,1,1,0,0,1,1,1,1,0,0),
392
+};
393
+
394
+int block_normal2[BLOCK_HEIGHT] = 	// 2-hit
395
+{
396
+		packWord16(1,0,0,1,1,0,0,0,0,1,1,1,0,0,1,1),
397
+		packWord16(1,0,0,1,1,0,0,0,0,1,1,1,0,0,1,1),
398
+		packWord16(0,0,1,1,0,0,1,1,0,0,1,0,0,1,0,0),
399
+		packWord16(0,0,1,1,0,0,1,1,0,0,1,0,0,1,0,0),
400
+		packWord16(0,0,0,0,1,1,0,0,1,1,0,0,1,1,0,0),
401
+		packWord16(0,0,0,0,1,1,0,0,1,1,0,0,1,1,0,0),
402
+		packWord16(0,0,1,1,0,0,1,1,1,0,0,0,0,0,1,1),
403
+		packWord16(0,0,1,1,0,0,1,1,1,0,0,0,0,0,1,1),
404
+		packWord16(0,0,1,0,0,1,1,0,0,0,0,1,1,1,0,0),
405
+		packWord16(0,0,1,0,0,1,1,0,0,0,0,1,1,1,0,0),
406
+		packWord16(0,1,1,1,1,0,0,1,1,0,0,0,0,0,1,1),
407
+		packWord16(0,1,1,1,1,0,0,1,1,0,0,0,0,0,1,1),
408
+		packWord16(1,0,0,0,0,1,0,0,1,1,1,0,0,0,0,0),
409
+		packWord16(1,0,0,0,0,1,0,0,1,1,1,0,0,0,0,0),
410
+		packWord16(0,1,1,0,0,0,0,1,0,0,0,0,1,1,0,0),
411
+		packWord16(0,1,1,0,0,0,0,1,0,0,0,0,1,1,0,0),
412
+};
413
+
414
+int block_normal3[BLOCK_HEIGHT] = 	// 3-hit
415
+{
416
+		packWord16(1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,1),
417
+		packWord16(1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,1),
418
+		packWord16(0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0),
419
+		packWord16(0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0),
420
+		packWord16(0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0),
421
+		packWord16(0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0),
422
+		packWord16(0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1),
423
+		packWord16(0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1),
424
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0),
425
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0),
426
+		packWord16(0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1),
427
+		packWord16(0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1),
428
+		packWord16(0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0),
429
+		packWord16(0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0),
430
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0),
431
+		packWord16(0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0),
432
+};
433
+
434
+void renderBunker(unsigned int*);
435
+void erodeBunker(unsigned int*, int which_bunker, int which_block);
436
+void blankBlock(unsigned int*, int which_bunker, int which_block, int block_row, int block_col);
437
+void updateBlock(unsigned int*, int which_bunker, int which_block, int block_row, int block_col, short* bunker);
438
+void selectBlock(unsigned int*, int bullet);
439
+
440
+#endif /* BUNKER_H_ */

+ 284
- 0
ecen427/global.c View File

@@ -0,0 +1,284 @@
1
+#include "global.h"
2
+
3
+
4
+static point_t alienBlockPosition;
5
+static point_t tankPosition;
6
+
7
+
8
+
9
+static short alienDirection;
10
+static short guise = 0;
11
+static short guiseBullet = 0;
12
+static short aliens[55] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
13
+		                   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
14
+		                   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
15
+		                   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
16
+		                   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
17
+
18
+static short bunker1[10] = {0,0,0,0,0,0,0,0,0,0};
19
+static short bunker2[10] = {0,0,0,0,0,0,0,0,0,0};
20
+static short bunker3[10] = {0,0,0,0,0,0,0,0,0,0};
21
+static short bunker4[10] = {0,0,0,0,0,0,0,0,0,0};
22
+
23
+
24
+
25
+static point_t tankBulletPosition;
26
+static point_t alienBulletPosition1;
27
+static point_t alienBulletPosition2;
28
+static point_t alienBulletPosition3;
29
+static point_t alienBulletPosition4;
30
+
31
+static short tankBullet = 0;
32
+static short alienBullet1 = 0;
33
+static short alienBullet2 = 0;
34
+static short alienBullet3 = 0;
35
+static short alienBullet4 = 0;
36
+
37
+static point_t ufoPosition;
38
+static short ufo_state = 0;
39
+static short ufo_left;
40
+
41
+
42
+short getUfoDirection(){
43
+	return ufo_left;
44
+}
45
+short setUfoDirection(){
46
+	ufo_left = rand()%2;
47
+}
48
+
49
+short getUfoPositionY() {
50
+	return ufoPosition.y;
51
+}
52
+void setUfoPositionY(short update) {
53
+	ufoPosition.y = update;
54
+}
55
+short getUfoPositionX() {
56
+	return ufoPosition.x;
57
+}
58
+void setUfoPositionX(short update) {
59
+	ufoPosition.x = update;
60
+}
61
+short getUfoState(){
62
+	return ufo_state;
63
+}
64
+void setUfoState(short state){
65
+	ufo_state = state;
66
+}
67
+
68
+unsigned short getGuiseBullet() {
69
+	return guiseBullet;
70
+}
71
+
72
+void setGuiseBullet(unsigned short frame) {
73
+	guiseBullet = frame;
74
+}
75
+
76
+// for tank bullet
77
+void setTankBulletState(short state) {
78
+	tankBullet = state;
79
+}
80
+
81
+short getTankBulletState() {
82
+	return tankBullet;
83
+}
84
+
85
+void initialTankBulletPosition() {
86
+	tankBulletPosition.x = getTankPositionX()+11;
87
+	tankBulletPosition.y = 410;
88
+}
89
+
90
+short getTankBulletPositionX() {
91
+	return tankBulletPosition.x;
92
+}
93
+
94
+short getTankBulletPositionY() {
95
+	return tankBulletPosition.y;
96
+}
97
+
98
+void setTankBulletPositionY(short update) {
99
+	tankBulletPosition.y = update;
100
+}
101
+
102
+//for alien bullet1
103
+void setAlien1BulletState(short state) {
104
+	alienBullet1 = state;
105
+}
106
+
107
+short getAlien1BulletState() {
108
+	return alienBullet1;
109
+}
110
+
111
+short getAlien1BulletPositionX() {
112
+	return alienBulletPosition1.x;
113
+}
114
+
115
+short getAlien1BulletPositionY() {
116
+	return alienBulletPosition1.y;
117
+}
118
+
119
+void setAlien1BulletPositionY(short update) {
120
+	alienBulletPosition1.y = update;
121
+}
122
+
123
+void setAlien1BulletPosition(short x, short y) {
124
+	alienBulletPosition1.x = x;
125
+	alienBulletPosition1.y = y;
126
+}
127
+//for alien bullet2
128
+void setAlien2BulletState(short state) {
129
+	alienBullet2 = state;
130
+}
131
+
132
+short getAlien2BulletState() {
133
+	return alienBullet2;
134
+}
135
+
136
+short getAlien2BulletPositionX() {
137
+	return alienBulletPosition2.x;
138
+}
139
+
140
+short getAlien2BulletPositionY() {
141
+	return alienBulletPosition2.y;
142
+}
143
+
144
+void setAlien2BulletPositionY(short update) {
145
+	alienBulletPosition2.y = update;
146
+}
147
+
148
+void setAlien2BulletPosition(short x, short y) {
149
+	alienBulletPosition2.x = x;
150
+	alienBulletPosition2.y = y;
151
+}
152
+
153
+//for alien bullet3
154
+void setAlien3BulletState(short state) {
155
+	alienBullet3 = state;
156
+}
157
+
158
+short getAlien3BulletState() {
159
+	return alienBullet3;
160
+}
161
+
162
+short getAlien3BulletPositionX() {
163
+	return alienBulletPosition3.x;
164
+}
165
+
166
+short getAlien3BulletPositionY() {
167
+	return alienBulletPosition3.y;
168
+}
169
+
170
+void setAlien3BulletPositionY(short update) {
171
+	alienBulletPosition3.y = update;
172
+}
173
+
174
+void setAlien3BulletPosition(short x, short y) {
175
+	alienBulletPosition3.x = x;
176
+	alienBulletPosition3.y = y;
177
+}
178
+
179
+//for alien bullet4
180
+void setAlien4BulletState(short state) {
181
+	alienBullet4 = state;
182
+}
183
+
184
+short getAlien4BulletState() {
185
+	return alienBullet4;
186
+}
187
+
188
+short getAlien4BulletPositionX() {
189
+	return alienBulletPosition4.x;
190
+}
191
+
192
+short getAlien4BulletPositionY() {
193
+	return alienBulletPosition4.y;
194
+}
195
+
196
+void setAlien4BulletPositionY(short update) {
197
+	alienBulletPosition4.y = update;
198
+}
199
+
200
+void setAlien4BulletPosition(short x, short y) {
201
+	alienBulletPosition4.x = x;
202
+	alienBulletPosition4.y = y;
203
+}
204
+//for bunker
205
+short* getBunker1() {
206
+	return bunker1;
207
+}
208
+
209
+void setBunker1(unsigned short state, unsigned short block) {
210
+	bunker1[block] = state;
211
+}
212
+short* getBunker2() {
213
+	return bunker2;
214
+}
215
+
216
+void setBunker2(unsigned short state, unsigned short block) {
217
+	bunker2[block] = state;
218
+}
219
+short* getBunker3() {
220
+	return bunker3;
221
+}
222
+
223
+void setBunker3(unsigned short state, unsigned short block) {
224
+	bunker3[block] = state;
225
+}
226
+short* getBunker4() {
227
+	return bunker4;
228
+}
229
+
230
+void setBunker4(unsigned short state, unsigned short block) {
231
+	bunker1[block] = state;
232
+}
233
+
234
+// Here are the accessors.
235
+short* getAliens() {
236
+	return aliens;
237
+}
238
+
239
+void setAliens(unsigned short alien, unsigned short position) {
240
+	xil_printf("setting alien\r\n");
241
+	aliens[position] = alien;
242
+}
243
+
244
+unsigned short getGuise() {
245
+	return guise;
246
+}
247
+
248
+void setGuise(unsigned short frame) {
249
+	guise = frame;
250
+}
251
+
252
+unsigned short getDirection() {
253
+	return alienDirection;
254
+}
255
+
256
+void setDirection(unsigned short direction) {
257
+	alienDirection = direction;
258
+}
259
+
260
+void setAlienBlockPosition(unsigned short x, unsigned short y) {
261
+	alienBlockPosition.x = x;
262
+	alienBlockPosition.y = y;
263
+}
264
+
265
+unsigned short getAlienBlockPositionX() {
266
+  return alienBlockPosition.x;
267
+}
268
+
269
+unsigned short getAlienBlockPositionY() {
270
+  return alienBlockPosition.y;
271
+}
272
+void setTankPosition(unsigned short x, unsigned short y) {
273
+	tankPosition.x = x;
274
+	tankPosition.y = y;
275
+}
276
+
277
+unsigned short getTankPositionX() {
278
+  return tankPosition.x;
279
+}
280
+
281
+unsigned short getTankPositionY() {
282
+  return tankPosition.y;
283
+}
284
+

+ 16
- 0
ecen427/global.h View File

@@ -0,0 +1,16 @@
1
+#ifndef GLOBAL_H_
2
+#define GLOBAL_H_
3
+#define WORD_WIDTH 32;
4
+
5
+typedef struct {unsigned short x; unsigned short y;} point_t;
6
+
7
+void setAlienBlockPosition(unsigned short x, unsigned short y);
8
+unsigned short getAlienBlockPositionX();
9
+unsigned short getAlienBlockPositionY();
10
+
11
+void setTankPosition(unsigned short x, unsigned short y);
12
+unsigned short getTankPositionX();
13
+unsigned short getTankPositionY();
14
+
15
+
16
+#endif /* GLOBAL_H_ */

+ 213
- 0
ecen427/lscript.ld View File

@@ -0,0 +1,213 @@
1
+/*******************************************************************/
2
+/*                                                                 */
3
+/* This file is automatically generated by linker script generator.*/
4
+/*                                                                 */
5
+/* Version: Xilinx EDK 13.4 EDK_O.87xd                                */
6
+/*                                                                 */
7
+/* Copyright (c) 2010 Xilinx, Inc.  All rights reserved.           */
8
+/*                                                                 */
9
+/* Description : MicroBlaze Linker Script                          */
10
+/*                                                                 */
11
+/*******************************************************************/
12
+
13
+_STACK_SIZE = DEFINED(_STACK_SIZE) ? _STACK_SIZE : 0x1000;
14
+_HEAP_SIZE = DEFINED(_HEAP_SIZE) ? _HEAP_SIZE : 0x400;
15
+
16
+/* Define Memories in the system */
17
+
18
+MEMORY
19
+{
20
+   microblaze_0_i_bram_ctrl_microblaze_0_d_bram_ctrl : ORIGIN = 0x00000050, LENGTH = 0x00007FB0
21
+   MCB_DDR2_S0_AXI_BASEADDR : ORIGIN = 0xC0000000, LENGTH = 0x08000000
22
+}
23
+
24
+/* Specify the default entry point to the program */
25
+
26
+ENTRY(_start)
27
+
28
+/* Define the sections, and where they are mapped in memory */
29
+
30
+SECTIONS
31
+{
32
+.vectors.reset 0x00000000 : {
33
+   *(.vectors.reset)
34
+} 
35
+
36
+.vectors.sw_exception 0x00000008 : {
37
+   *(.vectors.sw_exception)
38
+} 
39
+
40
+.vectors.interrupt 0x00000010 : {
41
+   *(.vectors.interrupt)
42
+} 
43
+
44
+.vectors.hw_exception 0x00000020 : {
45
+   *(.vectors.hw_exception)
46
+} 
47
+
48
+.text : {
49
+   *(.text)
50
+   *(.text.*)
51
+   *(.gnu.linkonce.t.*)
52
+} > MCB_DDR2_S0_AXI_BASEADDR
53
+
54
+.init : {
55
+   KEEP (*(.init))
56
+} > MCB_DDR2_S0_AXI_BASEADDR
57
+
58
+.fini : {
59
+   KEEP (*(.fini))
60
+} > MCB_DDR2_S0_AXI_BASEADDR
61
+
62
+.ctors : {
63
+   __CTOR_LIST__ = .;
64
+   ___CTORS_LIST___ = .;
65
+   KEEP (*crtbegin.o(.ctors))
66
+   KEEP (*(EXCLUDE_FILE(*crtend.o) .ctors))
67
+   KEEP (*(SORT(.ctors.*)))
68
+   KEEP (*(.ctors))
69
+   __CTOR_END__ = .;
70
+   ___CTORS_END___ = .;
71
+} > MCB_DDR2_S0_AXI_BASEADDR
72
+
73
+.dtors : {
74
+   __DTOR_LIST__ = .;
75
+   ___DTORS_LIST___ = .;
76
+   KEEP (*crtbegin.o(.dtors))
77
+   KEEP (*(EXCLUDE_FILE(*crtend.o) .dtors))
78
+   KEEP (*(SORT(.dtors.*)))
79
+   KEEP (*(.dtors))
80
+   __DTOR_END__ = .;
81
+   ___DTORS_END___ = .;
82
+} > MCB_DDR2_S0_AXI_BASEADDR
83
+
84
+.rodata : {
85
+   __rodata_start = .;
86
+   *(.rodata)
87
+   *(.rodata.*)
88
+   *(.gnu.linkonce.r.*)
89
+   __rodata_end = .;
90
+} > MCB_DDR2_S0_AXI_BASEADDR
91
+
92
+.sdata2 : {
93
+   . = ALIGN(8);
94
+   __sdata2_start = .;
95
+   *(.sdata2)
96
+   *(.sdata2.*)
97
+   *(.gnu.linkonce.s2.*)
98
+   . = ALIGN(8);
99
+   __sdata2_end = .;
100
+} > MCB_DDR2_S0_AXI_BASEADDR
101
+
102
+.sbss2 : {
103
+   __sbss2_start = .;
104
+   *(.sbss2)
105
+   *(.sbss2.*)
106
+   *(.gnu.linkonce.sb2.*)
107
+   __sbss2_end = .;
108
+} > MCB_DDR2_S0_AXI_BASEADDR
109
+
110
+.data : {
111
+   . = ALIGN(4);
112
+   __data_start = .;
113
+   *(.data)
114
+   *(.data.*)
115
+   *(.gnu.linkonce.d.*)
116
+   __data_end = .;
117
+} > MCB_DDR2_S0_AXI_BASEADDR
118
+
119
+.got : {
120
+   *(.got)
121
+} > MCB_DDR2_S0_AXI_BASEADDR
122
+
123
+.got1 : {
124
+   *(.got1)
125
+} > MCB_DDR2_S0_AXI_BASEADDR
126
+
127
+.got2 : {
128
+   *(.got2)
129
+} > MCB_DDR2_S0_AXI_BASEADDR
130
+
131
+.eh_frame : {
132
+   *(.eh_frame)
133
+} > MCB_DDR2_S0_AXI_BASEADDR
134
+
135
+.jcr : {
136
+   *(.jcr)
137
+} > MCB_DDR2_S0_AXI_BASEADDR
138
+
139
+.gcc_except_table : {
140
+   *(.gcc_except_table)
141
+} > MCB_DDR2_S0_AXI_BASEADDR
142
+
143
+.sdata : {
144
+   . = ALIGN(8);
145
+   __sdata_start = .;
146
+   *(.sdata)
147
+   *(.sdata.*)
148
+   *(.gnu.linkonce.s.*)
149
+   __sdata_end = .;
150
+} > MCB_DDR2_S0_AXI_BASEADDR
151
+
152
+.sbss : {
153
+   . = ALIGN(4);
154
+   __sbss_start = .;
155
+   *(.sbss)
156
+   *(.sbss.*)
157
+   *(.gnu.linkonce.sb.*)
158
+   . = ALIGN(8);
159
+   __sbss_end = .;
160
+} > MCB_DDR2_S0_AXI_BASEADDR
161
+
162
+.tdata : {
163
+   __tdata_start = .;
164
+   *(.tdata)
165
+   *(.tdata.*)
166
+   *(.gnu.linkonce.td.*)
167
+   __tdata_end = .;
168
+} > MCB_DDR2_S0_AXI_BASEADDR
169
+
170
+.tbss : {
171
+   __tbss_start = .;
172
+   *(.tbss)
173
+   *(.tbss.*)
174
+   *(.gnu.linkonce.tb.*)
175
+   __tbss_end = .;
176
+} > MCB_DDR2_S0_AXI_BASEADDR
177
+
178
+.bss : {
179
+   . = ALIGN(4);
180
+   __bss_start = .;
181
+   *(.bss)
182
+   *(.bss.*)
183
+   *(.gnu.linkonce.b.*)
184
+   *(COMMON)
185
+   . = ALIGN(4);
186
+   __bss_end = .;
187
+} > MCB_DDR2_S0_AXI_BASEADDR
188
+
189
+_SDA_BASE_ = __sdata_start + ((__sbss_end - __sdata_start) / 2 );
190
+
191
+_SDA2_BASE_ = __sdata2_start + ((__sbss2_end - __sdata2_start) / 2 );
192
+
193
+/* Generate Stack and Heap definitions */
194
+
195
+.heap : {
196
+   . = ALIGN(8);
197
+   _heap = .;
198
+   _heap_start = .;
199
+   . += _HEAP_SIZE;
200
+   _heap_end = .;
201
+} > microblaze_0_i_bram_ctrl_microblaze_0_d_bram_ctrl
202
+
203
+.stack : {
204
+   _stack_end = .;
205
+   . += _STACK_SIZE;
206
+   . = ALIGN(8);
207
+   _stack = .;
208
+   __stack = _stack;
209
+} > microblaze_0_i_bram_ctrl_microblaze_0_d_bram_ctrl
210
+
211
+_end = .;
212
+}
213
+

+ 14
- 0
ecen427/nes.c View File

@@ -0,0 +1,14 @@
1
+/*****************************************************************************
2
+* Filename:          C:\Users\superman\Desktop\korea\SpaceInvaderTestHW2/drivers/nes_v1_00_a/src/nes.c
3
+* Version:           1.00.a
4
+* Description:       nes Driver Source File
5
+* Date:              Tue Nov 18 16:03:58 2014 (by Create and Import Peripheral Wizard)
6
+*****************************************************************************/
7
+
8
+
9
+/***************************** Include Files *******************************/
10
+
11
+#include "nes.h"
12
+
13
+/************************** Function Definitions ***************************/
14
+

+ 123
- 0
ecen427/nes.h View File

@@ -0,0 +1,123 @@
1
+/*****************************************************************************
2
+* Filename:          C:\Users\superman\Desktop\korea\SpaceInvaderTestHW2/drivers/nes_v1_00_a/src/nes.h
3
+* Version:           1.00.a
4
+* Description:       nes Driver Header File
5
+* Date:              Tue Nov 18 16:03:58 2014 (by Create and Import Peripheral Wizard)
6
+*****************************************************************************/
7
+
8
+#ifndef NES_H
9
+#define NES_H
10
+
11
+/***************************** Include Files *******************************/
12
+
13
+#include "xbasic_types.h"
14
+#include "xstatus.h"
15
+#include "xil_io.h"
16
+
17
+/************************** Constant Definitions ***************************/
18
+
19
+
20
+/**
21
+ * User Logic Slave Space Offsets
22
+ * -- SLV_REG0 : user logic slave module register 0
23
+ */
24
+#define NES_USER_SLV_SPACE_OFFSET (0x00000000)
25
+#define NES_SLV_REG0_OFFSET (NES_USER_SLV_SPACE_OFFSET + 0x00000000)
26
+
27
+/**************************** Type Definitions *****************************/
28
+
29
+
30
+/***************** Macros (Inline Functions) Definitions *******************/
31
+
32
+/**
33
+ *
34
+ * Write a value to a NES register. A 32 bit write is performed.
35
+ * If the component is implemented in a smaller width, only the least
36
+ * significant data is written.
37
+ *
38
+ * @param   BaseAddress is the base address of the NES device.
39
+ * @param   RegOffset is the register offset from the base to write to.
40
+ * @param   Data is the data written to the register.
41
+ *
42
+ * @return  None.
43
+ *
44
+ * @note
45
+ * C-style signature:
46
+ * 	void NES_mWriteReg(Xuint32 BaseAddress, unsigned RegOffset, Xuint32 Data)
47
+ *
48
+ */
49
+#define NES_mWriteReg(BaseAddress, RegOffset, Data) \
50
+ 	Xil_Out32((BaseAddress) + (RegOffset), (Xuint32)(Data))
51
+
52
+/**
53
+ *
54
+ * Read a value from a NES register. A 32 bit read is performed.
55
+ * If the component is implemented in a smaller width, only the least
56
+ * significant data is read from the register. The most significant data
57
+ * will be read as 0.
58
+ *
59
+ * @param   BaseAddress is the base address of the NES device.
60
+ * @param   RegOffset is the register offset from the base to write to.
61
+ *
62
+ * @return  Data is the data from the register.
63
+ *
64
+ * @note
65
+ * C-style signature:
66
+ * 	Xuint32 NES_mReadReg(Xuint32 BaseAddress, unsigned RegOffset)
67
+ *
68
+ */
69
+#define NES_mReadReg(BaseAddress, RegOffset) \
70
+ 	Xil_In32((BaseAddress) + (RegOffset))
71
+
72
+
73
+/**
74
+ *
75
+ * Write/Read 32 bit value to/from NES user logic slave registers.
76
+ *
77
+ * @param   BaseAddress is the base address of the NES device.
78
+ * @param   RegOffset is the offset from the slave register to write to or read from.
79
+ * @param   Value is the data written to the register.
80
+ *
81
+ * @return  Data is the data from the user logic slave register.
82
+ *
83
+ * @note
84
+ * C-style signature:
85
+ * 	void NES_mWriteSlaveRegn(Xuint32 BaseAddress, unsigned RegOffset, Xuint32 Value)
86
+ * 	Xuint32 NES_mReadSlaveRegn(Xuint32 BaseAddress, unsigned RegOffset)
87
+ *
88
+ */
89
+#define NES_mWriteSlaveReg0(BaseAddress, RegOffset, Value) \
90
+ 	Xil_Out32((BaseAddress) + (NES_SLV_REG0_OFFSET) + (RegOffset), (Xuint32)(Value))
91
+
92
+#define NES_mReadSlaveReg0(BaseAddress, RegOffset) \
93
+ 	Xil_In32((BaseAddress) + (NES_SLV_REG0_OFFSET) + (RegOffset))
94
+
95
+/************************** Function Prototypes ****************************/
96
+
97
+
98
+/**
99
+ *
100
+ * Run a self-test on the driver/device. Note this may be a destructive test if
101
+ * resets of the device are performed.
102
+ *
103
+ * If the hardware system is not built correctly, this function may never
104
+ * return to the caller.
105
+ *
106
+ * @param   baseaddr_p is the base address of the NES instance to be worked on.
107
+ *
108
+ * @return
109
+ *
110
+ *    - XST_SUCCESS   if all self-test code passed
111
+ *    - XST_FAILURE   if any self-test code failed
112
+ *
113
+ * @note    Caching must be turned off for this function to work.
114
+ * @note    Self test may fail if data memory and device are not on the same bus.
115
+ *
116
+ */
117
+XStatus NES_SelfTest(void * baseaddr_p);
118
+/**
119
+*  Defines the number of registers available for read and write*/
120
+#define TEST_AXI_LITE_USER_NUM_REG 1
121
+
122
+
123
+#endif /** NES_H */

+ 14
- 0
ecen427/pit.c View File

@@ -0,0 +1,14 @@
1
+/*****************************************************************************
2
+* Filename:          C:\Users\superman\Desktop\korea\SpaceInvaderTestHW2/drivers/pit_v1_00_a/src/pit.c
3
+* Version:           1.00.a
4
+* Description:       pit Driver Source File
5
+* Date:              Thu Nov 06 14:24:21 2014 (by Create and Import Peripheral Wizard)
6
+*****************************************************************************/
7
+
8
+
9
+/***************************** Include Files *******************************/
10
+
11
+#include "pit.h"
12
+
13
+/************************** Function Definitions ***************************/
14
+

+ 129
- 0
ecen427/pit.h View File

@@ -0,0 +1,129 @@
1
+/*****************************************************************************
2
+* Filename:          C:\Users\superman\Desktop\korea\SpaceInvaderTestHW2/drivers/pit_v1_00_a/src/pit.h
3
+* Version:           1.00.a
4
+* Description:       pit Driver Header File
5
+* Date:              Thu Nov 06 14:24:21 2014 (by Create and Import Peripheral Wizard)
6
+*****************************************************************************/
7
+
8
+#ifndef PIT_H
9
+#define PIT_H
10
+
11
+/***************************** Include Files *******************************/
12
+
13
+#include "xbasic_types.h"
14
+#include "xstatus.h"
15
+#include "xil_io.h"
16
+
17
+/************************** Constant Definitions ***************************/
18
+
19
+
20
+/**
21
+ * User Logic Slave Space Offsets
22
+ * -- SLV_REG0 : user logic slave module register 0
23
+ * -- SLV_REG1 : user logic slave module register 1
24
+ */
25
+#define PIT_USER_SLV_SPACE_OFFSET (0x00000000)
26
+#define PIT_SLV_REG0_OFFSET (PIT_USER_SLV_SPACE_OFFSET + 0x00000000)
27
+#define PIT_SLV_REG1_OFFSET (PIT_USER_SLV_SPACE_OFFSET + 0x00000004)
28
+
29
+/**************************** Type Definitions *****************************/
30
+
31
+
32
+/***************** Macros (Inline Functions) Definitions *******************/
33
+
34
+/**
35
+ *
36
+ * Write a value to a PIT register. A 32 bit write is performed.
37
+ * If the component is implemented in a smaller width, only the least
38
+ * significant data is written.
39
+ *
40
+ * @param   BaseAddress is the base address of the PIT device.
41
+ * @param   RegOffset is the register offset from the base to write to.