Advertisement
g_heinz

duszek draft

Mar 22nd, 2021
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 KB | None | 0 0
  1. #include <gb/gb.h>
  2. #include <stdio.h>
  3. #include "GameCharacter.c"
  4. #include "duszek.c"
  5.  
  6. //create struct called GameCharacter and an instance of it called duszekchar
  7. //create an unsigned byte called spritesize set to 8, and an array of 2 unsigned 8bit ints called playerlocation
  8. struct GameCharacter duszekchar;
  9. UBYTE spritesize = 8;
  10. INT8 playerlocation[2];
  11.  
  12. //some sort of delay
  13. void performantdelay(UINT8 numloops){
  14. UINT8 i;
  15. for(i = 0; i < numloops; i++){
  16. wait_vbl_done();
  17. }
  18. }
  19.  
  20. void placegamecharacter(struct GameCharacter* character, UINT8 x, UINT8 y){
  21. move_sprite(character->spritids[0], x, y);
  22. move_sprite(character->spritids[1], x + spritesize, y);
  23. move_sprite(character->spritids[2], x, y + spritesize);
  24. move_sprite(character->spritids[3], x + spritesize, y + spritesize);
  25. }
  26.  
  27. //create a function that sets the attributes for GameCharacter duszekchar
  28. void setupduszekchar(){
  29. duszekchar.x = playerlocation[0];
  30. duszekchar.y = playerlocation[1];
  31. duszekchar.width = 16;
  32. duszekchar.height = 16;
  33.  
  34. //load the sprites for duszekchar
  35. set_sprite_tile(0, 0);
  36. duszekchar.spritids[0] = 0;
  37. set_sprite_tile(1, 1);
  38. duszekchar.spritids[1] = 1;
  39. set_sprite_tile(2, 2);
  40. duszekchar.spritids[2] = 2;
  41. set_sprite_tile(3, 3);
  42. duszekchar.spritids[3] = 3;
  43.  
  44. placegamecharacter(&duszekchar,duszekchar.x,duszekchar.y);
  45. }
  46.  
  47. void flipspriteL(){
  48.  
  49. set_sprite_tile(0, 4);
  50. duszekchar.spritids[0] = 0;
  51. set_sprite_tile(1, 5);
  52. duszekchar.spritids[1] = 1;
  53. set_sprite_tile(2, 6);
  54. duszekchar.spritids[2] = 2;
  55. set_sprite_tile(3, 7);
  56. duszekchar.spritids[3] = 3;
  57.  
  58. wait_vbl_done();
  59. }
  60.  
  61. void flipspriteR(){
  62. set_sprite_tile(0, 0);
  63. duszekchar.spritids[0] = 0;
  64. set_sprite_tile(1, 1);
  65. duszekchar.spritids[1] = 1;
  66. set_sprite_tile(2, 2);
  67. duszekchar.spritids[2] = 2;
  68. set_sprite_tile(3, 3);
  69. duszekchar.spritids[3] = 3;
  70.  
  71. wait_vbl_done();
  72. }
  73.  
  74. void animatesprite(struct GameCharacter* character, INT8 movex, INT8 movey){
  75. while(movex>0){
  76. scroll_sprite(character->spritids[0], 1, 0);
  77. scroll_sprite(character->spritids[1], 1, 0);
  78. scroll_sprite(character->spritids[2], 1, 0);
  79. scroll_sprite(character->spritids[3], 1, 0);
  80.  
  81. movex -= 1;
  82. playerlocation[0]+=1;
  83. wait_vbl_done();
  84. }
  85.  
  86. while(movex<0){
  87. scroll_sprite(character->spritids[0],-1,0);
  88. scroll_sprite(character->spritids[1],-1,0);
  89. scroll_sprite(character->spritids[2],-1,0);
  90. scroll_sprite(character->spritids[3],-1,0);
  91.  
  92. movex += 1;
  93. playerlocation[0]-=1;
  94. wait_vbl_done();
  95.  
  96. }
  97.  
  98. while(movey>0){
  99. scroll_sprite(character->spritids[0], 0, 1);
  100. scroll_sprite(character->spritids[1], 0, 1);
  101. scroll_sprite(character->spritids[2], 0, 1);
  102. scroll_sprite(character->spritids[3], 0, 1);
  103.  
  104. movey -= 1;
  105. playerlocation[0]+=1;
  106. wait_vbl_done();
  107. }
  108.  
  109. while(movey<0){
  110. scroll_sprite(character->spritids[0],0,-1);
  111. scroll_sprite(character->spritids[1],0,-1);
  112. scroll_sprite(character->spritids[2],0,-1);
  113. scroll_sprite(character->spritids[3],0,-1);
  114.  
  115. movey += 1;
  116. playerlocation[1]-=1;
  117. wait_vbl_done();
  118.  
  119. }
  120. }
  121.  
  122. void main(){
  123. set_sprite_data(0,8,duszek);
  124.  
  125. playerlocation[0] = 80;
  126. playerlocation[1] = 72;
  127. INT8 tileindexL = playerlocation[0];
  128. INT8 tileindexR = playerlocation[0]+8;
  129.  
  130. setupduszekchar();
  131.  
  132. SHOW_SPRITES;
  133. DISPLAY_ON;
  134.  
  135. while(1){
  136. switch(joypad()){
  137. case J_LEFT:
  138. if(tileindexL < tileindexR){
  139. flipspriteL();
  140. tileindexL += 8;
  141. tileindexR -= 8;
  142. }
  143. else{
  144. animatesprite(&duszekchar, -16,0);
  145. }
  146. break;
  147.  
  148. case J_RIGHT:
  149. if(tileindexL > tileindexR){
  150. flipspriteR();
  151. tileindexL -= 8;
  152. tileindexR += 8;
  153. }
  154. else{
  155. animatesprite(&duszekchar, 16,0);
  156. }
  157. break;
  158.  
  159. case J_UP:
  160. animatesprite(&duszekchar, 0,-16);
  161. break;
  162.  
  163. case J_DOWN:
  164. animatesprite(&duszekchar, 0,16);
  165. break;
  166. }
  167. }
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement