Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. #include "lolidra.h"
  2. #include "../enemy.h"
  3. #include "../game.h"
  4. #include "../hero.h"
  5. #include <stdlib.h>
  6. #include <math.h>
  7.  
  8. int boss5flag = 38;
  9.  
  10. void lolidraDestroy(Lolidra* l);
  11. int getNumOfMinions();
  12.  
  13. void createLolidra(int x, int y)
  14. {
  15.         if (flags[boss5flag] == 0) { //have not beaten boss 5
  16.                 PHL_FreeSurface(images[imgBoss]);
  17.                 images[imgBoss] = PHL_LoadQDA("boss05.bmp");
  18.        
  19.                 int i;
  20.                 for (i = 0; i < MAX_ENEMIES; i++) {
  21.                         if (enemies[i] == NULL) {
  22.                                 //Boss start
  23.                                 setBossRoom();
  24.                                
  25.                                 Enemy* e = malloc(sizeof *e);
  26.                                 Lolidra* l = malloc(sizeof *l);
  27.                                 l->id = i;
  28.                                
  29.                                 l->x = x;
  30.                                 l->y = y;
  31.                                
  32.                                 l->positionY = l->y;
  33.                                
  34.                                 l->imageIndex = 0;
  35.                                 l->hoverRot = 0;
  36.                                
  37.                                 l->hp = 100;
  38.                                 //l->hp = 1;
  39.                                 l->state = 0;                          
  40.                                 l->invincible = 0;
  41.                                 l->visible = 1;
  42.                                
  43.                                 l->timer = 0;
  44.                                 l->counter = 0;
  45.                                
  46.                                 l->mask.unused = 0;
  47.                                 l->mask.circle = 1;
  48.                                 l->mask.w = 46;
  49.                                 l->mask.h = 0;
  50.                                 l->mask.x = l->x;
  51.                                 l->mask.y = l->y;
  52.                                
  53.                                 e->data = l;
  54.                                 e->enemyStep = lolidraStep;
  55.                                 e->enemyDraw = lolidraDraw;
  56.                                 e->type = 44;
  57.                                
  58.                                 enemies[i] = e;
  59.                                 i = MAX_ENEMIES;
  60.                         }
  61.                 }
  62.         }
  63. }
  64.  
  65. void lolidraStep(Lolidra* l)
  66. {
  67.         char dead = 0;
  68.        
  69.         l->imageIndex += 0.1;
  70.         if (l->imageIndex >= 3) {
  71.                 l->imageIndex -= 3;
  72.         }
  73.        
  74.         if (l->invincible > 0) {
  75.                 l->invincible -= 1;
  76.         }
  77.        
  78.         //Spawn minions
  79.         if (l->state == 0)
  80.         {              
  81.                 if (l->counter < 5) {
  82.                         l->counter += 1;
  83.                 }else{
  84.                         if (getNumOfMinions() < 10) {
  85.                                 l->counter = 0;
  86.                                 PHL_PlaySound(sounds[sndPi02], CHN_ENEMIES);
  87.                                 createMinion(l->x, l->y - 10);
  88.                         }
  89.                 }
  90.                
  91.                 l->timer += 1;
  92.                 if (l->timer >= 600){
  93.                         l->counter = 0;
  94.                         l->timer = 0;
  95.                         l->state = 1;
  96.                         l->invincible = 20;
  97.                 }
  98.         }
  99.         //Disappear
  100.         else if (l->state == 1 || l->state == 3)
  101.         {
  102.                 if (l->invincible <= 0) {
  103.                         l->visible = 0;
  104.                 }
  105.  
  106.                 if (l->timer == 0) {
  107.                         PHL_PlaySound(sounds[sndPi10], CHN_ENEMIES);
  108.                 }
  109.                
  110.                 l->timer += 1;
  111.                 if (l->timer >= 330) {
  112.                         PHL_PlaySound(sounds[sndPi03], CHN_ENEMIES);
  113.                         l->timer = 0;
  114.                         l->visible = 1;
  115.                         l->invincible = 20;                    
  116.                         l->x = herox;
  117.                         l->positionY = heroy - 40;
  118.                        
  119.                         if (l->state == 1) {
  120.                                 l->state = 2;
  121.                         }
  122.                         if (l->state == 3) {
  123.                                 l->state = 0;
  124.                         }
  125.                 }
  126.         }
  127.         //Pop-up
  128.         else if (l->state == 2)
  129.         {
  130.                 l->timer += 1;
  131.                 if (l->timer >= 180) {
  132.                         l->timer = 0;
  133.                         l->state = 3;
  134.                         l->invincible = 20;
  135.                 }
  136.         }
  137.         //Death
  138.         else if (l->state == 4)
  139.         {              
  140.                 l->y += 0.2;
  141.                
  142.                 l->timer -= 1;
  143.                 l->invincible -= 1;
  144.                
  145.                 if (l->timer % 12 == 0) {
  146.                         createEffect(2, l->x - 64 + (rand() % 128), l->y - 64 + (rand() % 128));
  147.                 }
  148.                
  149.                 if (l->timer <= 0) {
  150.                         lolidraDestroy(l);
  151.                         dead = 1;
  152.                 }
  153.         }
  154.        
  155.         if (dead == 0)
  156.         {
  157.                 if (l->state != 4) {
  158.                         //Hover
  159.                         l->hoverRot += 5;
  160.                         if (l->hoverRot >= 360) {
  161.                                 l->hoverRot -= 360;
  162.                         }
  163.                         l->y = l->positionY + (5 * sin(l->hoverRot * 3.14159 / 180));          
  164.                
  165.                         //Update Mask
  166.                         l->mask.x = l->x;
  167.                         l->mask.y = l->y;
  168.                        
  169.                         //Collisions
  170.                         if (l->visible == 1) {
  171.                                 //Collide with Hero
  172.                                 if (checkCollision(getHeroMask(), l->mask) == 1) {
  173.                                         heroHit(30, l->x);
  174.                                 }
  175.                                
  176.                                 //Weapon collision
  177.                                 int i;
  178.                                 for (i = 0; i < MAX_WEAPONS; i++) {
  179.                                         if (weapons[i] != NULL) {
  180.                                                 if (weapons[i]->cooldown == 0) {
  181.                                                         if (checkCollision(l->mask, weapons[i]->weaponMask)) {
  182.                                                                 weaponHit(weapons[i]);
  183.                                                                 l->invincible = 15;
  184.                                                                 l->hp -= 1;
  185.                                                                
  186.                                                                 //Die
  187.                                                                 if (l->hp <= 0) {
  188.                                                                         l->state = 4;
  189.                                                                         l->timer = 180;
  190.                                                                         l->invincible = 200;
  191.                                                                 }
  192.                                                                
  193.                                                                 i = MAX_WEAPONS;
  194.                                                         }
  195.                                                 }
  196.                                         }      
  197.                                 }
  198.                         }
  199.                 }
  200.         }
  201.        
  202. }
  203.  
  204. void lolidraDraw(Lolidra* l)
  205. {
  206.         if (l->visible == 1 && l->invincible % 2 == 0) {
  207.                 PHL_DrawSurfacePart(l->x - 64, l->y - 74, ((int)l->imageIndex) * 128, 0, 128, 128, images[imgBoss]);
  208.         }
  209. }
  210.  
  211. void lolidraDestroy(Lolidra* l)
  212. {
  213.         enemyDestroy(l->id);
  214.         bossDefeatedFlag = 1;
  215.         roomSecret = 1;
  216.  
  217.         flags[boss5flag] = 1;
  218.         PHL_StopMusic();
  219. }
  220.  
  221. //Minions
  222. void createMinion(int x, int y)
  223. {
  224.         int i;
  225.         for (i = 0; i < MAX_ENEMIES; i++) {
  226.                 if (enemies[i] == NULL) {
  227.                         Enemy* e = malloc(sizeof *e);
  228.                         Minion* m = malloc(sizeof *m);
  229.                         m->id = i;
  230.                        
  231.                         m->state = 0;
  232.                         m->timer = 0;
  233.                        
  234.                         m->x = x;
  235.                         m->y = y;
  236.                        
  237.                         m->positionY = m->y;
  238.                        
  239.                         m->dir = rand() % 360;
  240.                         m->spd = 8;
  241.                        
  242.                         m->imageIndex = 0;
  243.                        
  244.                         m->mask.circle = 1;
  245.                         m->mask.unused = 0;
  246.                         m->mask.w = 10;
  247.                         m->mask.x = 0;
  248.                         m->mask.y = 0;
  249.                        
  250.                         e->data = m;
  251.                         e->enemyStep = minionStep;
  252.                         e->enemyDraw = minionDraw;
  253.                         e->type = 23;
  254.                        
  255.                         enemies[i] = e;
  256.                         i = MAX_ENEMIES;
  257.                 }
  258.         }
  259. }
  260.  
  261. void minionStep(Minion* m)
  262. {
  263.         char dead = 0;
  264.        
  265.         m->imageIndex += 0.2;
  266.         if (m->imageIndex >= 2) {
  267.                 m->imageIndex -= 2;
  268.         }
  269.        
  270.         //Slow down
  271.         if (m->state == 0)
  272.         {
  273.                 if (m->spd > 0) {
  274.                         m->spd -= 0.3;
  275.                 }
  276.                
  277.                 if (m->spd <= 0) {
  278.                         m->positionY = m->y;
  279.                         m->spd = 0;
  280.                         m->dir = 0;
  281.                         m->state = 1;
  282.                 }
  283.         }
  284.         //Hover
  285.         else if (m->state == 1)
  286.         {
  287.                 //Hover
  288.                 m->dir += 5;
  289.                 if (m->dir >= 360) {
  290.                         m->dir -= 360;
  291.                 }
  292.                 m->y = m->positionY + (10 * sin(m->dir * 3.14159 / 180));
  293.                
  294.                 m->timer += 1;
  295.                 if (m->timer >= 120) {
  296.                         m->timer = 0;
  297.                         m->state = 2;
  298.                         m->spd = (rand() % 2) + 1;
  299.                         m->dir = (atan2(heroy + 20 - m->y, m->x - herox) * 180 / 3.14159) + 270;
  300.                 }
  301.         }
  302.         //Suicide
  303.         else if (m->state == 2)
  304.         {
  305.                 m->timer += 1;
  306.                 if (m->timer >= 120) {
  307.                         createEffect(5, m->x, m->y);
  308.                         enemyDestroy(m->id);
  309.                         dead = 1;
  310.                 }
  311.         }
  312.        
  313.         if (dead == 0)
  314.         {
  315.                 //Movement
  316.                 if (m->spd != 0) {
  317.                         m->x += m->spd * sin(m->dir * 3.14159 / 180);
  318.                         m->y += m->spd * cos(m->dir * 3.14159 / 180);
  319.                 }
  320.                
  321.                 //Update Mask
  322.                 m->mask.x = m->x;
  323.                 m->mask.y = m->y;
  324.                
  325.                 //Collide with Hero
  326.                 if (checkCollision(getHeroMask(), m->mask) == 1) {
  327.                         if (heroHit(10, m->x) == 1) {
  328.                                 heroPoison();
  329.                         }
  330.                 }
  331.                
  332.                 //Weapon collision
  333.                 int i;
  334.                 for (i = 0; i < MAX_WEAPONS; i++) {
  335.                         if (weapons[i] != NULL) {
  336.                                 if (checkCollision(m->mask, weapons[i]->weaponMask)) {
  337.                                         weaponHit(weapons[i]);
  338.                                         createEffect(2, m->x - 32, m->y - 32);
  339.                                         enemyDestroy(m->id);
  340.                                        
  341.                                         i = MAX_WEAPONS;
  342.                                 }
  343.                         }      
  344.                 }
  345.         }
  346. }
  347.  
  348. void minionDraw(Minion* m)
  349. {
  350.         PHL_DrawSurfacePart(m->x - 32, m->y - 32, ((int)m->imageIndex) * 64, 128, 64, 64, images[imgBoss]);
  351. }
  352.  
  353. int getNumOfMinions()
  354. {
  355.         int result = 0;
  356.        
  357.         int i;
  358.         for (i = 0; i < MAX_ENEMIES; i++) {
  359.                 if (enemies[i] != NULL) {
  360.                         if (enemies[i]->type == 23) {
  361.                                 result += 1;
  362.                         }
  363.                 }
  364.         }
  365.        
  366.         return result;
  367. }