Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.89 KB | None | 0 0
  1. //Section 1. Global Scripts.
  2.  
  3. global script Init{
  4. void run(){
  5. Game->Counter[HEALTH_COUNTER] = 99;
  6. //One tank is "invisible"
  7. //This is how the original worked
  8. //All calculations take this into accout.
  9. SamusVars[NUM_TANKS]=1;
  10. SamusVars[CURR_FILLED_TANKS]= 1;
  11. }
  12. }
  13.  
  14. global script globalscript{
  15. void run(){
  16. int PrevTanks = SamusVars[NUM_TANKS];//Initialize variable to track tanks between frames.
  17. Link->HP = Link->MaxHP;
  18. SamusVars[LINK_PREV_HP] = Link->HP;//Initialize variable.
  19. while(true){
  20. //Not having a game over.
  21. if(Link->HP>=2){
  22. //Run energy tanks.
  23. health();
  24. DrawETanks();
  25. }
  26. //You have more tanks than you did last frame.
  27. if(SamusVars[NUM_TANKS]>PrevTanks){
  28. PrevTanks = SamusVars[NUM_TANKS];//Set variable to new value.
  29. //Max health counter.
  30. Game->Counter[HEALTH_COUNTER] = 99;
  31. SamusVars[CURR_FILLED_TANKS]= SamusVars[NUM_TANKS];//Match variable amount.
  32. item TradeSeqItem;
  33. //Create the item and place it at Link's location.
  34. TradeSeqItem = Screen->CreateItem(I_MAGICCONTAINER);
  35. TradeSeqItem->X = Link->X;
  36. TradeSeqItem->Y = Link->Y;
  37. TradeSeqItem->Pickup |= IP_HOLDUP;
  38. }
  39. Waitdraw();
  40. Waitframe();
  41. }
  42. }
  43. }
  44.  
  45. //Make sure you have HP when you die and restart.
  46.  
  47. global script OnContinue{
  48. void run(){
  49. Game->Counter[HEALTH_COUNTER] = 99;
  50. SamusVars[CURR_FILLED_TANKS]= SamusVars[NUM_TANKS];
  51. Link->HP = Link->MaxHP;
  52. }
  53. }
  54.  
  55. //General Use Array and Indices
  56.  
  57. const int INJURED_TIMER = 5;// Timer for playing injured SFX.
  58. const int NUM_TANKS = 21;//Current total energy tanks.
  59. const int CURR_FILLED_TANKS = 22;//Current filled energy tanks.
  60. const int NUM_RES_TANKS = 23;//Current total reserve tanks.
  61. const int NUM_FILLED_RES_TANKS = 24;//Current filled reserve tanks.
  62. const int LINK_PREV_HP = 25;//Tracks Link's HP between frames.
  63.  
  64. int SamusVars[1024];//Array for variable storage.
  65.  
  66. //D0- Blank so other scripts can use it.
  67. //D1- Amount this item heals.
  68.  
  69. item script Healing_Item{
  70. void run(int dummy, int amount){
  71. //If difference in counter and amount is more than 99, raise HP.
  72. if((Game->Counter[HEALTH_COUNTER] + amount)>99
  73. && SamusVars[CURR_FILLED_TANKS]<SamusVars[NUM_TANKS]){
  74. Game->Counter[HEALTH_COUNTER]-=100;
  75. Game->Counter[HEALTH_COUNTER]+=amount;
  76. SamusVars[CURR_FILLED_TANKS]++;
  77. }
  78. else if(SamusVars[NUM_RES_TANKS]>0){
  79. if(SamusVars[NUM_FILLED_RES_TANKS]<SamusVars[NUM_RES_TANKS]){
  80. if((Game->Counter[RESERVE_COUNTER] + amount)>100
  81. && (SamusVars[NUM_FILLED_RES_TANKS]+1)<SamusVars[NUM_RES_TANKS]){
  82. Game->Counter[RESERVE_COUNTER]+=amount;
  83. SamusVars[NUM_FILLED_RES_TANKS]++;
  84. }
  85. else{
  86. if((Game->Counter[RESERVE_COUNTER] + amount)>100){
  87. Game->Counter[RESERVE_COUNTER]= 100*SamusVars[NUM_RES_TANKS];
  88. SamusVars[NUM_FILLED_RES_TANKS]= SamusVars[NUM_RES_TANKS];
  89. }
  90. else
  91. Game->Counter[RESERVE_COUNTER]+=amount;
  92. }
  93. }
  94. else{
  95. Game->Counter[RESERVE_COUNTER]= 100*SamusVars[NUM_RES_TANKS];
  96. SamusVars[NUM_FILLED_RES_TANKS]= SamusVars[NUM_RES_TANKS];
  97. }
  98. Game->Counter[HEALTH_COUNTER]= 99;
  99. }
  100. else if((Game->Counter[HEALTH_COUNTER] + amount)>99
  101. && SamusVars[CURR_FILLED_TANKS]==SamusVars[NUM_TANKS])
  102. Game->Counter[HEALTH_COUNTER]= 99;
  103. else
  104. Game->Counter[HEALTH_COUNTER]+=amount;
  105. }
  106. }
  107.  
  108. int HEALTH_COUNTER = CR_SCRIPT2;//Counter for energy tanks.
  109.  
  110. //When you get this item, current number of tanks is increased.
  111.  
  112. item script Energy_Tank{
  113. void run(){
  114. SamusVars[NUM_TANKS]++;
  115. //Superfluous, unless your quest will keep track of total items obtained.
  116. Game->Counter[SECRET_COUNTER] ++;
  117. }
  118. }
  119.  
  120. //When you get this item, current number of reserve tanks is increased.
  121.  
  122. int RESERVE_COUNTER = CR_SCRIPT3;//Counter for reserve tanks.
  123.  
  124. item script Reserve_Tank{
  125. void run(int message){
  126. SamusVars[NUM_RES_TANKS]++;
  127. SamusVars[NUM_FILLED_RES_TANKS]++;
  128. Screen->Message(message);
  129. Game->Counter[SECRET_COUNTER]++;
  130. Game->Counter[RESERVE_COUNTER]+=100;
  131. }
  132. }
  133.  
  134. //Constants for drawing Energy Tanks.
  135.  
  136. const int TILE_ETANK = 1460;
  137. const int DRAW_ETANK_TILE = 1460;
  138. const int DRAW_ETANK_X = 168;
  139. const int DRAW_ETANK_Y = -26;
  140. const float DRAW_ETANK_SCALE = 12;
  141. const int DRAW_ETANK_CSET = 1;
  142. const int DRAW_ETANK_X_SPACING = 14;
  143. const int DRAW_ETANK_Y_SPACING = 14;
  144.  
  145. void DrawETanks(){
  146. int x2 = DRAW_ETANK_X;
  147. int y2 = DRAW_ETANK_Y;
  148. for ( int q = 1; q <= (SamusVars[CURR_FILLED_TANKS]-1); q++ ) {
  149. Screen->DrawTile(7, x2, y2, DRAW_ETANK_TILE, 1, 1, DRAW_ETANK_CSET, DRAW_ETANK_SCALE, DRAW_ETANK_SCALE, 0, 0, 0, 0, true, 128);
  150. x2 += DRAW_ETANK_X_SPACING;
  151. if ( q % 8 == 0 ) {
  152. y2 -= DRAW_ETANK_Y_SPACING;
  153. x2 = DRAW_ETANK_X;
  154. }
  155. }
  156. }
  157.  
  158. //Handles HP.
  159.  
  160. void health(){
  161. int damage;//Change in health this frame.
  162. //Your HP has changed.
  163. if(Link->HP !=SamusVars[LINK_PREV_HP]){
  164. //HP has decreased.
  165. if(Link->HP<SamusVars[LINK_PREV_HP]){
  166. //Calculate amount of decrease.
  167. damage = SamusVars[LINK_PREV_HP] - Link->HP;
  168. //If difference in counter and amount is less than zero, lower HP.
  169. int tanks_used = Ceiling(damage/ 100);
  170. if((Game->Counter[HEALTH_COUNTER] - damage) < 0
  171. && SamusVars[CURR_FILLED_TANKS] > 1
  172. && (SamusVars[CURR_FILLED_TANKS]-tanks_used)>=1){
  173. Game->Counter[HEALTH_COUNTER] += 100*tanks_used;
  174. Game->Counter[HEALTH_COUNTER] -= damage;
  175. SamusVars[CURR_FILLED_TANKS]-=tanks_used;
  176. }
  177. else if((Game->Counter[HEALTH_COUNTER] - damage) < 0
  178. && SamusVars[CURR_FILLED_TANKS] > 1
  179. && (SamusVars[CURR_FILLED_TANKS]-tanks_used)<1){
  180. //Reserve tank code.
  181. if(Game->Counter[RESERVE_COUNTER]>0){
  182. SamusVars[CURR_FILLED_TANKS] = (SamusVars[NUM_FILLED_RES_TANKS]-1);
  183. Game->Counter[RESERVE_COUNTER]-=((SamusVars[NUM_FILLED_RES_TANKS]-1) * 100);
  184. SamusVars[NUM_FILLED_RES_TANKS]= 1;
  185. if(Game->Counter[RESERVE_COUNTER]>0){
  186. if((Game->Counter[HEALTH_COUNTER] + Game->Counter[RESERVE_COUNTER])>99
  187. && SamusVars[CURR_FILLED_TANKS]<SamusVars[NUM_TANKS]){
  188. Game->Counter[HEALTH_COUNTER]-=100;
  189. Game->Counter[HEALTH_COUNTER]+=(Game->Counter[RESERVE_COUNTER]-1);
  190. Game->Counter[RESERVE_COUNTER]=1;
  191. SamusVars[CURR_FILLED_TANKS]++;
  192. }
  193. else if((Game->Counter[HEALTH_COUNTER] + Game->Counter[RESERVE_COUNTER])>99
  194. && SamusVars[CURR_FILLED_TANKS]==SamusVars[NUM_TANKS])
  195. Game->Counter[HEALTH_COUNTER]= 99;
  196. else
  197. Game->Counter[HEALTH_COUNTER]+= Game->Counter[RESERVE_COUNTER];
  198. }
  199. if((Game->Counter[HEALTH_COUNTER] + Game->Counter[RESERVE_COUNTER])>99
  200. && SamusVars[CURR_FILLED_TANKS]<SamusVars[NUM_TANKS]){
  201. Game->Counter[HEALTH_COUNTER]=0;
  202. Game->Counter[RESERVE_COUNTER]=0;
  203. SamusVars[CURR_FILLED_TANKS]++;
  204. }
  205. else if((Game->Counter[HEALTH_COUNTER] + Game->Counter[RESERVE_COUNTER])>99
  206. && SamusVars[CURR_FILLED_TANKS]==SamusVars[NUM_TANKS])
  207. Game->Counter[HEALTH_COUNTER]= 99;
  208. else
  209. Game->Counter[HEALTH_COUNTER]++;
  210. Game->Counter[RESERVE_COUNTER]=0;
  211. }
  212. else
  213. SamusVars[LINK_PREV_HP] = 0;
  214. }
  215. else if((Game->Counter[HEALTH_COUNTER] - damage)>0
  216. && SamusVars[CURR_FILLED_TANKS]>=1)Game->Counter[HEALTH_COUNTER]-=damage;
  217. else if((Game->Counter[HEALTH_COUNTER] - damage)<0 && SamusVars[CURR_FILLED_TANKS]==1){
  218. if(Game->Counter[RESERVE_COUNTER]>0){
  219. SamusVars[CURR_FILLED_TANKS] = (SamusVars[NUM_FILLED_RES_TANKS]-1);
  220. Game->Counter[RESERVE_COUNTER]-=((SamusVars[NUM_FILLED_RES_TANKS]-1) * 100);
  221. SamusVars[NUM_FILLED_RES_TANKS]= 1;
  222. if(Game->Counter[RESERVE_COUNTER]>0){
  223. if((Game->Counter[HEALTH_COUNTER] + Game->Counter[RESERVE_COUNTER])>99
  224. && SamusVars[CURR_FILLED_TANKS]<SamusVars[NUM_TANKS]){
  225. Game->Counter[HEALTH_COUNTER]-=100;
  226. Game->Counter[HEALTH_COUNTER]+=Game->Counter[RESERVE_COUNTER];
  227. SamusVars[CURR_FILLED_TANKS]++;
  228. }
  229. else if((Game->Counter[HEALTH_COUNTER] + Game->Counter[RESERVE_COUNTER])>99
  230. && SamusVars[CURR_FILLED_TANKS]==SamusVars[NUM_TANKS])
  231. Game->Counter[HEALTH_COUNTER]= 99;
  232. else
  233. Game->Counter[HEALTH_COUNTER]+= Game->Counter[RESERVE_COUNTER];
  234. }
  235. if((Game->Counter[HEALTH_COUNTER] + Game->Counter[RESERVE_COUNTER])>99
  236. && SamusVars[CURR_FILLED_TANKS]<SamusVars[NUM_TANKS]){
  237. Game->Counter[HEALTH_COUNTER]=0;
  238. Game->Counter[RESERVE_COUNTER]=0;
  239. SamusVars[CURR_FILLED_TANKS]++;
  240. }
  241. else if((Game->Counter[HEALTH_COUNTER] + Game->Counter[RESERVE_COUNTER])>99
  242. && SamusVars[CURR_FILLED_TANKS]==SamusVars[NUM_TANKS])
  243. Game->Counter[HEALTH_COUNTER]= 99;
  244. else
  245. Game->Counter[HEALTH_COUNTER]++;
  246. Game->Counter[RESERVE_COUNTER]=0;
  247. }
  248. else
  249. SamusVars[LINK_PREV_HP] = 0;
  250. }
  251. Link->HP = SamusVars[LINK_PREV_HP];
  252. }
  253. //HP has increased.
  254. else{
  255. //Amount of increase.
  256. damage = Link->HP-SamusVars[LINK_PREV_HP];
  257. //If difference in counter and amount is more than 99, raise HP.
  258. if((Game->Counter[HEALTH_COUNTER] + damage)>99){
  259. Game->Counter[HEALTH_COUNTER]-=100;
  260. Game->Counter[HEALTH_COUNTER]+=damage;
  261. if(SamusVars[CURR_FILLED_TANKS]<SamusVars[NUM_TANKS])
  262. SamusVars[CURR_FILLED_TANKS]++;
  263. else if(SamusVars[NUM_RES_TANKS]>0){
  264. if(SamusVars[NUM_FILLED_RES_TANKS]<SamusVars[NUM_RES_TANKS]){
  265. Game->Counter[RESERVE_COUNTER]++;
  266. SamusVars[NUM_FILLED_RES_TANKS]++;
  267. }
  268. }
  269. }
  270. else
  271. Game->Counter[HEALTH_COUNTER]+=damage;
  272. }
  273. //Set Link's HP every turn so he doesn't die immediately.
  274. Link->HP = SamusVars[LINK_PREV_HP];
  275. }
  276. if(Game->Counter[HEALTH_COUNTER]<=50 && SamusVars[CURR_FILLED_TANKS]==1
  277. && !SamusVars[HEART_BEEP_OFF]){
  278. if(SamusVars[INJURED_TIMER]<=0){
  279. SamusVars[INJURED_TIMER]=180;
  280. Game->PlaySound(SFX_ALERT);
  281. }
  282. else
  283. SamusVars[INJURED_TIMER]--;
  284. }
  285. }
  286.  
  287. const int SFX_ALERT = 82;//Sound to play when low on HP.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement