Advertisement
Guest User

Calleoca code

a guest
Oct 4th, 2014
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.25 KB | None | 0 0
  1. #include <vector>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include "LevelCodes.h"
  5. #include "PlayerMOB.h"
  6. #include "Globals.h"
  7. #include "NPCs.h"
  8.  
  9. #define PI 3.1415926535897932384626433832795
  10.  
  11. #define NPC_SIGN 151
  12. #define NPC_COIN 10
  13. #define NPC_FIREBAR 260
  14. #define NPC_GOAL 16
  15.  
  16. #define OFFSCREEN_DIST 400
  17. #define MIDPOINT_X -194620
  18. #define END_X -188792
  19.  
  20. using namespace std;
  21.  
  22. NPCMOB* FindNPC(short identity);
  23. void HurtPlayer();
  24. bool TriggerBox(double x1, double y1, double x2, double y2);
  25. int AngleDifference(int angle1, int angle2);
  26.  
  27. bool init_doonce;
  28.  
  29. PlayerMOB* demo;
  30.  
  31. NPCMOB* calleoca_npc1 = NULL;
  32. NPCMOB* calleoca_npc2 = NULL;
  33. NPCMOB* hurt_npc = NULL;
  34. NPCMOB* goal_npc = NULL;
  35.  
  36. int win_timer;
  37. int freeze_timer = 0;
  38. int phase = 0;
  39. double calleoca_x, calleoca_y, storage_x, storage_y;
  40.  
  41. double thwomp_hspeed = 0;
  42. double thwomp_vspeed = 0;
  43. double thwomp_height, thwomp_bottom;
  44.  
  45. double missile_direction = 0;
  46. double missile_hspeed = 0;
  47. double missile_vspeed = 0;
  48. double missile_top, missile_bottom;
  49. int missile_fuel = 0;
  50.  
  51. double fishingboo_hspeed = 0;
  52. double fishingboo_vspeed = 0;
  53. double fishingboo_ferocity = 1;
  54.  
  55. template <typename T> T Clamp(const T& value, const T& low, const T& high)
  56. {
  57.   return value < low ? low : (value > high ? high : value);
  58. }
  59.  
  60. void CalleocaInitCode()
  61. {
  62.     init_doonce = false;
  63.  
  64.     phase = 0;
  65.  
  66.     win_timer = 100;
  67.  
  68.     thwomp_hspeed = 0;
  69.     thwomp_vspeed = 0;
  70.  
  71.     freeze_timer = 0;
  72.  
  73.     missile_direction = 0;
  74.     missile_hspeed = 0;
  75.     missile_vspeed = 0;
  76.  
  77.     fishingboo_hspeed = 0;
  78.     fishingboo_vspeed = 0;
  79.     fishingboo_ferocity = 1;
  80. }
  81.  
  82. void Phase0()
  83. {
  84.     calleoca_npc1->AnimationFrame = 0;
  85.  
  86.     if (demo->CurXPos > calleoca_x + 128)
  87.     {
  88.         freeze_timer = 45;
  89.         phase = 1;
  90.     }
  91.  
  92.     if (demo->CurXPos >= MIDPOINT_X)
  93.     {
  94.         phase = 3;
  95.         calleoca_x = MIDPOINT_X - 256;
  96.         calleoca_y -= 256;
  97.     }
  98. }
  99.  
  100. /*************************************************************************************************/
  101. //Standing there
  102. void Phase1()
  103. {
  104.     thwomp_hspeed += (demo->CurXPos - calleoca_x) * 0.001;
  105.     if (abs(thwomp_height - calleoca_y) < 8)
  106.     {
  107.         thwomp_hspeed = Clamp<double>(thwomp_hspeed, -9, 9);
  108.  
  109.         if (TriggerBox(calleoca_x, calleoca_y + 64, calleoca_x + 64, calleoca_y + 512))
  110.             phase = 2;
  111.     }
  112.     else
  113.         thwomp_hspeed = 0;
  114.  
  115.     thwomp_vspeed = (thwomp_height - calleoca_y) * 0.1;
  116.     thwomp_vspeed = Clamp<double>(thwomp_vspeed, -6.0, 6.0);
  117.  
  118.     if (freeze_timer > 0)
  119.     {
  120.         thwomp_vspeed = 0;
  121.         freeze_timer--;
  122.     }
  123.        
  124.  
  125.     calleoca_x += thwomp_hspeed;
  126.     calleoca_y += thwomp_vspeed;
  127.  
  128.     calleoca_npc1->AnimationFrame = 2;
  129.     if (TriggerBox(calleoca_x + 10, calleoca_y + 0, calleoca_x + 54, calleoca_y + 64))
  130.         HurtPlayer();
  131.  
  132.     if (demo->CurXPos >= MIDPOINT_X)
  133.     {
  134.         freeze_timer = 150;
  135.         phase = 3;
  136.     }
  137. }
  138.  
  139. /*************************************************************************************************/
  140. //Thwomp rising / moving
  141. void Phase2()
  142. {
  143.     thwomp_hspeed *= 0.9;
  144.     if (demo->CurYPos <= calleoca_y)
  145.         thwomp_hspeed *= 0.9;
  146.  
  147.     thwomp_vspeed += (thwomp_bottom - calleoca_y) * 0.05;
  148.     thwomp_vspeed = Clamp<double>(thwomp_vspeed, -8.0, 8.0);
  149.    
  150.     calleoca_x += thwomp_hspeed;
  151.     calleoca_y += thwomp_vspeed;
  152.     calleoca_npc1->AnimationFrame = 1;
  153.     if (TriggerBox(calleoca_x + 10, calleoca_y + 0, calleoca_x + 54, calleoca_y + 64))
  154.         HurtPlayer();
  155.  
  156.     if (calleoca_y >= thwomp_bottom)
  157.     {
  158.         freeze_timer = 22;
  159.         phase = 1;
  160.     }
  161.  
  162.     if (demo->CurXPos >= MIDPOINT_X)
  163.     {
  164.         freeze_timer = 150;
  165.         phase = 3;
  166.     }
  167. }
  168.  
  169. /*************************************************************************************************/
  170. //Missile
  171. void Phase3()
  172. {
  173.     calleoca_npc1->AnimationFrame = 3 + int(0.5 + missile_direction / 45) % 8;
  174.  
  175.     int dir = (int) (atan2( (demo->CurYPos + demo->Height / 2) - (calleoca_y + 32),
  176.                            -(demo->CurXPos + demo->Width  / 2) + (calleoca_x + 32))
  177.                      * 180 / PI);
  178.  
  179.     missile_direction += AngleDifference((int)missile_direction, dir) * 0.015;
  180.  
  181.     if (missile_direction >= 360)
  182.         missile_direction -= 360;
  183.     else
  184.     if (missile_direction < 0)
  185.         missile_direction += 360;
  186.  
  187.     missile_hspeed += cos(missile_direction * PI / 180) * 0.25;
  188.     missile_vspeed -= sin(missile_direction * PI / 180) * 0.25;
  189.  
  190.     missile_hspeed = Clamp<double>(missile_hspeed * 0.975, -15, 15);
  191.     missile_vspeed = Clamp<double>(missile_vspeed * 0.975, -15, 15);
  192.  
  193.     if (freeze_timer > 0)
  194.     {
  195.         freeze_timer--;
  196.         missile_hspeed = 0;
  197.         missile_vspeed = 0;
  198.         missile_fuel = 600;
  199.     }
  200.     else
  201.     {
  202.         missile_fuel--;
  203.         if (missile_fuel <= 0)
  204.             if (!TriggerBox(calleoca_x - 100, calleoca_y - 100, calleoca_x + 164, calleoca_y + 164))
  205.                 freeze_timer = 110;
  206.     }
  207.  
  208.    
  209.     calleoca_x = Clamp<double>(calleoca_x + missile_hspeed, demo->CurXPos - 464, demo->CurXPos + 464);
  210.     calleoca_y = Clamp<double>(calleoca_y + missile_vspeed, missile_top, missile_bottom);
  211.  
  212.     if (TriggerBox(calleoca_x + 18, calleoca_y + 18, calleoca_x + 46, calleoca_y + 46))
  213.         HurtPlayer();
  214.  
  215.     if (demo->CurXPos >= END_X)
  216.     {
  217.         if (calleoca_x > END_X - 64)
  218.             calleoca_x = END_X - 64;
  219.         freeze_timer = 150;
  220.         phase = 4;
  221.     }
  222. }
  223.  
  224. void Phase4()
  225. {
  226.     if (freeze_timer > 0)
  227.     {
  228.         freeze_timer--;
  229.     }
  230.     else
  231.     {
  232.         fishingboo_hspeed += (demo->CurXPos - calleoca_x) * 0.001 * fishingboo_ferocity;
  233.         fishingboo_vspeed += (demo->CurYPos - calleoca_y) * 0.001 * fishingboo_ferocity;
  234.         fishingboo_hspeed = Clamp<double>(fishingboo_hspeed, -7 * fishingboo_ferocity, 7 * fishingboo_ferocity);
  235.         fishingboo_vspeed = Clamp<double>(fishingboo_vspeed, -0.5 * fishingboo_ferocity, 0.5 * fishingboo_ferocity);
  236.  
  237.         calleoca_x += fishingboo_hspeed;
  238.         calleoca_y += fishingboo_vspeed;
  239.  
  240.         fishingboo_ferocity += 0.0002;
  241.     }
  242.  
  243.     calleoca_x = Clamp<double>(calleoca_x, demo->CurXPos - 512, demo->CurXPos + 464);
  244. }
  245.  
  246. void CalleocaCode()
  247. {
  248.     demo = Player::Get(1);
  249.    
  250.     demo->Identity = 1;
  251.  
  252.     if (calleoca_npc2 == NULL && init_doonce)
  253.     {
  254.         if (win_timer > 0)
  255.             win_timer--;
  256.         else
  257.         {
  258.             goal_npc = FindNPC(NPC_GOAL);
  259.             if (goal_npc != NULL)
  260.             {
  261.                 goal_npc->Xpos = demo->CurXPos;
  262.                 goal_npc->Ypos = demo->CurYPos;
  263.             }
  264.         }
  265.        
  266.         return; //boss beaten
  267.     }
  268.    
  269.     if (!init_doonce)
  270.     {
  271.         calleoca_npc1 = FindNPC(NPC_SIGN);
  272.         calleoca_npc2 = FindNPC(NPC_COIN);
  273.         hurt_npc      = FindNPC(NPC_FIREBAR);
  274.  
  275.         calleoca_x = calleoca_npc1->Xpos;
  276.         calleoca_y = calleoca_npc1->Ypos;
  277.         storage_x  = calleoca_npc2->Xpos;
  278.         storage_y  = calleoca_npc2->Ypos;
  279.  
  280.         thwomp_height = calleoca_y - 64 * 6 + 16;
  281.         thwomp_bottom = calleoca_y + 128;
  282.  
  283.         missile_top = calleoca_y - 64 * 7 - 16;
  284.         missile_bottom = calleoca_y + 180;
  285.  
  286.         init_doonce = true;
  287.     }
  288.  
  289.     if (calleoca_npc1->Identity != NPC_SIGN)
  290.         calleoca_npc1 = FindNPC(NPC_SIGN);
  291.  
  292.     if (calleoca_npc2->Identity != NPC_COIN)
  293.         calleoca_npc2 = FindNPC(NPC_COIN);
  294.  
  295.     if (hurt_npc->Identity != NPC_FIREBAR)
  296.         hurt_npc = FindNPC(NPC_FIREBAR);
  297.  
  298.     hurt_npc->Xpos = demo->CurXPos;
  299.     hurt_npc->Ypos = demo->CurYPos - 128;
  300.  
  301.     switch (phase)
  302.     {
  303.         case 0: //Standing there
  304.             Phase0();
  305.         break;
  306.  
  307.         case 1: //Thwomp rising
  308.             Phase1();
  309.         break;
  310.  
  311.         case 2: //Thwomp attacking
  312.             Phase2();
  313.         break;
  314.  
  315.         case 3: //Missile
  316.             Phase3();
  317.         break;
  318.  
  319.         case 4: //Fishing Boo
  320.             Phase4();
  321.         break;
  322.     }
  323.  
  324.     if (calleoca_npc2 == NULL)
  325.         return; //boss beaten
  326.  
  327.     if (phase < 4)
  328.     {
  329.         calleoca_npc1->Xpos = calleoca_x;
  330.         calleoca_npc1->Ypos = calleoca_y;
  331.         calleoca_npc2->Xpos = storage_x;
  332.         calleoca_npc2->Ypos = storage_y;
  333.     }
  334.     else
  335.     {
  336.         calleoca_npc2->Xpos = calleoca_x;
  337.         calleoca_npc2->Ypos = calleoca_y;
  338.         calleoca_npc1->Xpos = storage_x;
  339.         calleoca_npc1->Ypos = storage_y;
  340.     }
  341.  
  342.     //gLunaRender.SafePrint(std::wstring(L"FUEL: " + std::to_wstring(missile_fuel)), 3, 0, 256);
  343.     //gLunaRender.SafePrint(std::wstring(L"DEMO X: " + std::to_wstring(demo->CurYPos)), 3, 0, 256 + 32);
  344. }
  345.  
  346. NPCMOB* FindNPC(short identity)
  347. {
  348.     NPCMOB* currentnpc = NULL;
  349.  
  350.     for(int i = 0; i < GM_NPCS_COUNT; i++)
  351.     {
  352.         currentnpc = NPC::Get(i);
  353.         if (currentnpc->Identity == identity)
  354.             return currentnpc;
  355.     }
  356.  
  357.     return NULL;
  358. }
  359.  
  360. bool TriggerBox(double x1, double y1, double x2, double y2)
  361. {
  362.     return (demo->CurXPos + demo->Width     > x1 &&
  363.             demo->CurXPos                   < x2 &&
  364.             demo->CurYPos + demo->Height    > y1 &&
  365.             demo->CurYPos                   < y2);
  366. }
  367.  
  368. void HurtPlayer()
  369. {
  370.     hurt_npc->Ypos = demo->CurYPos;
  371. }
  372.  
  373. int AngleDifference(int angle1, int angle2)
  374. {
  375.     return ((((angle1 - angle2) % 360) + 540) % 360) - 180;
  376. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement