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.

ufo.c 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. #include "ufo.h"
  2. void renderUfo(unsigned int* framePointer) { // draw for the first time
  3. if(getUfoState()){
  4. short x=0, y=0;
  5. for(x = 0; x < UFO_HEIGHT; x++) {
  6. for(y = 0; y < UFO_WIDTH; y++){
  7. if ((ufo[x%UFO_HEIGHT] & (1<<(UFO_WIDTH-1-y)))) {
  8. framePointer[(getUfoPositionY()+x)*640 + getUfoPositionX()+y] = 0x00FF0000;
  9. } else {
  10. framePointer[(getUfoPositionY()+x)*640 + getUfoPositionX()+y] = 0x00000000;
  11. }
  12. }
  13. }
  14. }
  15. }
  16. void moveUfo(unsigned int* framePointer, int ufo_left) {
  17. short ufox, ufoy;
  18. ufox = getUfoPositionX();
  19. ufoy = getUfoPositionY();
  20. if((ufox+UFO_WIDTH) == 639 && !ufo_left) {
  21. setUfoPositionX(ufox);
  22. blankUfo(framePointer, getUfoPositionX(), getUfoPositionY());
  23. setUfoState(0);
  24. }
  25. if(ufox == 0 && ufo_left) {
  26. setUfoPositionX(ufox);
  27. blankUfo(framePointer, getUfoPositionX(), getUfoPositionY());
  28. setUfoState(0);
  29. }
  30. if(ufo_left) {
  31. ufox -= 1;
  32. setUfoPositionX(ufox);
  33. }
  34. else {
  35. ufox += 1;
  36. setUfoPositionX(ufox);
  37. }
  38. }
  39. void blankUfo(unsigned int* framePointer, int ufox, int ufoy){
  40. setHaveSpaceShipSound(0);
  41. short row=0, col=0;
  42. for(row = 0; row < UFO_HEIGHT; row++){
  43. for(col = 0; col < UFO_WIDTH; col++){
  44. framePointer[(ufoy+row)*640+(ufox+col)] = 0x00000000;
  45. }
  46. }
  47. }
  48. int selectingUfoscore(unsigned int* framePointer, int ufoscore){
  49. int x_position = getUfoPositionX();
  50. int y_position = getUfoPositionY();
  51. int updatingscore = 0;
  52. int counter = 0;
  53. switch(ufoscore){
  54. case 0: // 50
  55. renderUfoscore(framePointer, 5, x_position, y_position);
  56. x_position = x_position + 8;
  57. renderUfoscore(framePointer, 0, x_position, y_position);
  58. updatingscore = 50;
  59. break;
  60. case 1: // 100
  61. renderUfoscore(framePointer, 1, x_position, y_position);
  62. x_position = x_position + 8;
  63. renderUfoscore(framePointer, 0, x_position, y_position);
  64. x_position = x_position + 8;
  65. renderUfoscore(framePointer, 0, x_position, y_position);
  66. updatingscore = 100;
  67. break;
  68. case 2: // 150
  69. renderUfoscore(framePointer, 1, x_position, y_position);
  70. x_position = x_position + 8;
  71. renderUfoscore(framePointer, 5, x_position, y_position);
  72. x_position = x_position + 8;
  73. renderUfoscore(framePointer, 0, x_position, y_position);
  74. updatingscore = 150;
  75. break;
  76. case 3: // 200
  77. renderUfoscore(framePointer, 2, x_position, y_position);
  78. x_position = x_position + 8;
  79. renderUfoscore(framePointer, 0, x_position, y_position);
  80. x_position = x_position + 8;
  81. renderUfoscore(framePointer, 0, x_position, y_position);
  82. updatingscore = 200;
  83. break;
  84. case 4: // 250
  85. renderUfoscore(framePointer, 2, x_position, y_position);
  86. x_position = x_position + 8;
  87. renderUfoscore(framePointer, 5, x_position, y_position);
  88. x_position = x_position + 8;
  89. renderUfoscore(framePointer, 0, x_position, y_position);
  90. updatingscore = 250;
  91. break;
  92. case 5: // 300
  93. renderUfoscore(framePointer, 3, x_position, y_position);
  94. x_position = x_position + 8;
  95. renderUfoscore(framePointer, 0, x_position, y_position);
  96. x_position = x_position + 8;
  97. renderUfoscore(framePointer, 0, x_position, y_position);
  98. updatingscore = 300;
  99. break;
  100. case 6: // 350
  101. renderUfoscore(framePointer, 3, x_position, y_position);
  102. x_position = x_position + 8;
  103. renderUfoscore(framePointer, 5, x_position, y_position);
  104. x_position = x_position + 8;
  105. renderUfoscore(framePointer, 0, x_position, y_position);
  106. updatingscore = 350;
  107. break;
  108. default:
  109. break;
  110. }
  111. while(counter < 500000){
  112. counter++;
  113. }
  114. blankUfo(framePointer, x_position-16, y_position);
  115. return updatingscore;
  116. }
  117. void renderUfoscore(unsigned int* framePointer, int number, int x_position, int y_position){
  118. short x=0, y=0;
  119. switch(number){
  120. case 0:
  121. for(x = 0; x < UFOSCORE_HEIGHT; x++) {
  122. for(y = 0; y < UFOSCORE_WIDTH; y++){
  123. if ((ufo_zero_block[x%UFOSCORE_HEIGHT] & (1<<(UFOSCORE_WIDTH-1-y)))) {
  124. framePointer[(y_position+x)*640 + x_position+y] = 0x00FF00FF;
  125. } else {
  126. framePointer[(y_position+x)*640 + x_position+y] = 0x00000000;
  127. }
  128. }
  129. }
  130. break;
  131. case 1:
  132. for(x = 0; x < UFOSCORE_HEIGHT; x++) {
  133. for(y = 0; y < UFOSCORE_WIDTH; y++){
  134. if ((ufo_one_block[x%UFOSCORE_HEIGHT] & (1<<(UFOSCORE_WIDTH-1-y)))) {
  135. framePointer[(y_position+x)*640 + x_position+y] = 0x00FF00FF;
  136. } else {
  137. framePointer[(y_position+x)*640 + x_position+y] = 0x00000000;
  138. }
  139. }
  140. }
  141. break;
  142. case 2:
  143. for(x = 0; x < UFOSCORE_HEIGHT; x++) {
  144. for(y = 0; y < UFOSCORE_WIDTH; y++){
  145. if ((ufo_two_block[x%UFOSCORE_HEIGHT] & (1<<(UFOSCORE_WIDTH-1-y)))) {
  146. framePointer[(y_position+x)*640 + x_position+y] = 0x00FF00FF;
  147. } else {
  148. framePointer[(y_position+x)*640 + x_position+y] = 0x00000000;
  149. }
  150. }
  151. }
  152. break;
  153. case 3:
  154. for(x = 0; x < UFOSCORE_HEIGHT; x++) {
  155. for(y = 0; y < UFOSCORE_WIDTH; y++){
  156. if ((ufo_three_block[x%UFOSCORE_HEIGHT] & (1<<(UFOSCORE_WIDTH-1-y)))) {
  157. framePointer[(y_position+x)*640 + x_position+y] = 0x00FF00FF;
  158. } else {
  159. framePointer[(y_position+x)*640 + x_position+y] = 0x00000000;
  160. }
  161. }
  162. }
  163. break;
  164. case 4:
  165. for(x = 0; x < UFOSCORE_HEIGHT; x++) {
  166. for(y = 0; y < UFOSCORE_WIDTH; y++){
  167. if ((ufo_four_block[x%UFOSCORE_HEIGHT] & (1<<(UFOSCORE_WIDTH-1-y)))) {
  168. framePointer[(y_position+x)*640 + x_position+y] = 0x00FF00FF;
  169. } else {
  170. framePointer[(y_position+x)*640 + x_position+y] = 0x00000000;
  171. }
  172. }
  173. }
  174. break;
  175. case 5:
  176. for(x = 0; x < UFOSCORE_HEIGHT; x++) {
  177. for(y = 0; y < UFOSCORE_WIDTH; y++){
  178. if ((ufo_five_block[x%UFOSCORE_HEIGHT] & (1<<(UFOSCORE_WIDTH-1-y)))) {
  179. framePointer[(y_position+x)*640 + x_position+y] = 0x00FF00FF;
  180. } else {
  181. framePointer[(y_position+x)*640 + x_position+y] = 0x00000000;
  182. }
  183. }
  184. }
  185. break;
  186. case 6:
  187. for(x = 0; x < UFOSCORE_HEIGHT; x++) {
  188. for(y = 0; y < UFOSCORE_WIDTH; y++){
  189. if ((ufo_six_block[x%UFOSCORE_HEIGHT] & (1<<(UFOSCORE_WIDTH-1-y)))) {
  190. framePointer[(y_position+x)*640 + x_position+y] = 0x00FF00FF;
  191. } else {
  192. framePointer[(y_position+x)*640 + x_position+y] = 0x00000000;
  193. }
  194. }
  195. }
  196. break;
  197. case 7:
  198. for(x = 0; x < UFOSCORE_HEIGHT; x++) {
  199. for(y = 0; y < UFOSCORE_WIDTH; y++){
  200. if ((ufo_seven_block[x%UFOSCORE_HEIGHT] & (1<<(UFOSCORE_WIDTH-1-y)))) {
  201. framePointer[(y_position+x)*640 + x_position+y] = 0x00FF00FF;
  202. } else {
  203. framePointer[(y_position+x)*640 + x_position+y] = 0x00000000;
  204. }
  205. }
  206. }
  207. break;
  208. case 8:
  209. for(x = 0; x < UFOSCORE_HEIGHT; x++) {
  210. for(y = 0; y < UFOSCORE_WIDTH; y++){
  211. if ((ufo_eight_block[x%UFOSCORE_HEIGHT] & (1<<(UFOSCORE_WIDTH-1-y)))) {
  212. framePointer[(y_position+x)*640 + x_position+y] = 0x00FF00FF;
  213. } else {
  214. framePointer[(y_position+x)*640 + x_position+y] = 0x00000000;
  215. }
  216. }
  217. }
  218. break;
  219. case 9:
  220. for(x = 0; x < UFOSCORE_HEIGHT; x++) {
  221. for(y = 0; y < UFOSCORE_WIDTH; y++){
  222. if ((ufo_nine_block[x%UFOSCORE_HEIGHT] & (1<<(UFOSCORE_WIDTH-1-y)))) {
  223. framePointer[(y_position+x)*640 + x_position+y] = 0x00FF00FF;
  224. } else {
  225. framePointer[(y_position+x)*640 + x_position+y] = 0x00000000;
  226. }
  227. }
  228. }
  229. break;
  230. default:
  231. break;
  232. }
  233. }