Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. #include "platform.h"
  2. #include "game.h"
  3. #include "PHL.h"
  4. #include "hero.h"
  5. #include <stdlib.h>
  6.  
  7. void createPlatform(int type, int xstart, int ystart, int xend, int yend, int spd, int secret)
  8. {
  9.         int i;
  10.         for (i = 0; i < MAX_PLATFORMS; i++) {
  11.                 if (platforms[i] == NULL) {
  12.                         Platform* p = malloc(sizeof *p);
  13.                         p->id = i;
  14.                         p->type = type;
  15.                        
  16.                         p->x = p->xstart = xstart;
  17.                         p->y = p->ystart = ystart;
  18.                        
  19.                         p->xend = xend;
  20.                         p->yend = yend;
  21.                        
  22.                         p->timer = 0;
  23.                        
  24.                         p->secret = secret;
  25.                        
  26.                         if (roomSecret == 1) {
  27.                                 p->secret = 0;
  28.                         }
  29.                        
  30.                         p->visible = 1;
  31.                         if (p->secret == 1) {
  32.                                 p->visible = 0;
  33.                         }
  34.                        
  35.                         if (type == 1) {
  36.                                 p->xend = p->x + 1;
  37.                                 p->yend = p->y;                        
  38.                         }
  39.                        
  40.                         p->state = 0;
  41.                         p->spd = spd;
  42.                        
  43.                         p->mask.circle = 0;
  44.                         p->mask.unused = 0;
  45.                         if (p->secret == 1) {
  46.                                 p->mask.unused = 1;
  47.                         }
  48.                         p->mask.x = xstart;
  49.                         p->mask.y = ystart;
  50.                         p->mask.w = p->mask.h = 40;
  51.                        
  52.                         platforms[i] = p;
  53.                         i = MAX_PLATFORMS;
  54.                 }
  55.         }
  56. }
  57.  
  58. void platformStep(Platform* p)
  59. {
  60.         char isSolid = p->visible;
  61.        
  62.         //Megaman blocks
  63.         if (p->type == 2) {
  64.                 int myStep = p->xend,
  65.                         maxSteps = p->yend;
  66.                        
  67.                 p->timer += 1;
  68.                 if (p->timer >= maxSteps * 60 + 60) {
  69.                         p->timer = 0;
  70.                 }
  71.                
  72.                 //Play sound
  73.                 if (p->timer == myStep * 60) {
  74.                         PHL_PlaySound(sounds[sndPi03], CHN_SOUND);
  75.                 }
  76.                
  77.                 if (p->timer > myStep * 60 && p->timer <= (myStep * 60) + 60) {
  78.                         isSolid = 1;
  79.                         p->visible = 1;
  80.                        
  81.                         //Blink effect
  82.                         if (p->timer > myStep * 60 + 30) {
  83.                                 p->visible = p->timer % 2;
  84.                         }
  85.                 }else{
  86.                         isSolid = 0;
  87.                         p->mask.unused = 1;
  88.                         p->visible = 0;
  89.                        
  90.                         //Fall off platform
  91.                         if (getHeroMask().x > p->mask.x + p->mask.w || getHeroMask().x + getHeroMask().w < p->mask.x) {
  92.                         }else if (heroy == p->y - 40 && getHeroVsp() >= 0) {
  93.                                 setHeroOnground(0);
  94.                         }
  95.                 }              
  96.         }
  97.        
  98.         if (isSolid == 1) {
  99.                 p->mask.unused = 0;
  100.                
  101.                 int targx = p->xend,
  102.                         targy = p->yend;
  103.                        
  104.                 if (p->state == 1) {
  105.                         targx = p->xstart;
  106.                         targy = p->ystart;
  107.                 }
  108.                
  109.                 //Check if the player is standing on top
  110.                 int isontop = 0;
  111.                 int isabove = 0;
  112.                 if (getHeroMask().x > p->mask.x + p->mask.w || getHeroMask().x + getHeroMask().w < p->mask.x) {
  113.                 }else if (heroy == p->y - 40 && getHeroVsp() >= 0) {
  114.                         isontop = 1;
  115.                 }else if (heroy < p->y - 40) {
  116.                         isabove = 1;
  117.                 }
  118.                
  119.                 //Move platform
  120.                 if (p->y != targy) {
  121.                         if (p->y < targy) {
  122.                                 p->y += p->spd;
  123.                                 if (isontop == 1) {
  124.                                         heroy += p->spd;
  125.                                 }
  126.                         }else{
  127.                                 p->y -= p->spd;
  128.                                 if (isontop == 1) {
  129.                                         heroy -= p->spd;
  130.                                 }else{
  131.                                         p->mask.y = p->y;
  132.                                         if (checkCollision(p->mask, getHeroMask()) && isabove == 1) {
  133.                                                 heroy = p->y - 40;
  134.                                         }
  135.                                 }
  136.                         }
  137.                 }
  138.                        
  139.                 if (p->x != targx) {
  140.                         if (p->x < targx) {
  141.                                 p->x += p->spd;
  142.                                 if (isontop == 1) {
  143.                                         herox += p->spd;
  144.                                 }
  145.                         }else{
  146.                                 p->x -= p->spd;
  147.                                 if (isontop == 1) {
  148.                                         herox -= p->spd;
  149.                                 }
  150.                         }
  151.                 }
  152.                        
  153.                 if (p->x == targx && p->y == targy) {
  154.                         if (p->state == 0) {
  155.                                 p->state = 1;
  156.                         }else{
  157.                                 p->state = 0;
  158.                         }
  159.                 }
  160.                
  161.                 if (p->type == 0) //Moving platform
  162.                 {              
  163.                        
  164.                 }
  165.                 else if (p->type == 1) { //Loose block
  166.                         if (p->spd != 0) {
  167.                                 p->timer -= 1;
  168.                                 if (p->timer <= 0) {
  169.                                         createRockSmash(p->x + 20, p->y + 20);
  170.                                         if (isontop == 1) {
  171.                                                 setHeroOnground(0);
  172.                                         }
  173.                                         platformDestroy(p->id);                                
  174.                                         /*createEffectExtra(4, p->x, p->y, -1, 0, 0);
  175.                                         createEffectExtra(4, p->x, p->y, -1, 0, 1);
  176.                                         createEffectExtra(4, p->x, p->y, 1, 0, 0);
  177.                                         createEffectExtra(4, p->x, p->y, 1, 0, 1);
  178.                                         */
  179.                                 }
  180.                         }
  181.                
  182.                         if (p->spd == 0 && isontop == 1) {
  183.                                 p->spd = 2;
  184.                                 p->timer = 30;
  185.                         }
  186.                 }
  187.                
  188.                 //Update Mask
  189.                 p->mask.x = p->x;
  190.                 p->mask.y = p->y;
  191.         }else{
  192.                 //p->mask.unused = 1;
  193.                 if (p->secret == 1) {
  194.                         if (roomSecret == 1) {
  195.                                 p->mask.unused = 0;
  196.                                 p->visible = 1;
  197.                                 p->secret = 0;
  198.                                 playSecret();
  199.                         }
  200.                 }
  201.         }
  202. }
  203.  
  204. void platformDraw(Platform* p)
  205. {      
  206.         if (p->visible == 1) {
  207.                 int cropX = p->type * 40;
  208.                
  209.                 if (p->type == 3) {
  210.                         cropX = 9 * 40;
  211.                 }
  212.                
  213.                 PHL_DrawSurfacePart(p->x, p->y, cropX, 400, 40, 40, images[imgMisc20]);
  214.         }
  215. }
  216.  
  217. void platformDestroy(int id)
  218. {
  219.         if (platforms[id] != NULL) {
  220.                 free(platforms[id]);
  221.         }
  222.         platforms[id] = NULL;
  223. }