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.

bullet.c 6.7KB

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