?login_element?

Subversion Repositories NedoOS

Rev

Rev 957 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #ifndef SPRITEPOOL_C
  2. #define SPRITEPOOL_C
  3.  
  4. #define MY_BULLET   0x500
  5. //#define BONUS_CARD 0x103
  6. //#define HEALTH_CARD 0x142
  7. #define BONUS_CARD 0x512
  8. #define HEALTH_CARD 0x518
  9.  
  10. #define NPC_count 15
  11. #define BULLETS_count 45
  12. #define MY_BULLETS_max 10
  13. #define MAX_BONUS_COUNT 14
  14.  
  15. #define SPR_FLIPX 16/*32768*/
  16. #define SPR_FLIPY 16384
  17. //#define MAX_Y_RES 240
  18.  
  19. #define BOSS_TYPE 255
  20.  
  21. //extern static u16 score;
  22.  
  23. static void push_bonus(u16 type, u16 x, u16 y, i8 dx, i8 dy);
  24. /*
  25. struct game_sprite
  26. {
  27.     u8 id;
  28.     u8 pal;
  29.     i16 x;
  30.     i16 y;
  31.     u16 tile;
  32. };
  33. */
  34. struct movable_sprite
  35. {
  36.     u8 id;
  37.     u8 pal;
  38.     i16 x;
  39.     i16 y;
  40.     u16 tile;
  41.     i8 dx;
  42.     i8 dy;
  43. };
  44.  
  45. typedef struct game_sprite Sprite;
  46. typedef struct movable_sprite MovableSprite;
  47.  
  48. struct npc
  49. {
  50.     MovableSprite sprite;
  51.     u16 hp;
  52.     u8 type;
  53.     u16 take_bonus;
  54. };
  55.  
  56. typedef struct npc Npc;
  57.  
  58. Sprite player;
  59. Npc npcs[NPC_count];
  60. MovableSprite bullets[BULLETS_count];
  61. MovableSprite my_bullets[MY_BULLETS_max];
  62. MovableSprite bonuses[MAX_BONUS_COUNT];
  63.  
  64. static u8 cnt;
  65. static u8 cards;
  66.  
  67. //static u8 anim_shift[] = {0, 4, 8, 12}; //const needed!!!
  68. static u8 anim_frame = 0;
  69.  
  70. static u8 is_bullet_active(MovableSprite *bullet)
  71. {
  72.     return bullet->y < MAX_Y_RES && bullet->y > -10 && bullet->x > -10 && bullet->x < 320;
  73. }
  74.  
  75. static u8 is_npc_active(Npc *npc)
  76. {
  77.     return npc->hp && npc->sprite.y < MAX_Y_RES + 40 && npc->sprite.x >= -16/*-60*/ && npc->sprite.x < 360 && npc->sprite.y > -40;
  78. }
  79.  
  80.  
  81.  
  82. void init_pool()
  83. {
  84.     cards = 2;
  85.     player.id = create_sprite(1, 4, 4);
  86.     player.pal = 15;
  87.     set_sprite256(player.id, 0, 15, 160, 205);
  88.  
  89.     for (cnt = 0; cnt < NPC_count; cnt++)
  90.     {
  91.         npcs[cnt].sprite.id = create_sprite(2, 4, 4);
  92.         npcs[cnt].sprite.y = MAX_Y_RES + 1;
  93.         npcs[cnt].hp = 0;
  94.         npcs[cnt].sprite.pal = 15;
  95.         set_sprite256(npcs[cnt].sprite.id, 0, 15, 160, 205);
  96.     }
  97.  
  98.     for (cnt = 0; cnt < BULLETS_count; cnt++)
  99.     {
  100.         bullets[cnt].id = create_sprite(0, 1, 1);
  101.         bullets[cnt].y = MAX_Y_RES + 1;
  102.         bullets[cnt].pal = 15;
  103.         set_sprite256(bullets[cnt].id, 0, 15, 160, 205);
  104.     }
  105.  
  106.     for (cnt = 0; cnt < MAX_BONUS_COUNT; cnt++)
  107.     {
  108.         bonuses[cnt].id = create_sprite(0, 1, 1);
  109.         bonuses[cnt].y = MAX_Y_RES + 1;
  110.         bonuses[cnt].pal = 15;
  111.         bonuses[cnt].dx = 0;
  112.         bonuses[cnt].dy = 0;
  113.         set_sprite256(bonuses[cnt].id, 0, 15, 160, 235);
  114.     }
  115.  
  116.         for (cnt = 0; cnt < MY_BULLETS_max; cnt++)
  117.     {
  118.         my_bullets[cnt].id = create_sprite(2, 2, 2);
  119.         my_bullets[cnt].y = -32;
  120.         my_bullets[cnt].pal = 15;
  121.         my_bullets[cnt].dx = 0;
  122.         my_bullets[cnt].dy = 0;
  123.         set_sprite256(my_bullets[cnt].id, 0, 15, 160, 105);
  124.     }
  125. }
  126.  
  127. static i8 find_free_bullet()
  128. {
  129.     for (cnt = 0; cnt < BULLETS_count; cnt++)
  130.         if (!is_bullet_active(&bullets[cnt]))
  131.             return cnt;
  132.  
  133.     return -1;
  134. }
  135.  
  136. static i8 find_free_my_bullet()
  137. {
  138.     if (cards > MY_BULLETS_max) cards = MY_BULLETS_max;
  139.     for (cnt = 0; cnt < cards; cnt++)
  140.         if (my_bullets[cnt].y < 0 || my_bullets[cnt].tile >= MY_BULLET + 6)
  141.             return cnt;
  142.  
  143.     return -1;
  144. }
  145.  
  146. static i8 find_free_npc()
  147. {
  148.     for (cnt = 0; cnt < NPC_count; cnt++)
  149.         if (!is_npc_active(&npcs[cnt]))
  150.             return cnt;
  151.  
  152.     return -1;
  153. }
  154.  
  155. static i8 find_free_bonus()
  156. {
  157.     static u8 cnt;
  158.     for (cnt = 0; cnt < MAX_BONUS_COUNT; cnt++)
  159.         if (bonuses[cnt].y > MAX_Y_RES || bonuses[cnt].x < 0 || bonuses[cnt].x > 320 || bonuses[cnt].y < 0)
  160.             return cnt;
  161.  
  162.     return -1;
  163. }
  164.  
  165. static void update_sprites(u8 part) //координаты спрайтов каждой из двух частей (part) обновляются через фрейм
  166. {
  167.     static u8 b;
  168.     set_sprite256(player.id, player.tile + (anim_frame<<2)/*anim_shift[anim_frame]*/, player.pal, player.x, player.y);
  169.     if (part)
  170.     {
  171.         for (cnt = 0; cnt < BULLETS_count; cnt++)
  172.         {
  173.             if (is_bullet_active(&bullets[cnt]))
  174.             {
  175.                 bullets[cnt].y += bullets[cnt].dy;
  176.                 bullets[cnt].x += bullets[cnt].dx;
  177.             }
  178.             set_sprite256(bullets[cnt].id, bullets[cnt].tile, bullets[cnt].pal, bullets[cnt].x, bullets[cnt].y);
  179.  
  180.             if (cnt < MAX_BONUS_COUNT)
  181.             {
  182.                 if (bonuses[cnt].y < MAX_Y_RES + 4 && bonuses[cnt].x > -8 && bonuses[cnt].x < 328)
  183.                 {
  184.                     if (bonuses[cnt].dy < 4) bonuses[cnt].dy ++;
  185.  
  186.                     bonuses[cnt].y += bonuses[cnt].dy;
  187.                     bonuses[cnt].x += bonuses[cnt].dx;
  188.                 }
  189.                 set_sprite256(bonuses[cnt].id, bonuses[cnt].tile, bonuses[cnt].pal, bonuses[cnt].x, bonuses[cnt].y);
  190.             }
  191.  
  192.             if (cnt < MY_BULLETS_max)
  193.             {
  194.                 if (my_bullets[cnt].tile >= MY_BULLET + 6) my_bullets[cnt].y = -20;
  195.                
  196.                 if (my_bullets[cnt].y > -16 && my_bullets[cnt].tile == MY_BULLET)
  197.                 {
  198.                     my_bullets[cnt].y += my_bullets[cnt].dy;
  199.                     my_bullets[cnt].x += my_bullets[cnt].dx;
  200.                 }
  201.  
  202.                 set_sprite256(my_bullets[cnt].id, my_bullets[cnt].tile, my_bullets[cnt].pal, my_bullets[cnt].x, my_bullets[cnt].y);
  203.  
  204.                 if (my_bullets[cnt].tile != MY_BULLET) my_bullets[cnt].tile += 2;
  205.             }
  206.         }
  207.     }
  208.     else
  209.     {
  210.         for (cnt = 0; cnt < NPC_count; cnt++)
  211.         {
  212.             if (npcs[cnt].hp < 1 && npcs[cnt].sprite.y < MAX_Y_RES)
  213.             {
  214.                 score += 5;
  215.                 sfx_play(3, 3);
  216.                 if (npcs[cnt].take_bonus)
  217.                 {
  218.                     push_bonus(npcs[cnt].take_bonus, npcs[cnt].sprite.x + 16, npcs[cnt].sprite.y + 16, 0, -5);
  219.                 }
  220.                 npcs[cnt].sprite.y = MAX_Y_RES + 1;
  221.             }
  222.             if (is_npc_active(&npcs[cnt]))
  223.             {
  224.                 npcs[cnt].sprite.y += npcs[cnt].sprite.dy;
  225.                 npcs[cnt].sprite.x += npcs[cnt].sprite.dx;
  226.             }
  227.             if (npcs[cnt].type == BOSS_TYPE ||
  228.                 npcs[cnt].sprite.tile == 1552)
  229.             {
  230.                 set_sprite256(npcs[cnt].sprite.id, npcs[cnt].sprite.tile + (anim_frame<<2)/*anim_shift[anim_frame]*/ + (((npcs[cnt].sprite.dx < 0)&&(npcs[cnt].sprite.tile == 1552)) ? SPR_FLIPX : 0), npcs[cnt].sprite.pal, npcs[cnt].sprite.x, npcs[cnt].sprite.y);
  231.             }
  232.             else
  233.             {
  234.                 set_sprite256(npcs[cnt].sprite.id, npcs[cnt].sprite.tile + (anim_frame<<2)/*anim_shift[anim_frame]*/, npcs[cnt].sprite.pal, npcs[cnt].sprite.x, npcs[cnt].sprite.y);
  235.             }
  236.            
  237.         }
  238.     }
  239. }
  240.  
  241. static void flush_sprites()
  242. {
  243.     for (cnt = 0; cnt < BULLETS_count; cnt++)
  244.     {
  245.         bullets[cnt].y = 400;
  246.         if (cnt < NPC_count)
  247.             npcs[cnt].sprite.y = 400;
  248.  
  249.         if (cnt < MY_BULLETS_max)
  250.             my_bullets[cnt].y = -40;
  251.  
  252.         if (cnt < MAX_BONUS_COUNT)
  253.             bonuses[cnt].y = 400;
  254.     }
  255. //begin_set_sprites();
  256.     update_sprites(0);
  257.     update_sprites(1);
  258. end_set_sprites();
  259. }
  260.  
  261. #endif