Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. #include "effect.h"
  2. #include "game.h"
  3. #include "PHL.h"
  4. #include "hero.h"
  5. #include "collision.h"
  6. #include <stdlib.h>
  7. #include <math.h>
  8.  
  9. void createEffect(int type, int x, int y)
  10. {
  11.         createEffectExtra(type, x, y, 0, 0, 0);
  12. }
  13.  
  14. void createEffectExtra(int t, int x, int y, double hsp, double vsp, int val)
  15. {
  16.         int i;
  17.         for (i = 0; i < MAX_EFFECTS; i++) {
  18.                 if (effects[i] == NULL) {
  19.                         Effect* e = malloc(sizeof *e);
  20.        
  21.                         e->id = i;
  22.                         e->type = t;
  23.                        
  24.                         e->x = x;
  25.                         e->y = y;
  26.                        
  27.                         e->vsp = vsp;
  28.                         e->hsp = hsp;
  29.                         e->grav = 0;
  30.                        
  31.                         e->imageIndex = 0;
  32.                         e->imageSpeed = 0;
  33.                        
  34.                         e->cropx = 0;
  35.                         e->cropy = 0;
  36.                        
  37.                         e->width = 40;
  38.                         e->height = 40;
  39.                        
  40.                         e->image = imgMisc20;
  41.                         e->timer = 60;
  42.                        
  43.                        
  44.                         e->visible = 1;
  45.                         e->val1 = 0;
  46.                        
  47.                         e->loop = 0;
  48.                         e->frames = 0;
  49.                        
  50.                         e->depth = 1;
  51.                        
  52.                         //Sword collision      
  53.                         if (e->type == 1) {                    
  54.                                 e->cropx = 440;
  55.                                 e->cropy = 40;
  56.                                 e->imageSpeed = 0.25;
  57.                                 e->timer = 19;
  58.                         }
  59.                        
  60.                         //Enemy poof
  61.                         else if (e->type == 2) {
  62.                                 PHL_PlaySound(sounds[sndBom01], CHN_EFFECTS);
  63.                                 e->width = 64;
  64.                                 e->height = 64;
  65.                                 e->imageSpeed = 0.33;
  66.                                 e->timer = 30;
  67.                                 e->image = imgMisc32;
  68.                         }
  69.                        
  70.                         //Dust after landing from a fall - left/right
  71.                         else if (e->type == 3) {
  72.                                 e->cropx = 320;
  73.                                 e->cropy = 80;
  74.                                 e->hsp = -1;
  75.                                 if (hsp > 0) {
  76.                                         e->hsp = 1;
  77.                                         e->cropx = 0;
  78.                                 }
  79.                                 e->imageSpeed = 0.33;
  80.                                 e->timer = 8 * (1 / e->imageSpeed);
  81.                         }
  82.                        
  83.                         //Block destroy/debris
  84.                         else if (e->type == 4) {
  85.                                 e->grav = 0.2;
  86.                                 e->loop = 1;
  87.                                 e->frames = 4;
  88.                                 e->timer = 60;
  89.                                
  90.                                 //Set flash offset
  91.                                 if ((e->hsp > 0 && val == 0) || (e->hsp > 0 && val == 1)) {
  92.                                         e->timer -= 1;
  93.                                 }
  94.                                
  95.                                 e->imageSpeed = 0.34;
  96.                                
  97.                                 int size = (rand() % 2) + 1;
  98.  
  99.                                 e->cropx = 0;
  100.                                 if (e->hsp < 0) {
  101.                                         e->cropx = 160;
  102.                                 }
  103.                                 if (size == 1) { //Big
  104.                                         e->cropy = 40;
  105.                                 }else{ //Small
  106.                                         e->cropy = 440;
  107.                                 }
  108.                                
  109.                         }
  110.                        
  111.                         //Chest sparkle
  112.                         else if (e->type == 5) {
  113.                                 /*e->x -= 20;
  114.                                 e->y -= 20;
  115.                                 e->x += -20 + (rand() % 40) + 1;
  116.                                 e->y += -20 + (rand() % 40) + 1;
  117.                                 */
  118.                                 e->x -= 20;
  119.                                 e->y -= 20;
  120.                                 e->cropx = 440;
  121.                                 e->cropy = 120;
  122.                                 e->imageSpeed = 0.3;
  123.                                 e->timer = 16;
  124.                                 e->depth = 0;
  125.                         }
  126.                        
  127.                         //Charge orbs
  128.                         else if (e->type == 6) {
  129.                                 e->x -= 20;
  130.                                 e->y -= 20;
  131.                                 e->cropx = 0;
  132.                                 e->cropy = 200;
  133.                                
  134.                                 e->val1 = (rand() % 360) + 1;
  135.                                 e->imageSpeed = 0.3;
  136.                                 e->timer = 20;
  137.                                 e->depth = 0;
  138.                         }
  139.                        
  140.                         //Poison bubble
  141.                         else if (e->type == 7) {
  142.                                 PHL_PlaySound(sounds[sndPi02], CHN_EFFECTS);
  143.                                 e->x -= 30;
  144.                                 e->x += (rand() % 20) + 1;
  145.                                 e->cropx = 280;
  146.                                 e->cropy = 120;
  147.                                 e->timer = 35;
  148.                                
  149.                                 e->vsp = -2;
  150.                                 e->imageIndex = 0;
  151.                                 e->imageSpeed = 0.16;
  152.                                 e->depth = 0;
  153.                         }
  154.                        
  155.                         //Stone break free
  156.                         else if (e->type == 8) {
  157.                                 e->image = imgMisc32;
  158.                                 e->cropy = 64;
  159.                                 e->width = 64;
  160.                                 e->height = 64;
  161.                                
  162.                                 e->imageSpeed = 0.32;
  163.                                 e->timer = 18;
  164.                         }
  165.                        
  166.                         //Tiny stone debris
  167.                         else if (e->type == 9) {
  168.                                 e->x -= 20;
  169.                                 e->y -= 20;
  170.                                 e->image = imgMisc20;
  171.                                 e->cropy = 40;
  172.                                 e->cropx = 320 + ((rand() % 3) * 40);
  173.                                 e->imageSpeed = 0;
  174.                                
  175.                                 e->vsp = -2 - (0.25 * (rand() % 8));
  176.                                 e->hsp = -1 + (0.25 * (rand() % 8));
  177.                                 e->grav = 0.1;
  178.                                
  179.                                 e->timer = 60;
  180.                                 e->depth = 0;
  181.                         }
  182.                        
  183.                         //Lava top animation
  184.                         else if (e->type == 10) {
  185.                                 e->cropy = 40;
  186.                                 e->cropx = 80;
  187.                                
  188.                                 e->imageSpeed = 0.125;
  189.                                 e->depth = -1;
  190.                                 e->loop = 1;
  191.                                 e->frames = 3;
  192.                                 e->timer = 100;
  193.                                
  194.                                 e->image = imgTiles;
  195.                         }
  196.                        
  197.                         //Water top animation
  198.                         else if (e->type == 11) {
  199.                                 e->cropy = 40;
  200.                                 e->cropx = 240;
  201.                                
  202.                                 e->imageSpeed = 0.125;
  203.                                 e->depth = -1;
  204.                                 e->loop = 1;
  205.                                 e->frames = 4;
  206.                                 e->timer = 100;
  207.                                
  208.                                 e->image = imgTiles;
  209.                         }
  210.                        
  211.                         //Hero Air Bubble
  212.                         else if (e->type == 12) {
  213.                                 e->x -= 20;
  214.                                 e->val1 = e->x; //Start x
  215.                                 e->y -= 20;
  216.                                 e->cropx = 440;
  217.                                 e->loop = 1;
  218.                                 e->frames = 2;
  219.                                 e->imageSpeed = 0.2;
  220.                                 e->timer = 120;
  221.                                 e->vsp = -0.5;
  222.                                 e->depth = 0;
  223.                         }
  224.                        
  225.                         //Water splash
  226.                         else if (e->type == 13) {
  227.                                 e->cropx = 200;
  228.                                 e->imageSpeed = 0.1;
  229.                                 e->timer = 55;
  230.                                 e->grav = 0.1;
  231.                         }
  232.                        
  233.                         //Lava splash
  234.                         else if (e->type == 14) {
  235.                                 e->cropx = 400;
  236.                                 e->cropy = 200;
  237.                                 e->imageSpeed = 0.1;
  238.                                 e->timer = 55;
  239.                                 e->grav = 0.1;
  240.                         }
  241.                        
  242.                         effects[i] = e;
  243.                         i = MAX_EFFECTS;
  244.                 }
  245.         }
  246. }
  247.  
  248. void effectStep(Effect* e)
  249. {
  250.         e->x += e->hsp;
  251.         e->y += e->vsp;
  252.         e->vsp += e->grav;
  253.         e->imageIndex += e->imageSpeed;
  254.        
  255.         if (e->loop == 1) {
  256.                 if (e->imageIndex >= e->frames) {
  257.                         e->imageIndex -= e->frames;
  258.                 }
  259.         }
  260.        
  261.         if (e->type == 12) { //Hero Air Bubble
  262.                 e->x = e->val1 + 5 * sin((e->timer * 5) * 3.14159 / 180);
  263.                 if (checkTileCollisionXY(4, e->x + 20, e->y + 20) == 0) {
  264.                         e->timer = 0;
  265.                 }
  266.         }
  267.        
  268.         if (e->type == 10 || e->type == 11) { //Lava top
  269.                 e->timer = 100;
  270.         }
  271.        
  272.         if (e->type == 4 || e->type == 9 || e->type == 12) { //Stone Rubble
  273.                 if (e->timer <= 30 && e->timer % 2 != 0) {
  274.                         e->visible = 0;
  275.                 }else{
  276.                         e->visible = 1;
  277.                 }
  278.         }
  279.         else if (e->type == 6) { //Charge orb
  280.                 if (e->timer % 2 == 0) {
  281.                         e->visible = 1;
  282.                         e->x = herox + ((e->timer * 3) * sin(e->val1 * 3.14159 / 180)) - 20;
  283.                         e->y = heroy + ((e->timer * 3) * cos(e->val1 * 3.14159 / 180));
  284.                 }else{
  285.                         e->visible = 0;
  286.                 }
  287.         }
  288.        
  289.         e->timer -= 1;
  290.         if (e->timer <= 0) {
  291.                 effectDestroy(e->id);
  292.         }
  293. }
  294.  
  295. void effectDraw(Effect* e)
  296. {      
  297.         //if (e->type != 4 || (e->timer > 30 || e->timer % 2 == 0)) {
  298.         if (e->visible == 1) {
  299.                 if (e->type == 7) { //Poison Bubble
  300.                         int animation[6] = {0, 1, 2, 1, 0, 3};
  301.                         PHL_DrawSurfacePart(e->x, e->y, e->cropx + (e->width * (animation[(int)e->imageIndex])), e->cropy, e->width, e->height, images[e->image]);
  302.                 }else{
  303.                         PHL_DrawSurfacePart(e->x, e->y, e->cropx + (e->width * ((int)e->imageIndex)), e->cropy, e->width, e->height, images[e->image]);
  304.                 }
  305.         }      
  306. }
  307.  
  308. void effectDestroy(int id)
  309. {      
  310.         if (effects[id] != NULL) {
  311.                 free(effects[id]);
  312.         }
  313.         effects[id] = NULL;
  314. }
  315.  
  316. void createRockSmash(int x, int y)
  317. {
  318.         x -= 20;
  319.  
  320.         int randvsp = (rand() % 3) + 1;
  321.         createEffectExtra(4, x, y, -1.5, -2 - randvsp, 0);
  322.        
  323.         randvsp = (rand() % 3) + 1;
  324.         createEffectExtra(4, x, y, -1, -5 - randvsp, 1);
  325.        
  326.         randvsp = (rand() % 3) + 1;
  327.         createEffectExtra(4, x, y, 1.5, -2 - randvsp, 0);
  328.        
  329.         randvsp = (rand() % 3) + 1;
  330.         createEffectExtra(4, x, y, 1, -5 - randvsp, 1);
  331.         PHL_PlaySound(sounds[sndBom02], 2);
  332. }
  333.  
  334. void createSplash(int x, int y)
  335. {
  336.         double chsp = 0,
  337.                    cvsp = 0;
  338.        
  339.         x -= 20;
  340.        
  341.         chsp = -0.25 - ((rand() % 9) * 0.25);
  342.         cvsp = -1.5 - ((rand() % 9) * 0.25);
  343.         createEffectExtra(13, x, y, chsp, cvsp, 0);
  344.        
  345.         chsp = 0.25 + ((rand() % 9) * 0.25);
  346.         cvsp = -1.5 - ((rand() % 9) * 0.25);
  347.         createEffectExtra(13, x, y, chsp, cvsp, 0);
  348.        
  349.         chsp = -0.25 - ((rand() % 9) * 0.25);
  350.         cvsp = -0.5 - ((rand() % 4) * 0.25);
  351.         createEffectExtra(13, x, y, chsp, cvsp, 0);
  352.        
  353.         chsp = 0.25 + ((rand() % 9) * 0.25);
  354.         cvsp = -0.5 - ((rand() % 4) * 0.25);
  355.         createEffectExtra(13, x, y, chsp, cvsp, 0);
  356.        
  357.         PHL_PlaySound(sounds[sndWater01], CHN_EFFECTS);
  358. }
  359.  
  360. void createLavaSplash(int x, int y)
  361. {
  362.         double chsp = 0,
  363.                    cvsp = 0;
  364.        
  365.         x -= 20;
  366.        
  367.         chsp = -0.25 - ((rand() % 9) * 0.25);
  368.         cvsp = -1.5 - ((rand() % 9) * 0.25);
  369.         createEffectExtra(14, x, y, chsp, cvsp, 0);
  370.        
  371.         chsp = 0.25 + ((rand() % 9) * 0.25);
  372.         cvsp = -1.5 - ((rand() % 9) * 0.25);
  373.         createEffectExtra(14, x, y, chsp, cvsp, 0);
  374.        
  375.         chsp = -0.25 - ((rand() % 9) * 0.25);
  376.         cvsp = -0.5 - ((rand() % 4) * 0.25);
  377.         createEffectExtra(14, x, y, chsp, cvsp, 0);
  378.        
  379.         chsp = 0.25 + ((rand() % 9) * 0.25);
  380.         cvsp = -0.5 - ((rand() % 4) * 0.25);
  381.         createEffectExtra(14, x, y, chsp, cvsp, 0);
  382.        
  383.         PHL_PlaySound(sounds[sndShot07], CHN_EFFECTS);
  384. }