Advertisement
g_heinz

Code Dump

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