Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Section 1. Global Scripts.
- global script Init{
- void run(){
- Game->Counter[HEALTH_COUNTER] = 99;
- //One tank is "invisible"
- //This is how the original worked
- //All calculations take this into accout.
- SamusVars[NUM_TANKS]=1;
- SamusVars[CURR_FILLED_TANKS]= 1;
- }
- }
- global script globalscript{
- void run(){
- int PrevTanks = SamusVars[NUM_TANKS];//Initialize variable to track tanks between frames.
- Link->HP = Link->MaxHP;
- SamusVars[LINK_PREV_HP] = Link->HP;//Initialize variable.
- while(true){
- //Not having a game over.
- if(Link->HP>=2){
- //Run energy tanks.
- health();
- DrawETanks();
- }
- //You have more tanks than you did last frame.
- if(SamusVars[NUM_TANKS]>PrevTanks){
- PrevTanks = SamusVars[NUM_TANKS];//Set variable to new value.
- //Max health counter.
- Game->Counter[HEALTH_COUNTER] = 99;
- SamusVars[CURR_FILLED_TANKS]= SamusVars[NUM_TANKS];//Match variable amount.
- item TradeSeqItem;
- //Create the item and place it at Link's location.
- TradeSeqItem = Screen->CreateItem(I_MAGICCONTAINER);
- TradeSeqItem->X = Link->X;
- TradeSeqItem->Y = Link->Y;
- TradeSeqItem->Pickup |= IP_HOLDUP;
- }
- Waitdraw();
- Waitframe();
- }
- }
- }
- //Make sure you have HP when you die and restart.
- global script OnContinue{
- void run(){
- Game->Counter[HEALTH_COUNTER] = 99;
- SamusVars[CURR_FILLED_TANKS]= SamusVars[NUM_TANKS];
- Link->HP = Link->MaxHP;
- }
- }
- //General Use Array and Indices
- const int INJURED_TIMER = 5;// Timer for playing injured SFX.
- const int NUM_TANKS = 21;//Current total energy tanks.
- const int CURR_FILLED_TANKS = 22;//Current filled energy tanks.
- const int NUM_RES_TANKS = 23;//Current total reserve tanks.
- const int NUM_FILLED_RES_TANKS = 24;//Current filled reserve tanks.
- const int LINK_PREV_HP = 25;//Tracks Link's HP between frames.
- int SamusVars[1024];//Array for variable storage.
- //D0- Blank so other scripts can use it.
- //D1- Amount this item heals.
- item script Healing_Item{
- void run(int dummy, int amount){
- //If difference in counter and amount is more than 99, raise HP.
- if((Game->Counter[HEALTH_COUNTER] + amount)>99
- && SamusVars[CURR_FILLED_TANKS]<SamusVars[NUM_TANKS]){
- Game->Counter[HEALTH_COUNTER]-=100;
- Game->Counter[HEALTH_COUNTER]+=amount;
- SamusVars[CURR_FILLED_TANKS]++;
- }
- else if(SamusVars[NUM_RES_TANKS]>0){
- if(SamusVars[NUM_FILLED_RES_TANKS]<SamusVars[NUM_RES_TANKS]){
- if((Game->Counter[RESERVE_COUNTER] + amount)>100
- && (SamusVars[NUM_FILLED_RES_TANKS]+1)<SamusVars[NUM_RES_TANKS]){
- Game->Counter[RESERVE_COUNTER]+=amount;
- SamusVars[NUM_FILLED_RES_TANKS]++;
- }
- else{
- if((Game->Counter[RESERVE_COUNTER] + amount)>100){
- Game->Counter[RESERVE_COUNTER]= 100*SamusVars[NUM_RES_TANKS];
- SamusVars[NUM_FILLED_RES_TANKS]= SamusVars[NUM_RES_TANKS];
- }
- else
- Game->Counter[RESERVE_COUNTER]+=amount;
- }
- }
- else{
- Game->Counter[RESERVE_COUNTER]= 100*SamusVars[NUM_RES_TANKS];
- SamusVars[NUM_FILLED_RES_TANKS]= SamusVars[NUM_RES_TANKS];
- }
- Game->Counter[HEALTH_COUNTER]= 99;
- }
- else if((Game->Counter[HEALTH_COUNTER] + amount)>99
- && SamusVars[CURR_FILLED_TANKS]==SamusVars[NUM_TANKS])
- Game->Counter[HEALTH_COUNTER]= 99;
- else
- Game->Counter[HEALTH_COUNTER]+=amount;
- }
- }
- int HEALTH_COUNTER = CR_SCRIPT2;//Counter for energy tanks.
- //When you get this item, current number of tanks is increased.
- item script Energy_Tank{
- void run(){
- SamusVars[NUM_TANKS]++;
- //Superfluous, unless your quest will keep track of total items obtained.
- Game->Counter[SECRET_COUNTER] ++;
- }
- }
- //When you get this item, current number of reserve tanks is increased.
- int RESERVE_COUNTER = CR_SCRIPT3;//Counter for reserve tanks.
- item script Reserve_Tank{
- void run(int message){
- SamusVars[NUM_RES_TANKS]++;
- SamusVars[NUM_FILLED_RES_TANKS]++;
- Screen->Message(message);
- Game->Counter[SECRET_COUNTER]++;
- Game->Counter[RESERVE_COUNTER]+=100;
- }
- }
- //Constants for drawing Energy Tanks.
- const int TILE_ETANK = 1460;
- const int DRAW_ETANK_TILE = 1460;
- const int DRAW_ETANK_X = 168;
- const int DRAW_ETANK_Y = -26;
- const float DRAW_ETANK_SCALE = 12;
- const int DRAW_ETANK_CSET = 1;
- const int DRAW_ETANK_X_SPACING = 14;
- const int DRAW_ETANK_Y_SPACING = 14;
- void DrawETanks(){
- int x2 = DRAW_ETANK_X;
- int y2 = DRAW_ETANK_Y;
- for ( int q = 1; q <= (SamusVars[CURR_FILLED_TANKS]-1); q++ ) {
- 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);
- x2 += DRAW_ETANK_X_SPACING;
- if ( q % 8 == 0 ) {
- y2 -= DRAW_ETANK_Y_SPACING;
- x2 = DRAW_ETANK_X;
- }
- }
- }
- //Handles HP.
- void health(){
- int damage;//Change in health this frame.
- //Your HP has changed.
- if(Link->HP !=SamusVars[LINK_PREV_HP]){
- //HP has decreased.
- if(Link->HP<SamusVars[LINK_PREV_HP]){
- //Calculate amount of decrease.
- damage = SamusVars[LINK_PREV_HP] - Link->HP;
- //If difference in counter and amount is less than zero, lower HP.
- int tanks_used = Ceiling(damage/ 100);
- if((Game->Counter[HEALTH_COUNTER] - damage) < 0
- && SamusVars[CURR_FILLED_TANKS] > 1
- && (SamusVars[CURR_FILLED_TANKS]-tanks_used)>=1){
- Game->Counter[HEALTH_COUNTER] += 100*tanks_used;
- Game->Counter[HEALTH_COUNTER] -= damage;
- SamusVars[CURR_FILLED_TANKS]-=tanks_used;
- }
- else if((Game->Counter[HEALTH_COUNTER] - damage) < 0
- && SamusVars[CURR_FILLED_TANKS] > 1
- && (SamusVars[CURR_FILLED_TANKS]-tanks_used)<1){
- //Reserve tank code.
- if(Game->Counter[RESERVE_COUNTER]>0){
- SamusVars[CURR_FILLED_TANKS] = (SamusVars[NUM_FILLED_RES_TANKS]-1);
- Game->Counter[RESERVE_COUNTER]-=((SamusVars[NUM_FILLED_RES_TANKS]-1) * 100);
- SamusVars[NUM_FILLED_RES_TANKS]= 1;
- if(Game->Counter[RESERVE_COUNTER]>0){
- if((Game->Counter[HEALTH_COUNTER] + Game->Counter[RESERVE_COUNTER])>99
- && SamusVars[CURR_FILLED_TANKS]<SamusVars[NUM_TANKS]){
- Game->Counter[HEALTH_COUNTER]-=100;
- Game->Counter[HEALTH_COUNTER]+=(Game->Counter[RESERVE_COUNTER]-1);
- Game->Counter[RESERVE_COUNTER]=1;
- SamusVars[CURR_FILLED_TANKS]++;
- }
- else if((Game->Counter[HEALTH_COUNTER] + Game->Counter[RESERVE_COUNTER])>99
- && SamusVars[CURR_FILLED_TANKS]==SamusVars[NUM_TANKS])
- Game->Counter[HEALTH_COUNTER]= 99;
- else
- Game->Counter[HEALTH_COUNTER]+= Game->Counter[RESERVE_COUNTER];
- }
- if((Game->Counter[HEALTH_COUNTER] + Game->Counter[RESERVE_COUNTER])>99
- && SamusVars[CURR_FILLED_TANKS]<SamusVars[NUM_TANKS]){
- Game->Counter[HEALTH_COUNTER]=0;
- Game->Counter[RESERVE_COUNTER]=0;
- SamusVars[CURR_FILLED_TANKS]++;
- }
- else if((Game->Counter[HEALTH_COUNTER] + Game->Counter[RESERVE_COUNTER])>99
- && SamusVars[CURR_FILLED_TANKS]==SamusVars[NUM_TANKS])
- Game->Counter[HEALTH_COUNTER]= 99;
- else
- Game->Counter[HEALTH_COUNTER]++;
- Game->Counter[RESERVE_COUNTER]=0;
- }
- else
- SamusVars[LINK_PREV_HP] = 0;
- }
- else if((Game->Counter[HEALTH_COUNTER] - damage)>0
- && SamusVars[CURR_FILLED_TANKS]>=1)Game->Counter[HEALTH_COUNTER]-=damage;
- else if((Game->Counter[HEALTH_COUNTER] - damage)<0 && SamusVars[CURR_FILLED_TANKS]==1){
- if(Game->Counter[RESERVE_COUNTER]>0){
- SamusVars[CURR_FILLED_TANKS] = (SamusVars[NUM_FILLED_RES_TANKS]-1);
- Game->Counter[RESERVE_COUNTER]-=((SamusVars[NUM_FILLED_RES_TANKS]-1) * 100);
- SamusVars[NUM_FILLED_RES_TANKS]= 1;
- if(Game->Counter[RESERVE_COUNTER]>0){
- if((Game->Counter[HEALTH_COUNTER] + Game->Counter[RESERVE_COUNTER])>99
- && SamusVars[CURR_FILLED_TANKS]<SamusVars[NUM_TANKS]){
- Game->Counter[HEALTH_COUNTER]-=100;
- Game->Counter[HEALTH_COUNTER]+=Game->Counter[RESERVE_COUNTER];
- SamusVars[CURR_FILLED_TANKS]++;
- }
- else if((Game->Counter[HEALTH_COUNTER] + Game->Counter[RESERVE_COUNTER])>99
- && SamusVars[CURR_FILLED_TANKS]==SamusVars[NUM_TANKS])
- Game->Counter[HEALTH_COUNTER]= 99;
- else
- Game->Counter[HEALTH_COUNTER]+= Game->Counter[RESERVE_COUNTER];
- }
- if((Game->Counter[HEALTH_COUNTER] + Game->Counter[RESERVE_COUNTER])>99
- && SamusVars[CURR_FILLED_TANKS]<SamusVars[NUM_TANKS]){
- Game->Counter[HEALTH_COUNTER]=0;
- Game->Counter[RESERVE_COUNTER]=0;
- SamusVars[CURR_FILLED_TANKS]++;
- }
- else if((Game->Counter[HEALTH_COUNTER] + Game->Counter[RESERVE_COUNTER])>99
- && SamusVars[CURR_FILLED_TANKS]==SamusVars[NUM_TANKS])
- Game->Counter[HEALTH_COUNTER]= 99;
- else
- Game->Counter[HEALTH_COUNTER]++;
- Game->Counter[RESERVE_COUNTER]=0;
- }
- else
- SamusVars[LINK_PREV_HP] = 0;
- }
- Link->HP = SamusVars[LINK_PREV_HP];
- }
- //HP has increased.
- else{
- //Amount of increase.
- damage = Link->HP-SamusVars[LINK_PREV_HP];
- //If difference in counter and amount is more than 99, raise HP.
- if((Game->Counter[HEALTH_COUNTER] + damage)>99){
- Game->Counter[HEALTH_COUNTER]-=100;
- Game->Counter[HEALTH_COUNTER]+=damage;
- if(SamusVars[CURR_FILLED_TANKS]<SamusVars[NUM_TANKS])
- SamusVars[CURR_FILLED_TANKS]++;
- else if(SamusVars[NUM_RES_TANKS]>0){
- if(SamusVars[NUM_FILLED_RES_TANKS]<SamusVars[NUM_RES_TANKS]){
- Game->Counter[RESERVE_COUNTER]++;
- SamusVars[NUM_FILLED_RES_TANKS]++;
- }
- }
- }
- else
- Game->Counter[HEALTH_COUNTER]+=damage;
- }
- //Set Link's HP every turn so he doesn't die immediately.
- Link->HP = SamusVars[LINK_PREV_HP];
- }
- if(Game->Counter[HEALTH_COUNTER]<=50 && SamusVars[CURR_FILLED_TANKS]==1
- && !SamusVars[HEART_BEEP_OFF]){
- if(SamusVars[INJURED_TIMER]<=0){
- SamusVars[INJURED_TIMER]=180;
- Game->PlaySound(SFX_ALERT);
- }
- else
- SamusVars[INJURED_TIMER]--;
- }
- }
- const int SFX_ALERT = 82;//Sound to play when low on HP.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement