Advertisement
Guest User

Untitled

a guest
Jan 17th, 2020
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.52 KB | None | 0 0
  1. #include <stdbool.h>
  2. #include <stddef.h>
  3. #include <stdint.h>
  4. #include <tice.h>
  5.  
  6. #include <math.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10.  
  11. #include <graphx.h>
  12. #include <keypadc.h>
  13. #include <fileioc.h>
  14.  
  15. #include "gfx/sprites.h"
  16.  
  17.  
  18. typedef struct {
  19. int x;
  20. int y;
  21. int xdir;
  22. int ydir;
  23. } bullet_t;
  24. static bullet_t bullet[20];
  25.  
  26. typedef struct {
  27. int x;
  28. int y;
  29. int xdir;
  30. int ydir;
  31. int vel;
  32. int bvel;
  33. bool detected;
  34. int health;
  35. bullet_t laser[1];
  36. } robot_t;
  37. static robot_t robots[10];
  38.  
  39.  
  40. void UpdateRobots(int *numrobots, int x, int y) {
  41. int i;
  42. for(i = 0; i < *numrobots ; i ++) {
  43. if (robots[i].xdir == 1) {
  44. gfx_TransparentSprite_NoClip(robotR,robots[i].x,robots[i].y);
  45. } else {
  46. gfx_TransparentSprite_NoClip(robotL,robots[i].x,robots[i].y);
  47. }
  48.  
  49. if (abs(x-robots[i].x) > abs(y-robots[i].y)) {
  50. if (x > robots[i].x) {
  51. robots[i].x ++;
  52. robots[i].xdir = 1;
  53. } else {
  54. robots[i].x --;
  55. robots[i].xdir = -1;
  56. }
  57. }
  58.  
  59. if (abs(y-robots[i].y) >= abs(x-robots[i].x)) {
  60. if (y > robots[i].y) {
  61. robots[i].y ++;
  62. } else {
  63. robots[i].y --;
  64. }
  65. }
  66.  
  67. }
  68. }
  69.  
  70. void UpdateBullets(int *numbullets, int *numrobots, int bvel) {
  71. int i, j;
  72. for(i = 0; i < *numbullets ; i ++) {
  73. gfx_TransparentSprite_NoClip(ball_bullet,bullet[i].x,bullet[i].y);
  74. for(j = 0; j < *numrobots; j ++) {
  75. if (gfx_CheckRectangleHotspot(bullet[i].x, bullet[i].y, ball_bullet_width, ball_bullet_height, robots[j].x, robots[j].y, robotL_width, robotL_height)){
  76.  
  77. }
  78. }
  79.  
  80. if (bullet[i].x + bullet[i].xdir * bvel > 0 && bullet[i].x + bullet[i].xdir * bvel < 320-8 &&
  81. bullet[i].y + bullet[i].ydir * bvel > 0 && bullet[i].y + bullet[i].ydir * bvel < 240-8) {
  82.  
  83. bullet[i].x += bullet[i].xdir * bvel;
  84. bullet[i].y += bullet[i].ydir * bvel;
  85.  
  86. } else {
  87.  
  88. bullet[i].x = bullet[*numbullets-1].x;
  89. bullet[i].y = bullet[*numbullets-1].y;
  90. bullet[i].xdir = bullet[*numbullets-1].xdir;
  91. bullet[i].ydir = bullet[*numbullets-1].ydir;
  92. *numbullets -= 1;
  93. }
  94. }
  95. }
  96.  
  97.  
  98.  
  99.  
  100. void main(void) {
  101.  
  102. float x=152, y=112;
  103.  
  104. int numbullets=0, bulletcap = 20, bulletDamage = 50;
  105. int loadtimer=0, loadtime=5;
  106. int gunxdir = 1, gunydir = 0;
  107. int robotspawntimer = 0, robotspawntime = 50;
  108. int numrobots = 0;
  109. int vel = 2, bvel = 4;
  110. int pause, dirs;
  111. int xspawn, yspawn;
  112.  
  113. bool quit = false;
  114. gfx_sprite_t *Character = redseed;
  115. gfx_sprite_t RobotL;
  116.  
  117. srand(rtc_Time());
  118. gfx_Begin();
  119.  
  120.  
  121. gfx_SetPalette(sprites_pal, sizeof_sprites_pal, 0);
  122. gfx_FillScreen(0);
  123. while (quit == false) {
  124.  
  125. loadtimer ++;
  126. robotspawntimer ++;
  127. dirs = 0;
  128.  
  129. gfx_ZeroScreen();
  130. gfx_SetDrawBuffer();
  131.  
  132. //character sprite
  133. gfx_TransparentSprite_NoClip(Character, x, y);
  134.  
  135.  
  136. //update robot and bullet positions
  137. UpdateRobots(&numrobots, x, y);
  138. UpdateBullets(&numbullets, &numrobots, bvel);
  139.  
  140. //spawn robots
  141. if (robotspawntimer == robotspawntime && numrobots < 10) {
  142. robotspawntimer = 0;
  143. xspawn = randInt(0,320-32);
  144. yspawn = randInt(0,240-32);
  145. if (abs(x - xspawn) > 40 && abs(y - yspawn) > 40) {
  146. robots[numrobots].x = xspawn;
  147. robots[numrobots].y = yspawn;
  148. robots[numrobots].xdir = 0;
  149. robots[numrobots].ydir = 0;
  150. robots[numrobots].vel = 1;
  151. robots[numrobots].bvel = 1;
  152. robots[numrobots].health = 100;
  153. numrobots ++;
  154. }
  155. }
  156.  
  157. kb_Scan();
  158. if (kb_Data[1] & kb_2nd && numbullets<bulletcap && loadtimer > loadtime) {
  159. loadtimer = 0;
  160. bullet[numbullets].x = x + 8;
  161. bullet[numbullets].y = y + 8;
  162. bullet[numbullets].xdir = gunxdir;
  163. bullet[numbullets].ydir = gunydir;
  164. numbullets++;
  165. }
  166.  
  167. gfx_SwapDraw();
  168.  
  169. if (kb_Data[6] & kb_Clear)
  170. quit = true;
  171. if (kb_Data[7] & kb_Left && x>0+2*vel) {
  172. x-=vel;
  173. if (!(kb_Data[2] & kb_Alpha))
  174. gunxdir = -1;
  175. dirs++;
  176. }
  177.  
  178. if (kb_Data[7] & kb_Right && x<320-32-2*vel) {
  179. x+=vel;
  180. if (!(kb_Data[2] & kb_Alpha))
  181. gunxdir = 1;
  182. dirs++;
  183. }
  184.  
  185. if (kb_Data[7] & kb_Up && y>0+2*vel) {
  186. y-=vel;
  187. if (!(kb_Data[2] & kb_Alpha))
  188. gunydir = -1;
  189. dirs++;
  190. }
  191.  
  192. if (kb_Data[7] & kb_Down && y<240-32-2*vel) {
  193. y+=vel;
  194. if (!(kb_Data[2] & kb_Alpha))
  195. gunydir = 1;
  196. dirs++;
  197. }
  198. if (!(kb_Data[2] & kb_Alpha)) {
  199. if ((dirs==1) && ((kb_Data[7] & kb_Left) || (kb_Data[7] & kb_Right)))
  200. gunydir = 0;
  201. if ((dirs==1) && ((kb_Data[7] & kb_Up) || (kb_Data[7] & kb_Down)))
  202. gunxdir = 0;
  203. }
  204. }
  205. gfx_End();
  206. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement