g_heinz

Basic attack collision draft [24 Mar 2021]

Mar 24th, 2021 (edited)
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.53 KB | None | 0 0
  1. (Folder: sprite_testing)
  2.  
  3. #include <gb/gb.h>
  4. #include <stdio.h>
  5. #include "GameCharacter.c"
  6. #include "Foe.c"
  7. #include "Attack.c"
  8. #include "duszek.c"
  9. #include "flare.c"
  10. #include "dummkopf.c"
  11.  
  12. struct GameCharacter duszekchar;
  13. struct Attack flareatk;
  14. struct Foe dummkopffoe;
  15. UBYTE spritesize = 8;
  16. INT8 playerlocation[2];
  17.  
  18. void performantdelay(UINT8 numloops){
  19. UINT8 i;
  20. for(i = 0; i < numloops; i++){
  21. wait_vbl_done();
  22. }
  23. }
  24.  
  25. UBYTE checkhit(struct Attack* attack, struct Foe* foe){
  26. return (((foe->x >= attack->x && foe->x <= attack->x+attack->width) && (foe->y >= attack->y && foe->y <= attack->y+attack->height) || (attack->x >= foe->x && attack->x <= foe->x+foe->width) && (attack->y >= foe->y && attack->y <= foe->y+foe->height)) && attack->hitbox == 1);
  27. }
  28.  
  29. void placegamecharacter(struct GameCharacter* character, UINT8 x, UINT8 y){
  30. move_sprite(character->spritids[0], x, y);
  31. move_sprite(character->spritids[1], x + spritesize, y);
  32. move_sprite(character->spritids[2], x, y + spritesize);
  33. move_sprite(character->spritids[3], x + spritesize, y + spritesize);
  34. }
  35.  
  36. void placefoe(struct Foe* foe, UINT8 x, UINT8 y){
  37. move_sprite(foe->spritids[0],x,y);
  38. move_sprite(foe->spritids[1],x+8,y);
  39. move_sprite(foe->spritids[2],x,y+8);
  40. move_sprite(foe->spritids[3],x+8,y+8);
  41. }
  42.  
  43. void setupflare(){
  44. flareatk.x = playerlocation[0]+16;
  45. flareatk.y = playerlocation[1];
  46. flareatk.width = 16;
  47. flareatk.height = 16;
  48.  
  49. //frame 1 R
  50. set_sprite_tile(4,72);
  51. flareatk.attackframes[0] = 4;
  52. set_sprite_tile(5,73);
  53. flareatk.attackframes[1] = 5;
  54. set_sprite_tile(6,74);
  55. flareatk.attackframes[2] = 6;
  56. set_sprite_tile(7,75);
  57. flareatk.attackframes[3] = 7;
  58.  
  59. //frame 2 R
  60. set_sprite_tile(4,80);
  61. flareatk.attackframes[0] = 4;
  62. set_sprite_tile(5,81);
  63. flareatk.attackframes[1] = 5;
  64. set_sprite_tile(6,82);
  65. flareatk.attackframes[2] = 6;
  66. set_sprite_tile(7,83);
  67. flareatk.attackframes[3] = 7;
  68.  
  69. //frame 3 R
  70. set_sprite_tile(4,88);
  71. flareatk.attackframes[0] = 4;
  72. set_sprite_tile(5,89);
  73. flareatk.attackframes[1] = 5;
  74. set_sprite_tile(6,90);
  75. flareatk.attackframes[2] = 6;
  76. set_sprite_tile(7,91);
  77. flareatk.attackframes[3] = 7;
  78.  
  79. }
  80.  
  81. void setupduszek(){
  82. duszekchar.x = playerlocation[0];
  83. duszekchar.y = playerlocation[1];
  84. duszekchar.width = 16;
  85. duszekchar.height = 16;
  86.  
  87. //load sprites for duszekchar
  88. set_sprite_tile(0,0);
  89. duszekchar.spritids[0] = 0;
  90. set_sprite_tile(1,1);
  91. duszekchar.spritids[1] = 1;
  92. set_sprite_tile(2,2);
  93. duszekchar.spritids[2] = 2;
  94. set_sprite_tile(3,3);
  95. duszekchar.spritids[3] = 3;
  96.  
  97. placegamecharacter(&duszekchar, duszekchar.x, duszekchar.y);
  98. }
  99.  
  100. void setupdummkopf(){
  101. dummkopffoe.x = playerlocation[0]+16;
  102. dummkopffoe.y = playerlocation[1];
  103. dummkopffoe.width = 16;
  104. dummkopffoe.height = 16;
  105.  
  106. // load sprites for dummkopf
  107. set_sprite_tile(8,97);
  108. dummkopffoe.spritids[0] = 8;
  109. set_sprite_tile(9,98);
  110. dummkopffoe.spritids[1] = 9;
  111. set_sprite_tile(10,99);
  112. dummkopffoe.spritids[2] = 10;
  113. set_sprite_tile(11,100);
  114. dummkopffoe.spritids[3] = 11;
  115.  
  116. placefoe(&dummkopffoe, dummkopffoe.x,dummkopffoe.y);
  117. }
  118.  
  119. void idleduszek(){
  120. set_sprite_tile(0,0);
  121. duszekchar.spritids[0] = 0;
  122. set_sprite_tile(1,1);
  123. duszekchar.spritids[1] = 1;
  124. set_sprite_tile(2,2);
  125. duszekchar.spritids[2] = 2;
  126. set_sprite_tile(3,3);
  127. duszekchar.spritids[3] = 3;
  128.  
  129. performantdelay(5);
  130.  
  131. set_sprite_tile(0,8);
  132. duszekchar.spritids[0] = 0;
  133. set_sprite_tile(1,9);
  134. duszekchar.spritids[1] = 1;
  135. set_sprite_tile(2,10);
  136. duszekchar.spritids[2] = 2;
  137. set_sprite_tile(3,11);
  138. duszekchar.spritids[3] = 3;
  139.  
  140. performantdelay(4);
  141.  
  142. set_sprite_tile(0,16);
  143. duszekchar.spritids[0] = 0;
  144. set_sprite_tile(1,17);
  145. duszekchar.spritids[1] = 1;
  146. set_sprite_tile(2,18);
  147. duszekchar.spritids[2] = 2;
  148. set_sprite_tile(3,19);
  149. duszekchar.spritids[3] = 3;
  150.  
  151. performantdelay(4);
  152.  
  153. set_sprite_tile(0,8);
  154. duszekchar.spritids[0] = 0;
  155. set_sprite_tile(1,9);
  156. duszekchar.spritids[1] = 1;
  157. set_sprite_tile(2,10);
  158. duszekchar.spritids[2] = 2;
  159. set_sprite_tile(3,11);
  160. duszekchar.spritids[3] = 3;
  161.  
  162. performantdelay(4);
  163. }
  164.  
  165. void attackduszek(){
  166. //duszek frame 1
  167. set_sprite_tile(0,24);
  168. duszekchar.spritids[0] = 0;
  169. set_sprite_tile(1,25);
  170. duszekchar.spritids[1] = 1;
  171. set_sprite_tile(2,26);
  172. duszekchar.spritids[2] = 2;
  173. set_sprite_tile(3,27);
  174. duszekchar.spritids[3] = 3;
  175.  
  176. performantdelay(3);
  177.  
  178. //duszek frame 2
  179. set_sprite_tile(0,32);
  180. duszekchar.spritids[0] = 0;
  181. set_sprite_tile(1,33);
  182. duszekchar.spritids[1] = 1;
  183. set_sprite_tile(2,34);
  184. duszekchar.spritids[2] = 2;
  185. set_sprite_tile(3,35);
  186. duszekchar.spritids[3] = 3;
  187.  
  188. performantdelay(3);
  189.  
  190. //duszek frame 3
  191. set_sprite_tile(0,40);
  192. duszekchar.spritids[0] = 0;
  193. set_sprite_tile(1,41);
  194. duszekchar.spritids[1] = 1;
  195. set_sprite_tile(2,42);
  196. duszekchar.spritids[2] = 2;
  197. set_sprite_tile(3,43);
  198. duszekchar.spritids[3] = 3;
  199.  
  200. performantdelay(3);
  201.  
  202. //duszek frame 4 with flare
  203. set_sprite_tile(0,48);
  204. duszekchar.spritids[0] = 0;
  205. set_sprite_tile(1,49);
  206. duszekchar.spritids[1] = 1;
  207. set_sprite_tile(2,50);
  208. duszekchar.spritids[2] = 2;
  209. set_sprite_tile(3,51);
  210. duszekchar.spritids[3] = 3;
  211.  
  212. //flare frame 1
  213. set_sprite_tile(4,72);
  214. flareatk.attackframes[0] = 4;
  215. set_sprite_tile(5,73);
  216. flareatk.attackframes[1] = 5;
  217. set_sprite_tile(6,74);
  218. flareatk.attackframes[2] = 6;
  219. set_sprite_tile(7,75);
  220. flareatk.attackframes[3] = 7;
  221. move_sprite(flareatk.attackframes[0],flareatk.x,flareatk.y);
  222. move_sprite(flareatk.attackframes[1],flareatk.x+8,flareatk.y);
  223. move_sprite(flareatk.attackframes[2],flareatk.x,flareatk.y+8);
  224. move_sprite(flareatk.attackframes[3],flareatk.x+8,flareatk.y+8);
  225.  
  226.  
  227. performantdelay(3);
  228.  
  229. // duszek frame 5 with flare
  230. set_sprite_tile(0,56);
  231. duszekchar.spritids[0] = 0;
  232. set_sprite_tile(1,57);
  233. duszekchar.spritids[1] = 1;
  234. set_sprite_tile(2,58);
  235. duszekchar.spritids[2] = 2;
  236. set_sprite_tile(3,59);
  237. duszekchar.spritids[3] = 3;
  238.  
  239. //flare frame 2
  240. //flareatk.hitbox = 1;
  241. set_sprite_tile(4,80);
  242. flareatk.attackframes[0] = 4;
  243. set_sprite_tile(5,81);
  244. flareatk.attackframes[1] = 5;
  245. set_sprite_tile(6,82);
  246. flareatk.attackframes[2] = 6;
  247. set_sprite_tile(7,83);
  248. flareatk.attackframes[3] = 7;
  249. move_sprite(flareatk.attackframes[0],flareatk.x,flareatk.y);
  250. move_sprite(flareatk.attackframes[1],flareatk.x+8,flareatk.y);
  251. move_sprite(flareatk.attackframes[2],flareatk.x,flareatk.y+8);
  252. move_sprite(flareatk.attackframes[3],flareatk.x+8,flareatk.y+8);
  253.  
  254. performantdelay(3);
  255.  
  256. // duszek frame 6 with flare
  257. set_sprite_tile(0,64);
  258. duszekchar.spritids[0] = 0;
  259. set_sprite_tile(1,65);
  260. duszekchar.spritids[1] = 1;
  261. set_sprite_tile(2,66);
  262. duszekchar.spritids[2] = 2;
  263. set_sprite_tile(3,67);
  264. duszekchar.spritids[3] = 3;
  265.  
  266. //flare frame 3
  267. set_sprite_tile(4,88);
  268. flareatk.attackframes[0] = 4;
  269. set_sprite_tile(5,89);
  270. flareatk.attackframes[1] = 5;
  271. set_sprite_tile(6,90);
  272. flareatk.attackframes[2] = 6;
  273. set_sprite_tile(7,91);
  274. flareatk.attackframes[3] = 7;
  275. move_sprite(flareatk.attackframes[0],flareatk.x,flareatk.y);
  276. move_sprite(flareatk.attackframes[1],flareatk.x+8,flareatk.y);
  277. move_sprite(flareatk.attackframes[2],flareatk.x,flareatk.y+8);
  278. move_sprite(flareatk.attackframes[3],flareatk.x+8,flareatk.y+8);
  279.  
  280. performantdelay(3);
  281.  
  282. // duszek frame 5 with flare
  283. set_sprite_tile(0,56);
  284. duszekchar.spritids[0] = 0;
  285. set_sprite_tile(1,57);
  286. duszekchar.spritids[1] = 1;
  287. set_sprite_tile(2,58);
  288. duszekchar.spritids[2] = 2;
  289. set_sprite_tile(3,59);
  290. duszekchar.spritids[3] = 3;
  291.  
  292. //flare frame 2
  293. set_sprite_tile(4,80);
  294. flareatk.attackframes[0] = 4;
  295. set_sprite_tile(5,81);
  296. flareatk.attackframes[1] = 5;
  297. set_sprite_tile(6,82);
  298. flareatk.attackframes[2] = 6;
  299. set_sprite_tile(7,83);
  300. flareatk.attackframes[3] = 7;
  301. move_sprite(flareatk.attackframes[0],flareatk.x,flareatk.y);
  302. move_sprite(flareatk.attackframes[1],flareatk.x+8,flareatk.y);
  303. move_sprite(flareatk.attackframes[2],flareatk.x,flareatk.y+8);
  304. move_sprite(flareatk.attackframes[3],flareatk.x+8,flareatk.y+8);
  305.  
  306. performantdelay(3);
  307.  
  308. // duszek frame 4 with flare
  309. set_sprite_tile(0,48);
  310. duszekchar.spritids[0] = 0;
  311. set_sprite_tile(1,49);
  312. duszekchar.spritids[1] = 1;
  313. set_sprite_tile(2,50);
  314. duszekchar.spritids[2] = 2;
  315. set_sprite_tile(3,51);
  316. duszekchar.spritids[3] = 3;
  317.  
  318. //flare frame 1
  319. //flareatk.hitbox = 0;
  320. set_sprite_tile(4,72);
  321. flareatk.attackframes[0] = 4;
  322. set_sprite_tile(5,73);
  323. flareatk.attackframes[1] = 5;
  324. set_sprite_tile(6,74);
  325. flareatk.attackframes[2] = 6;
  326. set_sprite_tile(7,75);
  327. flareatk.attackframes[3] = 7;
  328. move_sprite(flareatk.attackframes[0],flareatk.x,flareatk.y);
  329. move_sprite(flareatk.attackframes[1],flareatk.x+8,flareatk.y);
  330. move_sprite(flareatk.attackframes[2],flareatk.x,flareatk.y+8);
  331. move_sprite(flareatk.attackframes[3],flareatk.x+8,flareatk.y+8);
  332.  
  333. performantdelay(3);
  334.  
  335. // duszek frame 3
  336. set_sprite_tile(0,40);
  337. duszekchar.spritids[0] = 0;
  338. set_sprite_tile(1,41);
  339. duszekchar.spritids[1] = 1;
  340. set_sprite_tile(2,42);
  341. duszekchar.spritids[2] = 2;
  342. set_sprite_tile(3,43);
  343. duszekchar.spritids[3] = 3;
  344.  
  345. //clearing attack tiles
  346. set_sprite_tile(4,96);
  347. flareatk.attackframes[0] = 4;
  348. set_sprite_tile(5,96);
  349. flareatk.attackframes[1] = 5;
  350. set_sprite_tile(6,96);
  351. flareatk.attackframes[2] = 6;
  352. set_sprite_tile(7,96);
  353. flareatk.attackframes[3] = 7;
  354. move_sprite(flareatk.attackframes[0],flareatk.x,flareatk.y);
  355. move_sprite(flareatk.attackframes[1],flareatk.x+8,flareatk.y);
  356. move_sprite(flareatk.attackframes[2],flareatk.x,flareatk.y+8);
  357. move_sprite(flareatk.attackframes[3],flareatk.x+8,flareatk.y+8);
  358.  
  359. performantdelay(3);
  360.  
  361. // duszek frame 2
  362. set_sprite_tile(0,32);
  363. duszekchar.spritids[0] = 0;
  364. set_sprite_tile(1,33);
  365. duszekchar.spritids[1] = 1;
  366. set_sprite_tile(2,34);
  367. duszekchar.spritids[2] = 2;
  368. set_sprite_tile(3,35);
  369. duszekchar.spritids[3] = 3;
  370.  
  371. performantdelay(3);
  372.  
  373. //duszek frame 1
  374. set_sprite_tile(0,24);
  375. duszekchar.spritids[0] = 0;
  376. set_sprite_tile(1,25);
  377. duszekchar.spritids[1] = 1;
  378. set_sprite_tile(2,26);
  379. duszekchar.spritids[2] = 2;
  380. set_sprite_tile(3,27);
  381. duszekchar.spritids[3] = 3;
  382.  
  383. performantdelay(3);
  384.  
  385. }
  386.  
  387. void main(){
  388. playerlocation[0] = 80;
  389. playerlocation[1] = 72;
  390. set_sprite_data(0,72,duszek);
  391. set_sprite_data(72,25,flare);
  392. set_sprite_data(97,4,dummkopf);
  393. setupduszek();
  394. setupflare();
  395. setupdummkopf();
  396.  
  397. SHOW_SPRITES;
  398. DISPLAY_ON;
  399.  
  400. while(1){
  401. idleduszek();
  402.  
  403. switch(joypad()){
  404. case J_B:
  405. attackduszek();
  406. flareatk.hitbox = 1;
  407. if(checkhit(&flareatk,&dummkopffoe) == 1){
  408. printf("Hit!");
  409. }
  410. flareatk.hitbox==0;
  411. break;
  412. }
  413.  
  414. }
  415.  
  416. }
Add Comment
Please, Sign In to add comment