Advertisement
ZoriaRPG

ZScript King Zora

Nov 18th, 2016
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.36 KB | None | 0 0
  1. /////////////////////////
  2. /// Zelda 3 King Zora ///
  3. /// v0.3              ///
  4. /// 18-Nov-2016       ///
  5. /// By: ZoriaRPG      ///
  6. /////////////////////////
  7.  
  8. ///Graphics
  9. const int TILE_KINGZORA_BASE = 0;
  10. const int TILE_KINGZORA_OPENMOUTHBASE = 6;
  11. const int SPRITE_KING_ZORA_SPLASH = 100;
  12.  
  13. //Sounds
  14. const int SFX_KING_ZORA_RISES = 63;
  15. const int SFX_KINGZORA_POST_RISE_SPLASH = 64;
  16. const int SFX_KINGZORA_OPEN_MOUTH = 65;
  17.  
  18. //Splash Sprite Random Distance
  19. const int KINGZORA_SPLASH_X_WAVER = 32;
  20. const int KINGZORA_SPLASH_Y_WAVER = 48;
  21.  
  22. //Script Settings
  23. const int KINGZORA_SPLASH_ANIM_REPEAT = 12; //The number of times that the splash sprites repeat.
  24. const int KIGZORA_RISE_LOOP_DUR = 200; //The total duration of the animation, in frames.
  25. const int KINGZORA_INITIAL_RISE_TIME = 20; //Delays with water splashes before King Zora begins to rise.
  26. const int KINGZORA_RISE_CYCLE_MODULUS = 60; //The divsor that determines hor many frames to wait before drawing the
  27.                     //next row of tiles, and moving King Zora up a bit.
  28. const int KINGZORA_WAIT_OPEN_MOUTH = 40; //Frames after rising animation ends, before mouth opens.
  29.  
  30. const int KINGZORA_ITEM_JUMP = 10;
  31.  
  32. //Tango Window Styles
  33.  
  34. const int TANGO_SIZE_TINY = 4;
  35. const int WINDOW_STYLE_KINGZORA_MAIN = 4;
  36. const int WINDOW_STYLE_KINGZORA_TINY = 5;
  37. const int WINDOW_STYLE_KINGZORA_ERROR= 6;
  38.  
  39.  
  40.  
  41. ffc script KingZora{ //zora npc id, initial distance minimum to run, item to sell, item cost, message, min distance for dialogue, Screen->D[reg] (-1 to repeat sale)
  42.     void run(int npctype, int initdist, int giveitem, int cost, int msg, int distance, int reg){
  43.        
  44.         if ( reg > -1 && Screen->D[reg] ) { this->Data = 0; this->Script = 0; Quit(): }
  45.         npc kingzora[20]; int buffer[256];
  46.         int cost_str[5];
  47.        
  48.        
  49.         itoa(cost_str,cost); //Store the cost of the item as text.
  50.        
  51.         int msg1[]="I will sell you something good, for ";
  52.         int msg2[]="rupees. What do you say?";
  53.         strcpy(buffer,msg1);
  54.         strcat(buffer,cost_str);
  55.         strcat(buffer,msg2);
  56.         //The string is now in the buffer.
  57.        
  58.         //Spawn King Zora
  59.        
  60.         //Init animation
  61.         //screen rumbles
  62.         //water ripples
  63.        
  64.         //King zora rises
  65.        
  66.        
  67.        
  68.         kingzora[1] = Screen->CreateNPC(npctype);
  69.         kingzora[1]->X = this->X;
  70.         kingzora[1]->Y = this->Y;
  71.         kingzora[1]->HitXOffset = -200;
  72.         kingzora[1]->HitYOffset = -200;
  73.        
  74.         kingzora[1]->DrawYOffset = -200; //We'll move him in afterthe animation.
  75.        
  76.        
  77.         kingzora[1]->Extend = 3;
  78.         kingzora[1]->TileWidth = 3;
  79.         kingzora[1]->TileHeight = 1; //We will make this 2, then 3, gradually.
  80.        
  81.         eweapon splash[12]; //the size of this array should match the constant 'KINGZORA_SPLASH_ANIM_REPEAT'.
  82.        
  83.         int q[4];
  84.        
  85.         while(true){
  86.            
  87.             while( DistXY(this) < initdist ) Waitframe(); //Wait until Link is close enugh.
  88.            
  89.             //shake screen, do ripples
  90.            
  91.             if ( !q[3] ) { //Don't do this more than one time.
  92.                 if ( SFX_KING_ZORA_RISES ) Game->PlaySound(SFX_KING_ZORA_RISES);
  93.                 for  q[0] = 1, q[0] < KIGZORA_RISE_LOOP_DUR; q++ ) {
  94.                     Screen->Quake = 2;
  95.                     for ( q[1] = 0; q[1] < KINGZORA_SPLASH_ANIM_REPEAT; q[1]++ ){
  96.                         //draw splashes
  97.                         splash[ q[1] ] = Screen->CreateLWeapon(LW_SPARKLE);
  98.                         splash[ q[1] ]->CollDetection = false;
  99.                         splash[ q[1] ]->UseSprite = SPRITE_KING_ZORA_SPLASH;
  100.                         splash[ q[1] ]->X = this->X + Rand(-KINGZORA_SPLASH_X_WAVER, KINGZORA_SPLASH_X_WAVER);
  101.                     `   splash[ q[1] ]->Y = this->Y + Rand(-KINGZORA_SPLASH_Y_WAVER, KINGZORA_SPLASH_Y_WAVER);
  102.                     }
  103.                     //King Zora Rises from the Deep
  104.                     kingzora[1]->DrawYOffset = this->Y + 32;
  105.                     if ( (q[0]-KINGZORA_INITIAL_RISE_TIME) % KINGZORA_RISE_CYCLE_MODULUS == 0 && q[0] != 0 ) {
  106.                         if ( kingzora[1]->TileHeight != 3 ) kingzora[1]->TileHeight++; //add a row of tiles
  107.                         if ( kingzora[1]->DrawYOffset != kingzora[1]->Y ) kingzora[1]->DrawYOffset += 16; //and move him upward
  108.                                                                 //to simulate rising from the water.
  109.                     }
  110.                     Waitframe();
  111.                 }
  112.                
  113.                 //Play the post-rise splash sound.
  114.                 if ( SFX_KINGZORA_POST_RISE_SPLASH ) Game->PlaySound(SFX_KINGZORA_POST_RISE_SPLASH);
  115.                
  116.                 //Wait a few rames after rising    
  117.                 Waitframes(KINGZORA_WAIT_OPEN_MOUTH);
  118.                 //!!King Zora Opens his mouth, here.
  119.                
  120.                 //Play open mouth sound
  121.                
  122.                 if ( SFX_KINGZORA_OPEN_MOUTH ) Game->PlaySound(SFX_KINGZORA_OPEN_MOUTH);
  123.                
  124.                 q[3] = 1; // Mark that the animation sequence is complete.
  125.             }
  126.                        
  127.            
  128.  
  129.            
  130.            
  131.            
  132.             if ( ( reg > -1 && !Screen->D[reg] ) && DistXY(this) < distance && ( Link->PressA || Link->PressB ) ) {
  133.                 //Open his mouth
  134.                 kingzora[1]->OriginalTile = TILE_KINGZORA_OPENMOUTHBASE;
  135.            
  136.                 //Display the buffer string in a menu.
  137.                 if ( KingZoraMenu(cost,buffer) {
  138.                    
  139.                     //Opens the menu and dialogues/
  140.                     //if it returns true, create the item.
  141.                     item it = Screen->CreateItem(giveitem);
  142.                     it->X = -200;
  143.                     it->Y = this->Y;
  144.                     it->Jump = KINGZORA_ITEM_JUMP;
  145.                     it->Pickup = IP_HOLDUP;
  146.                     WaitNoAction();
  147.                     it->X = Link->X; //Fall in a pseudo-3d arc, to Link
  148.                     while( !LinkCollision(it) ) {
  149.                         it->Y--;
  150.                         WaitNoAction();
  151.                     }
  152.                     if ( reg > -1 ) Screen->D[reg] = 1; //Stop the player from buying the item twice, unless 'reg' is set to a neative value.  
  153.                
  154.                 }
  155.                 else error();
  156.  
  157.             }
  158.             Waitframe();
  159.         }
  160.     }
  161.    
  162.     bool KingZoraMenu(int cost, int str){
  163.         int buffer[300];
  164.         strcpy(buffer, str);
  165.        
  166.         //Display the buffer string in a menu.
  167.         ShowString(buffer, WINDOW_SLOT_1, WINDOW_STYLE_KINGZORA_MAIN, 48, 48);
  168.        
  169.         //Give a yes/no choice.
  170.         if ( yesno() ) {
  171.             if ( cost <= Game->Counter[CR_RUPEES] ) {
  172.                 Game->DCounter[CR_RUPEES] -= cost;
  173.                 return true;
  174.             //Compare cost to Game->Counter[CR_RUPEES]
  175.             //if item sold, return true.
  176.         }
  177.         else return false;
  178.     }
  179.     bool yesno(){
  180.         //the yes no menu.
  181.         //Opens a submenu over the dialogue display.
  182.         int y[]="@choice(1)Yes@26";
  183.         int n[]="@choice(2)No@domenu(1)@suspend()";
  184.         SetUpWindow(WINDOW_SLOT_2, WINDOW_STYLE_KINGZORA_TINY, 32, 32, TANGO_SIZE_TINY);
  185.         Tango_LoadString(WINDOW_SLOT_2, y);
  186.         Tango_AppendString(WINDOW_SLOT_2, n);
  187.        
  188.         while( !Tango_MenuIsActive() ) Waitframe();
  189.    
  190.         int slotState[278];
  191.         int menuState[960];
  192.         int cursorPos;
  193.         Tango_SaveSlotState(WINDOW_SLOT_2, slotState);
  194.         Tango_SaveMenuState(menuState);
  195.        
  196.         int done = 0;
  197.         int choice;
  198.        
  199.         while(true){
  200.    
  201.             while( Tango_MenuIsActive() ) {
  202.                 cursorPos=Tango_GetMenuCursorPosition();
  203.                 Waitframe();
  204.             }
  205.        
  206.             choice = Tango_GetLastMenuChoice();
  207.             if ( choice == 1 ) { // yes
  208.                 done = choice;
  209.                 menuArg = choice;
  210.             }
  211.            
  212.             else if ( choice == 2 ) { //no
  213.                 done = choice;
  214.                 menuArg = choice;
  215.             }
  216.        
  217.  
  218.             if ( done ) {
  219.                 break;
  220.             //  return choice;
  221.             }
  222.             else {
  223.                 Tango_RestoreSlotState(WINDOW_SLOT_1, slotState);
  224.                 Tango_RestoreMenuState(menuState);
  225.                 Tango_SetMenuCursorPosition(cursorPos);
  226.             }
  227.         }
  228.    
  229.         Tango_ClearSlot(WINDOW_SLOT_2);
  230.        
  231.         if ( done == 1 ) return true; //if yes, return true
  232.         else return false;
  233.     }
  234.     void error(){
  235.         //a dialogue that gives an error message.
  236.         int err[]="Sorry, you seem to lack the funds to buy my marvelous goodies.";
  237.         //clear slot 2 (the yes/no menu)
  238.         Tango_ClearSlot(WINDOW_SLOT_1);
  239.         Tango_ClearSlot(WINDOW_SLOT_2);
  240.         //ShowMessage(err); //show the message in the slot used by the initial dialogue
  241.         ShowString(err, WINDOW_SLOT_1, WINDOW_STYLE_KINGZORA_ERROR, 48, 48);
  242.     }
  243. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement