Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. #include "gas.h"
  2. #include "../PHL.h"
  3. #include "../game.h"
  4. #include "../hero.h"
  5. #include <stdlib.h>
  6.  
  7. void gasStep(Gas* g);
  8. void gasDraw(Gas* g);
  9.  
  10. void createGas(int x, int y, int temp)
  11. {
  12.         if (temp == 0 || hasKey[7] == 0) {
  13.                 int i;
  14.                 for (i = 0; i < MAX_ENEMIES; i++) {
  15.                         if (enemies[i] == NULL) {
  16.                                 Enemy* e = malloc(sizeof *e);
  17.                                 Gas* g = malloc(sizeof *g);
  18.                                 g->id = i;
  19.                                
  20.                                 g->x = x;
  21.                                 g->y = y;
  22.                                
  23.                                 g->state = 0;
  24.                                 g->timer = 0;
  25.                                 g->imageIndex = 0;
  26.                                
  27.                                 /*
  28.                                 g->mask.unused = g->mask.circle = 0;
  29.                                 g->mask.w = g->mask.h = 24;
  30.                                 g->mask.x = x + 20 - (g->mask.w / 2);
  31.                                 g->mask.y = y + 40 - g->mask.h;
  32.                                 */
  33.                                
  34.                                 e->data = g;
  35.                                 e->enemyStep = gasStep;
  36.                                 e->enemyDraw = gasDraw;
  37.                                 e->type = -1;
  38.                                
  39.                                 enemies[i] = e;
  40.                                 i = MAX_ENEMIES;
  41.                         }
  42.                 }
  43.         }
  44. }
  45.  
  46. void gasStep(Gas* g)
  47. {      
  48.         if (g->state != 0) {
  49.                 g->imageIndex += 0.2;
  50.         }
  51.        
  52.         if (g->state == 0) { //Wait
  53.                 Mask tempMask;
  54.                 tempMask.circle = tempMask.unused = 0;
  55.                 tempMask.x = g->x - 100;
  56.                 tempMask.y = g->y - 20;
  57.                 tempMask.w = 240;
  58.                 tempMask.h = 60;
  59.                
  60.                 if (checkCollisionXY(tempMask, herox, heroy + 20)) {
  61.                         g->state = 1;
  62.                         g->imageIndex = 3;
  63.                         g->timer = 32;
  64.                         PHL_PlaySound(sounds[sndGas01], CHN_ENEMIES);
  65.                 }
  66.         }
  67.         else if (g->state == 1 || g->state == 3) { //Small puff        
  68.                 if (g->imageIndex >= 5) {
  69.                         g->imageIndex -= 2;
  70.                 }
  71.                
  72.                 g->timer -= 1;
  73.                 if (g->timer <= 0) {
  74.                         if (g->state == 3) {
  75.                                 g->state = 0;
  76.                         }else{
  77.                                 g->state = 2;
  78.                                 g->imageIndex = 0;
  79.                                 g->timer = 175;
  80.                         }
  81.                 }
  82.         }
  83.         else if (g->state == 2) { //Big puff
  84.                 if (g->imageIndex >= 3) {
  85.                         g->imageIndex -= 3;
  86.                 }
  87.                
  88.                 g->timer -= 1;
  89.                 if (g->timer <= 0) {
  90.                         g->state = 3;
  91.                         g->timer = 120;
  92.                         g->imageIndex = 3;
  93.                 }
  94.                
  95.                 if (hasItem[7] != 1) { //Does not have gas mask
  96.                         Mask mask;
  97.                         mask.unused = mask.circle = 0;
  98.                         mask.w = mask.h = 24;
  99.                         mask.x = g->x + 20 - (mask.w / 2);
  100.                         mask.y = g->y + 40 - mask.h;
  101.                
  102.                         if (checkCollision(getHeroMask(), mask)) {
  103.                                 if (heroHit(15, g->x + 20)) {
  104.                                         heroPoison();
  105.                                 }
  106.                         }
  107.                 }
  108.         }
  109. }
  110.  
  111. void gasDraw(Gas* g)
  112. {
  113.         if (g->state != 0) {
  114.                 PHL_DrawSurfacePart(g->x, g->y, (int)g->imageIndex * 40, 400, 40, 40, images[imgEnemies]);
  115.         }
  116. }