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.

alien.c 7.7KB

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