Contains the source code from the course work throughout my undergraduate Computer Engineering degree at Brigham Young University. There is a mixture of Go, Python, C, C++, Java, VHDL, Verilog, Matlab, Bash, Assembly, etc..
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bunker.c 19KB

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