Advertisement
TheBlueTophat

Scrolling Code Module 2

May 20th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.96 KB | None | 0 0
  1. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \\
  2. // Coolgamers Z3 Scrolling, Version 2 Update/Itteration 4 Module 2. \\
  3. // Module 2:                                                        \\
  4. // Link and Item related functions, variables, & constants.         \\
  5. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \\
  6.  
  7. // ~ Constants and Variables ~
  8.  
  9. // These are indices into the LinkStats Array.
  10.  
  11. // Link Stats Array. Use the LS_ constants as indices into this.
  12. float LinkStats[64];
  13.  
  14. // Link's current Action.
  15. const int LS_ACTION = 0;
  16. // The speed at which Link walks. This is measured in pixels per frame.
  17. const int LS_WALKSPEED = 1;
  18. // Link X, Y, and Z positions.
  19. // I'm not sure the purpose of this originally. Gonna keep it in for now though.
  20. const int LS_X = 2;
  21. const int LS_Y = 3;
  22. const int LS_Z = 4;
  23. // Link Hitbox X, Y, and Z positions.
  24. const int LS_HIT_X = 5;
  25. const int LS_HIT_Y = 6;
  26. const int LS_HIT_Z = 7;
  27. // Link Hitbox X, Y, and Z offsets.
  28. const int LS_HIT_X_OFFSET = 8;
  29. const int LS_HIT_Y_OFFSET = 9;
  30. const int LS_HIT_Z_OFFSET = 10;
  31. // Link Hitbox Width (x), Height (y), and Depth (z).
  32. const int LS_HIT_W = 11; // width
  33. const int LS_HIT_H = 12; // height
  34. const int LS_HIT_D = 13; // depth
  35. // Link Draw X and Y positions.
  36. const int LS_DRAW_X = 14;
  37. const int LS_DRAW_Y = 15;
  38. // Link Draw X and Y offsets.
  39. const int LS_DRAW_X_OFFSET = 16;
  40. const int LS_DRAW_Y_OFFSET = 17;
  41. // Link Draw Width and Height, in tiles.
  42. const int LS_DRAW_W = 18;
  43. const int LS_DRAW_H = 19;
  44. // The Opacity of Link. OP_OPAQUE makes Link Opaque, OP_TRANS makes Link Transparent, and OP_INVIS (or 0) makes Link Invisible.
  45. const int LS_OPACITY = 20;
  46. // The layer to draw Link to.
  47. const int LS_DRAWLAYER = 21;
  48.  
  49. // Start of Link's tilesheet.
  50. const int LS_ANIMATION_SHEET_START = 22;
  51. // The amount of frames that each animation frame lasts.
  52. // const int LS_ANIMATIONDELAY = 23;
  53. // Link's Animation Flip.
  54. const int LS_FLIP = 24;
  55. // If Link detects collisions with weapons.
  56. const int LS_WEPDETECT = 25;
  57. // If Link detects collisions with enemies.
  58. const int LS_ENEMYDETECT = 26;
  59. // If Link detects collisions with solid objects (ie. doesn't go into solid areas).
  60. const int LS_SOLIDETECT = 27;
  61. // If Links Animation Timer should be paused or not.
  62. const int LS_PAUSEANIMATIONTIMERS = 28;
  63. // Links' Direction.
  64. const int LS_DIR = 29;
  65. // Links' Angle.
  66. const int LS_ANGLE = 30;
  67. // Links' action in the previous frame.
  68. const int LS_PREVACTION = 31;
  69. // Link Animation Timer.
  70. const int LS_ANIMATIONTIMER = 32;
  71. // Link Action Timer.
  72. const int LS_ACTIONTIMER = 33;
  73. // Number of seperate frames used for Link's animation per Direction.
  74. const int LS_ANIMATIONFRAMES = 34;
  75. // Number of tiles between the end of Link action set of tiles and the start of the next one
  76. // (This is factored into the sets of tiles for normal directions and diagonal directions).
  77. const int LS_DIR_OR_ACTION_END_TILEDIST = 35;// may be renamed.
  78.  
  79. // If Links Action Timer should be paused or not.
  80. const int LS_PAUSEACTIONTIMERS = 36;
  81.  
  82. // The amount of frames that each frame of Links current Action lasts.
  83. int LS_ANIMATIONDELAY[32]; // The array needs populated with the function SetLinkActionFrameDelays()
  84.  
  85. // ~ Scrolling engine Link Actions ~
  86. // No action. This would be used for something such as a cutscene.
  87. const int SCRL_LA_NONE = -1;
  88. // When link is standing still.
  89. const int SCRL_LA_STAND = 0;
  90. // When link is walking.
  91. const int SCRL_LA_WALK = 1;
  92. // When link is slashing with something.
  93. const int SCRL_LA_SLASH = 2;
  94. // When link is stabbing with something.
  95. const int SCRL_LA_STAB = 3;
  96. // When link is pounding with something.
  97. const int SCRL_LA_POUND = 4;
  98. // When link is in the air.
  99. const int SCRL_LA_JUMP = 5;
  100. // When link is charging a weapon.
  101. const int SCRL_LA_CHARGE = 6;
  102. // When link is holding an item up, 1 hand, on land.
  103. const int SCRL_LA_HOLD1LAND = 7;
  104. // When link is holding an item up, 2 hands, on land.
  105. const int SCRL_LA_HOLD2LAND = 8;
  106. // When link is casting a spell (eg. dins fire).
  107. const int SCRL_LA_CAST = 9;
  108. // When link is frozen, on land.
  109. const int SCRL_LA_FROZELAND = 10;
  110. // When link is hurt, on land.
  111. const int SCRL_LA_HURTLAND = 11;
  112. // When link is dying, on land.
  113. const int SCRL_LA_DIELAND = 12;
  114. // When link is floating still (in water).
  115. const int SCRL_LA_FLOATWATER = 13;
  116. // When link is swimming.
  117. const int SCRL_LA_SWIM = 14;
  118. // When link is diving.
  119. const int SCRL_LA_DIVE = 15;
  120. // When link is holding an item up, 1 hand, in water.
  121. const int SCRL_LA_HOLD1WATER = 16;
  122. // When link is holding an item up, 2 hands, in water.
  123. const int SCRL_LA_HOLD2WATER = 17;
  124. // When link is drowning.
  125. const int SCRL_LA_DROWN = 18;
  126. // When link is frozen, in water.
  127. const int SCRL_LA_FROZEWATER = 19;
  128. // When link is hurt, in water.
  129. const int SCRL_LA_HURTWATER = 20;
  130. // When link is dying, in water.
  131. const int SCRL_LA_DIEWATER = 21;
  132. // When link is falling.
  133. const int SCRL_LA_FALL = 22;
  134.  
  135. // ~ Link Action Animation Timer(s) ~
  136. float LinkAnimationTimer[32]; // Depreciated. This needs to be removed.
  137.  
  138. // ~ Scripted Item Classes ~
  139. // A list of flags in one of the ->InitD[] registers will be used to determine the exact behavior of these weapons.
  140. const int SCRL_IC_NONE = 89; // The first zz### item class.
  141. const int SCRL_IC_TESTWEP = 90;
  142.  
  143. // ~ Scripted Item Options ~
  144. const int SCRL_INITD_FLAGSET = 0; // The ->InitD register to use for flags.
  145. const int SCRL_INITD_SCRIPT_FLAGSET = 1; // The ->InitD register to use for some other flags.
  146. const int SCRL_INITD_SPRITE = 2; // Sprite of the weapon.
  147.  
  148.  
  149. // ~ Functions ~
  150.  
  151. // Populates the LS_ANIMATIONDELAY array.
  152. void SetLinkActionFrameDelays()
  153. {
  154.     LS_ANIMATIONDELAY[SCRL_LA_STAND] = 8;
  155.     LS_ANIMATIONDELAY[SCRL_LA_WALK] = 8;
  156.     LS_ANIMATIONDELAY[SCRL_LA_SLASH] = 8;
  157.     // need to set up the code here.
  158. }
  159.  
  160. void HandleLinkItems()
  161. {
  162.     if(LinkStats[LS_ACTION] == SCRL_LA_STAND || LinkStats[LS_ACTION] == SCRL_LA_WALK)
  163.     {
  164.         if(Link->InputA)
  165.         {
  166.             itemdata itID = Game->LoadItemData(GetEquipmentA());
  167.            
  168.             if(itID->Family == SCRL_LW_TESTWEP)
  169.             {
  170.                 //CreateCustomWeapon(SCRL_LW_GENERALW, itID->InitD[SCRL_INITD_FLAGSET], itID->InitD[SCRL_INITD_SPRITE], FrontOfLinkX(), FrontOfLinkY()); // The function needs implemented, in the custom weapon Module.
  171.                
  172.                
  173.             }
  174.         }
  175.        
  176.         if(Link->InputB)
  177.         {
  178.             itemdata itID = Game->LoadItemData(GetEquipmentB());
  179.         }
  180.     }
  181. }
  182.  
  183. // button: -1 to only check if Link's action is Stand or Walk, 0 for A, 1 for B. Other buttons may be added in the future.
  184. bool CanUseItem(int button)
  185. {
  186.     if(LinkStats[LS_ACTION] == SCRL_LA_STAND || LinkStats[LS_ACTION] == SCRL_LA_WALK)
  187.     {
  188.         if(button == -1)
  189.         {
  190.             return true;
  191.         }
  192.        
  193.         if(button == 0)
  194.         {
  195.             if(Link->InputA == false)
  196.             {
  197.                 return true;
  198.             }
  199.         }
  200.        
  201.         if(button == 1)
  202.         {
  203.             if(Link->InputB == false)
  204.             {
  205.                 return true;
  206.             }
  207.         }
  208.     }
  209.    
  210.     return false;
  211. }
  212.  
  213. // Draws Link and any equipment he may have.
  214. void DrawLink()
  215. {  
  216.     int LinkAnimationTile;
  217.     int LinkDirAnimationOffset;
  218.    
  219.     if(LinkStats[LS_ACTION] == SCRL_LA_STAND        || LinkStats[LS_ACTION] == SCRL_LA_WALK
  220.     || LinkStats[LS_ACTION] == SCRL_LA_FLOATWATER   || LinkStats[LS_ACTION] == SCRL_LA_SWIM)
  221.     {
  222.         if(Link->InputUp && Link->InputDown == false && Link->InputLeft == false && Link->InputRight == false)   {LinkStats[LS_DIR] = DIR_UP;}
  223.         if(Link->InputDown && Link->InputUp == false && Link->InputLeft == false && Link->InputRight == false)   {LinkStats[LS_DIR] = DIR_DOWN;}
  224.         if(Link->InputLeft && Link->InputDown == false && Link->InputUp == false && Link->InputRight == false)   {LinkStats[LS_DIR] = DIR_LEFT;}
  225.         if(Link->InputRight && Link->InputUp == false && Link->InputLeft == false && Link->InputUp == false)     {LinkStats[LS_DIR] = DIR_RIGHT;}
  226.        
  227.         if(Link->InputUp && Link->InputDown == false && Link->InputLeft && Link->InputRight == false)    {LinkStats[LS_DIR] = DIR_LEFTUP;}
  228.         if(Link->InputUp && Link->InputDown == false && Link->InputLeft == false && Link->InputRight)    {LinkStats[LS_DIR] = DIR_RIGHTUP;}
  229.         if(Link->InputDown && Link->InputUp == false && Link->InputLeft && Link->InputRight == false)    {LinkStats[LS_DIR] = DIR_LEFTDOWN;}
  230.         if(Link->InputDown && Link->InputUp == false && Link->InputLeft == false && Link->InputRight)    {LinkStats[LS_DIR] = DIR_RIGHTDOWN;}
  231.     }
  232.    
  233.     // If Links' dir is DIR_UP/DIR_DOWN/DIR_LEFT/DIR_RIGHT.
  234.     if(LinkStats[LS_DIR] <= 3)
  235.     {
  236.         LinkDirAnimationOffset = (LinkStats[LS_ANIMATIONFRAMES] * LinkStats[LS_DIR]);
  237.     }
  238.    
  239.     // If Links' dir is DIR_LEFTUP/DIR_LEFTDOWN/DIR_RIGHTUP/DIR_RIGHTDOWN.
  240.     if(LinkStats[LS_DIR] >= 4)
  241.     {
  242.         LinkDirAnimationOffset = (LinkStats[LS_ANIMATIONFRAMES] * LinkStats[LS_DIR]) + LinkStats[LS_DIR_OR_ACTION_END_TILEDIST];
  243.     }
  244.    
  245.     LinkAnimationTile =     LinkStats[LS_ANIMATION_SHEET_START]
  246.                         +   ((((LinkStats[LS_ANIMATIONFRAMES] * 4) + LinkStats[LS_DIR_OR_ACTION_END_TILEDIST]) * LinkStats[LS_ACTION]) * 2)
  247.                         +   CurLinkAnimationFrame()
  248.                         +   LinkDirAnimationOffset;
  249.    
  250.     if(LinkStats[LS_OPACITY] != OP_INVIS)
  251.     {
  252.         if(LinkStats[LS_ACTION] > SCRL_LA_NONE)      
  253.         {
  254.             // You'd want to put any equipment drawing code that goes BEHIND Link here.
  255.            
  256.             Screen->FastTile(LinkStats[LS_DRAWLAYER], LinkStats[LS_DRAW_X] + LinkStats[LS_DRAW_X_OFFSET], LinkStats[LS_DRAW_Y] + LinkStats[LS_DRAW_Y_OFFSET], LinkAnimationTile, 6, LinkStats[LS_OPACITY]);
  257.        
  258.             // You'd want to put any equipment drawing code that goes INFRONT of Link here.
  259.         }
  260.     }
  261. }
  262.  
  263. // This isn't Link's animation tile, this is just the current frame the animation is at.
  264. int CurLinkAnimationFrame()
  265. {
  266.     return Floor(LinkStats[LS_ANIMATIONTIMER] / LS_ANIMATIONDELAY[LinkStats[LS_ACTION]]);
  267. }
  268.  
  269. // Handles items (such as swords).
  270. void HandleItems()
  271. {
  272.     // example how to handle an item and create a weapon for it
  273.     if(LinkStats[LS_ANIMATIONTIMER] == 0)
  274.     {
  275.         if(LinkStats[LS_ACTION] == SCRL_LA_SLASH)
  276.         {
  277.             // ...
  278.         }
  279.     }
  280. }
  281.  
  282. // Does things based on Links' action.
  283. void HandleLinkActions()
  284. {
  285.     if(LinkStats[LS_ACTION] == SCRL_LA_STAND && (Link->InputUp || Link->InputDown || Link->InputLeft || Link->InputRight))
  286.     {
  287.         LinkStats[LS_ACTION] = SCRL_LA_WALK;
  288.     }
  289.    
  290.     if(LinkStats[LS_ACTION] == SCRL_LA_WALK && Link->InputUp == false && Link->InputDown == false && Link->InputLeft == false && Link->InputRight == false)
  291.     {
  292.         LinkStats[LS_ACTION] = SCRL_LA_STAND;
  293.     }
  294.    
  295.     if(LinkStats[LS_ACTION] == SCRL_LA_SLASH && LinkStats[LS_ANIMATIONTIMER] >= ((4 * LS_ANIMATIONDELAY[LinkStats[LS_ACTION]]) -1))
  296.     {
  297.         LinkStats[LS_ACTION] = SCRL_LA_STAND;
  298.     }
  299. }
  300.  
  301. // Handles Links' Animation timers.
  302. void HandleLinkAnimationTimer()
  303. {
  304.     if(LinkStats[LS_PAUSEANIMATIONTIMERS] == 0)
  305.     {  
  306.         LinkStats[LS_ANIMATIONTIMER] += 1;
  307.  
  308.         if(LinkStats[LS_ANIMATIONTIMER] >= (LinkStats[LS_ANIMATIONFRAMES] * LS_ANIMATIONDELAY[LinkStats[LS_ACTION]]))
  309.         {
  310.             LinkStats[LS_ANIMATIONTIMER] = 0;
  311.         }
  312.        
  313.         if(LinkStats[LS_ACTION] != LinkStats[LS_PREVACTION])
  314.         {
  315.             LinkStats[LS_ANIMATIONTIMER] = 0;
  316.         }
  317.        
  318.         LinkStats[LS_PREVACTION] = LinkStats[LS_ACTION];
  319.     }
  320. }
  321.  
  322. void HandleLink()
  323. {
  324.     HandleItems();
  325.     HandleLinkActions();
  326.     HandleLinkAnimationTimer();
  327.     DrawLink();
  328. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement