Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. #include "podoboo.h"
  2. #include "../PHL.h"
  3. #include "../hero.h"
  4. #include "../game.h"
  5. #include "../effect.h"
  6. #include <stdlib.h>
  7. #include <math.h>
  8.  
  9. void podobooStep(Podoboo* p);
  10. void podobooDraw(Podoboo* p);
  11.  
  12. void createPodoboo(int x, int y, int offset, int height)
  13. {
  14.         int i;
  15.         for (i = 0; i < MAX_ENEMIES; i++) {
  16.                 if (enemies[i] == NULL) {
  17.                         Enemy* e = malloc(sizeof *e);
  18.                         Podoboo* p = malloc(sizeof *p);
  19.                        
  20.                         p->id = i;
  21.                        
  22.                         p->x = x;
  23.                         p->y = p->ystart = y;
  24.                        
  25.                         p->hp = 2;
  26.                         p->blink = 0;                  
  27.                        
  28.                         p->yoffset = p->rot = 0;
  29.                        
  30.                         p->vsp = 0;
  31.                         p->grav = 0.13;
  32.                        
  33.                         p->jumpheight = -5;
  34.                         /*
  35.                         if (height == 1) {
  36.                                 p->jumpheight = -5.4;
  37.                         }
  38.                         */
  39.                         if (height == 1) {
  40.                                 p->jumpheight = -7;
  41.                         }
  42.                        
  43.                         p->imageIndex = 0;                     
  44.                        
  45.                         p->timer = 30 * offset;
  46.                         p->state = 0;
  47.                        
  48.                         e->data = p;
  49.                         e->enemyStep = podobooStep;
  50.                         e->enemyDraw = podobooDraw;
  51.                         e->type = 15;
  52.                        
  53.                         enemies[i] = e;
  54.                         i = MAX_ENEMIES;
  55.                 }
  56.         }
  57. }
  58.  
  59. void podobooStep(Podoboo* p)
  60. {
  61.         //Blinking
  62.         {
  63.                 if (p->blink > 0) {
  64.                         p->blink -= 1;
  65.                 }
  66.         }
  67.        
  68.         p->timer -= 1;
  69.        
  70.         //Patterns
  71.         {
  72.                 //Float in lava
  73.                 if (p->state == 0)
  74.                 {
  75.                         //Animate
  76.                         p->imageIndex += 0.1;
  77.                         if (p->imageIndex >= 2) {
  78.                                 p->imageIndex -= 2;
  79.                         }
  80.                
  81.                         //Bob movement
  82.                         p->rot += 5;
  83.                         if (p->rot >= 360) {
  84.                                 p->rot -= 360;
  85.                         }
  86.                         p->y = p->ystart + (5 * sin(p->rot * 3.14159 / 180));
  87.                        
  88.                         //Jump
  89.                         if (p->timer <= 0) {
  90.                                 p->state = 1;
  91.                                 createLavaSplash(p->x + 20, p->y);
  92.                                
  93.                                 p->y = p->ystart;
  94.                                 p->vsp = p->jumpheight;
  95.                         }
  96.                 }
  97.                 //In air
  98.                 else if (p->state == 1)
  99.                 {
  100.                         //Animate
  101.                         p->imageIndex += 0.25;
  102.                         if (p->imageIndex >= 3) {
  103.                                 p->imageIndex -= 3;
  104.                         }
  105.                
  106.                         //Movement
  107.                         p->y += p->vsp;
  108.                         p->vsp += p->grav;
  109.                        
  110.                         //Land in lava again
  111.                         if (p->vsp > 0 && p->y >= p->ystart) {
  112.                                 createLavaSplash(p->x + 20, p->y);
  113.                                 p->y = p->ystart;
  114.                                 p->state = 0;
  115.                                 p->vsp = 0;
  116.                                 p->timer = 60;
  117.                         }
  118.                 }
  119.                
  120.         }
  121.        
  122.         //Create Mask
  123.         Mask mask;
  124.         {
  125.                 mask.unused = mask.circle = 0;
  126.                 mask.w = mask.h = 30;
  127.                 mask.x = p->x + 5;
  128.                 mask.y = p->y + 5;
  129.         }
  130.        
  131.         //Collide with hero
  132.         {
  133.                 if (checkCollision(mask, getHeroMask())) {
  134.                         heroHit(15, mask.x + (mask.w / 2));
  135.                 }
  136.         }
  137.        
  138.         //Weapon collision
  139.         {
  140.                 int i;
  141.                 for (i = 0; i < MAX_WEAPONS; i++) {
  142.                         if (weapons[i] != NULL) {
  143.                                 if (weapons[i]->cooldown == 0) {
  144.                                         if (checkCollision(mask, weapons[i]->weaponMask)) {
  145.                                                 weaponHit(weapons[i]);
  146.                                                 p->hp -= 1;
  147.                                                 p->blink = 15;
  148.                                                
  149.                                                 //Death
  150.                                                 if (p->hp <= 0) {
  151.                                                         createEffect(2, p->x - 12, p->y - 12);
  152.                                                         spawnCollectable(p->x + 20, p->y);
  153.                                                         enemyDestroy(p->id);
  154.                                                 }
  155.                                                
  156.                                                 i = MAX_WEAPONS;
  157.                                         }
  158.                                 }
  159.                         }      
  160.                 }
  161.         }
  162.  
  163. }
  164.  
  165. void podobooDraw(Podoboo* p)
  166. {
  167.         if (p->blink % 2 == 0) {
  168.                 int thisImage = p->imageIndex;
  169.                
  170.                 if (p->state == 1) {
  171.                         thisImage += 2;
  172.                 }
  173.                
  174.                 PHL_DrawSurfacePart(p->x, p->y, 280 + (40 * thisImage), 520, 40, 40, images[imgEnemies]);
  175.         }
  176. }