ZoriaRPG

Moosh.zh

May 20th, 2017
124
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Moosh.zh constants
  2.  
  3. //const int MAX_PUSH = 4;
  4.  
  5. //const int CMB_MENUSELECT = 2600; //Combo used for the menu selection cursor. Uses the upper left quarter of the tile block.
  6. //const int CS_MENUSELECT = 8; //CSet used for the menu selection cursor
  7. //const int FONT_MENU = 0; //The font used for the menu. FONT_Z1 by default.
  8.  
  9. //const int SFX_MENU = 6; //Sound for navigating a menu
  10. //const int SFX_SELECT = 5; //Sound for making a menu selection
  11. //const int SFX_CANCEL = 5; //Sound for cancelling a selection
  12. //const int SFX_ERROR = 5; //Error sound
  13.  
  14. //const int WORM_MAX_STEP = 10;
  15.  
  16. void DrawComboArc(int Layer, int X1, int Y1, int X2, int Y2, int Combo, int CSet, int Segments, int Curve, int Opacity){
  17.     int a = Angle(X1, Y1, X2, Y2);
  18.     int d = Distance(X1, Y1, X2, Y2);
  19.     int w = 180/d;
  20.     for(int i=0; i<Segments; i++){
  21.         Screen->FastCombo(Layer, X1+VectorX((d/Segments)*i, a)+VectorX(Curve*Sin(w*(d/Segments*i)), a-90), Y1+VectorY((d/Segments)*i, a)+VectorY(Curve*Sin(w*(d/Segments*i)), a-90), Combo, CSet, Opacity);
  22.     }
  23. }
  24.  
  25. int DrawArrayTentacle(int Layer, int TentacleX, int TentacleY, int Combo, int CSet, int MaxLag, int Counter, int CounterIncrement){
  26.     int Size = SizeOfArray(TentacleX);
  27.     for(int i=0; i<Size; i++){
  28.         int Angle = Angle(TentacleX[0], TentacleY[0], TentacleX[Size-1], TentacleY[Size-1]);
  29.         int Distance = Distance(TentacleX[0], TentacleY[0], TentacleX[Size-1], TentacleY[Size-1]);
  30.         int TX = TentacleX[0]+VectorX((Distance/(Size-1))*i, Angle)+VectorX(Sin(180/Size*i)*(Min(8, Distance/8)*Sin(Floor(i/2)*(180/Size)*i+Counter)), Angle+90);
  31.         int TY = TentacleY[0]+VectorY((Distance/(Size-1))*i, Angle)+VectorY(Sin(180/Size*i)*(Min(8, Distance/8)*Sin(Floor(i/2)*(180/Size)*i+Counter)), Angle+90);
  32.         int Lag = 1+MaxLag*Sin(180/Size*i);
  33.         if(i!=0&&i!=Size-1){
  34.             TentacleX[i] += VectorX(Distance(TentacleX[i], TentacleY[i], TX, TY)/Lag, Angle(TentacleX[i], TentacleY[i], TX, TY));
  35.             TentacleY[i] += VectorY(Distance(TentacleX[i], TentacleY[i], TX, TY)/Lag, Angle(TentacleX[i], TentacleY[i], TX, TY));
  36.         }
  37.         Screen->FastCombo(Layer, TentacleX[i], TentacleY[i], Combo, CSet, 128);
  38.     }
  39.     Counter += CounterIncrement;
  40.     if(Counter>360){
  41.         Counter -= 360;
  42.     }
  43.     return Counter;
  44. }
  45.  
  46. void NoWalk(){
  47.     Link->InputUp=false;
  48.     Link->InputDown=false;
  49.     Link->InputRight=false;
  50.     Link->InputLeft=false;
  51. }
  52.  
  53. void NoButton(){
  54.     Link->InputA=false;
  55.     Link->InputB=false;
  56.     Link->InputL=false;
  57.     Link->InputR=false;
  58.     Link->PressA=false;
  59.     Link->PressB=false;
  60.     Link->PressL=false;
  61.     Link->PressR=false;
  62. }
  63.  
  64. bool PressButtonItem(int itm){
  65.     if(GetEquipmentA()==itm&&Link->PressA)return true;
  66.     else if(GetEquipmentB()==itm&&Link->PressB)return true;
  67.     return false;
  68. }
  69. bool InputButtonItem(int itm){
  70.     if(GetEquipmentA()==itm&&Link->InputA)return true;
  71.     else if(GetEquipmentB()==itm&&Link->InputB)return true;
  72.     return false;
  73. }
  74.  
  75. int DirAngle(int Dir){
  76.     if(Dir==DIR_UP)return -90;
  77.     else if(Dir==DIR_DOWN)return 90;
  78.     else if(Dir==DIR_LEFT)return 180;
  79.     else if(Dir==DIR_RIGHT)return 0;
  80.     else if(Dir==DIR_LEFTUP)return -135;
  81.     else if(Dir==DIR_RIGHTUP)return -45;
  82.     else if(Dir==DIR_LEFTDOWN)return 135;
  83.     else if(Dir==DIR_RIGHTDOWN)return 45;
  84. }
  85.  
  86. bool Xor(bool A, bool B){
  87.     if((A&&!B)||(B&&!A))
  88.         return true;
  89.     return false;
  90. }
  91.  
  92. void DrawTrueMapPosition(int Layer, int Map, int X, int Y){
  93.     int MinScreen = Floor(X/256)+16*Floor(Y/176);
  94.     Screen->Rectangle(Layer, 0, 0, 255, 175, 0, 1, 0, 0, 0, true, 128);
  95.     int TLX = -(X%256);
  96.     int TLY = -(Y%176);
  97.     Screen->DrawScreen(Layer, Map, MinScreen, TLX, TLY, 0);
  98.     Screen->DrawScreen(Layer, Map, MinScreen+1, TLX+256, TLY, 0);
  99.     Screen->DrawScreen(Layer, Map, MinScreen+16, TLX, TLY+176, 0);
  100.     Screen->DrawScreen(Layer, Map, MinScreen+17, TLX+256, TLY+176, 0);
  101.     //Screen->DrawInteger(5, 8, 8, FONT_Z3SMALL, 0x01, -1, -1, -1, MinScreen, 0, 128);
  102.  }
  103.  
  104. float LargeDistance(int x1, int y1, int x2, int y2){
  105.     int c1x = (x1+x2)/2;
  106.     int c1y = (y1+y2)/2;
  107.     int c2x = (x1+c1x)/2;
  108.     int c2y = (y1+c1y)/2;
  109.     int c3x = (x1+c2x)/2;
  110.     int c3y = (y1+c2y)/2;
  111.     return Distance(x1, y1, c3x, c3y)*8;
  112. }
  113.  
  114. void ScreenPan(int Layer, int Map, int StartScreen, int EndScreen, int Duration){
  115.     int StartX = StartScreen%16*256;
  116.     int StartY = Floor(StartScreen/16)*176;
  117.     int EndX = EndScreen%16*256;
  118.     int EndY = Floor(EndScreen/16)*176;
  119.     int X = StartX;
  120.     int Y = StartY;
  121.     int Distance = LargeDistance(StartX, StartY, EndX, EndY);
  122.     for(int i=0; i<Duration; i++){
  123.         DrawTrueMapPosition(Layer, Map, X, Y);
  124.         X += VectorX(Distance/Duration, Angle(StartX, StartY, EndX, EndY));
  125.         Y += VectorY(Distance/Duration, Angle(StartX, StartY, EndX, EndY));
  126.         WaitNoAction();
  127.     }
  128. }
  129.  
  130. void ScreenPan2(int Layer, int Map, int StartScreen, int EndScreen, int Speed){
  131.     int StartX = StartScreen%16*256;
  132.     int StartY = Floor(StartScreen/16)*176;
  133.     int EndX = EndScreen%16*256;
  134.     int EndY = Floor(EndScreen/16)*176;
  135.     int X = StartX;
  136.     int Y = StartY;
  137.     int Distance = LargeDistance(StartX, StartY, EndX, EndY);
  138.     while(LargeDistance(X, Y, EndX, EndY)>Speed){
  139.         DrawTrueMapPosition(Layer, Map, X, Y);
  140.         X += VectorX(Speed, Angle(StartX, StartY, EndX, EndY));
  141.         Y += VectorY(Speed, Angle(StartX, StartY, EndX, EndY));
  142.         WaitNoAction();
  143.     }
  144. }
  145.  
  146. void ScreenHold(int Layer, int Map, int Screen, int Duration){
  147.     int X = Screen%16*256;
  148.     int Y = Floor(Screen/16)*176;
  149.     for(int i=0; i<Duration; i++){
  150.         DrawTrueMapPosition(Layer, Map, X, Y);
  151.         WaitNoAction();
  152.     }
  153. }
  154.  
  155. // void NoWalk(){
  156.     // Link->InputUp = false; Link->PressUp = false;
  157.     // Link->InputDown = false; Link->PressDown = false;
  158.     // Link->InputLeft = false; Link->PressLeft = false;
  159.     // Link->InputRight = false; Link->PressRight = false;
  160. // }
  161.  
  162. bool LeavingScreen(){
  163.     if(Link->X<2&&Link->InputLeft)
  164.         return true;
  165.     if(Link->X>238&&Link->InputRight)
  166.         return true;
  167.     if(Link->Y<2&&Link->InputUp)
  168.         return true;
  169.     if(Link->Y>158&&Link->InputDown)
  170.         return true;
  171.     return false;
  172. }
  173.  
  174. //This function checks the path of the beamos' laser before firing
  175. bool CheckPath(int X, int Y, int Angle, int Distance, int SafeDist, int Step){
  176.     for(int i = 0; i<Distance-Step; i+=Step){
  177.         X += VectorX(Step, Angle);
  178.         Y += VectorY(Step, Angle);
  179.         if(Screen->isSolid(X, Y)&&i>SafeDist)
  180.             return false;
  181.     }
  182.     return true;
  183. }
  184.  
  185. void DrawTile(int layer, int cx, int cy, int tile, int blockw, int blockh, int cset, int xscale, int yscale, int rx, int ry, int rangle, int flip, bool transparency, int opacity){
  186.     int w = xscale;
  187.     if(xscale==-1)
  188.         w = blockw*16;
  189.     int h = yscale;
  190.     if(yscale==-1)
  191.         h = blockh*16;
  192.     Screen->DrawTile(layer, cx-w/2, cy-h/2, tile, blockw, blockh, cset, xscale, yscale, rx-w/2, ry-h/2, rangle, flip, transparency, opacity);
  193. }
  194.  
  195. void DrawCombo(int layer, int cx, int cy, int tile, int blockw, int blockh, int cset, int xscale, int yscale, int rx, int ry, int rangle, int frame, int flip, bool transparency, int opacity){
  196.     int w = xscale;
  197.     if(xscale==-1)
  198.         w = blockw*16;
  199.     int h = yscale;
  200.     if(yscale==-1)
  201.         h = blockh*16;
  202.     Screen->DrawCombo(layer, cx-w/2, cy-h/2, tile, blockw, blockh, cset, xscale, yscale, rx-w/2, ry-h/2, rangle, frame, flip, transparency, opacity);
  203. }
  204.  
  205. bool PixelCollision(int PixX, int PixY, int BoxX, int BoxY, int BoxWidth, int BoxHeight){
  206.     if(PixX>=BoxX&&PixX<=BoxX+BoxWidth&&PixY>=BoxY&&PixY<=BoxY+BoxHeight)
  207.         return true;
  208.     return false;
  209. }
  210.  
  211. //const int MAX_PUSH = 4;
  212.  
  213. void HandlePushArray(int PushArray, int Imprecision){
  214.     for(int i=0; i<MAX_PUSH&&PushArray[0]<=-1; i++){
  215.         if(CanWalk(Link->X, Link->Y, DIR_LEFT, 1, false)){
  216.             Link->X--;
  217.             PushArray[0]++;
  218.         }
  219.         else if(Imprecision>0&&Abs(GridY(Link->Y+8)-Link->Y)<Imprecision&&CanWalk(Link->X, GridY(Link->Y+8), DIR_LEFT, 1, false)){
  220.             Link->Y = GridY(Link->Y+8);
  221.             Link->X--;
  222.             PushArray[0]++;
  223.         }
  224.         else{
  225.             PushArray[0] = 0;
  226.         }
  227.     }
  228.     for(int i=0; i<MAX_PUSH&&PushArray[0]>=1; i++){
  229.         if(CanWalk(Link->X, Link->Y, DIR_RIGHT, 1, false)){
  230.             Link->X++;
  231.             PushArray[0]--;
  232.         }
  233.         else if(Imprecision>0&&Abs(GridY(Link->Y+8)-Link->Y)<Imprecision&&CanWalk(Link->X, GridY(Link->Y+8), DIR_RIGHT, 1, false)){
  234.             Link->Y = GridY(Link->Y+8);
  235.             Link->X++;
  236.             PushArray[0]++;
  237.         }
  238.         else{
  239.             PushArray[0] = 0;
  240.         }
  241.     }
  242.     for(int i=0; i<MAX_PUSH&&PushArray[1]<=-1; i++){
  243.         if(CanWalk(Link->X, Link->Y, DIR_UP, 1, false)){
  244.             Link->Y--;
  245.             PushArray[1]++;
  246.         }
  247.         else if(Imprecision>0&&Abs(GridX(Link->X+8)-Link->X)<Imprecision&&CanWalk(GridX(Link->X+8), Link->Y, DIR_UP, 1, false)){
  248.             Link->X = GridX(Link->X+8);
  249.             Link->Y--;
  250.             PushArray[0]++;
  251.         }
  252.         else{
  253.             PushArray[1] = 0;
  254.         }
  255.     }
  256.     for(int i=0; i<MAX_PUSH&&PushArray[1]>=1; i++){
  257.         if(CanWalk(Link->X, Link->Y, DIR_DOWN, 1, false)){
  258.             Link->Y++;
  259.             PushArray[1]--;
  260.         }
  261.         else if(Imprecision>0&&Abs(GridX(Link->X+8)-Link->X)<Imprecision&&CanWalk(GridX(Link->X+8), Link->Y, DIR_DOWN, 1, false)){
  262.             Link->X = GridX(Link->X+8);
  263.             Link->Y++;
  264.             PushArray[0]++;
  265.         }
  266.         else{
  267.             PushArray[1] = 0;
  268.         }
  269.     }
  270. }
  271.  
  272. void SetNPCHitbox(npc n, int OffX, int OffY, int HitX, int HitY){
  273.     n->HitXOffset = OffX;
  274.     n->HitYOffset = OffY;
  275.     n->HitWidth = HitX;
  276.     n->HitHeight = HitY;
  277. }
  278.  
  279. void SetEWeaponHitbox(eweapon e , int OffX, int OffY, int HitX, int HitY){
  280.     e->HitXOffset = OffX;
  281.     e->HitYOffset = OffY;
  282.     e->HitWidth = HitX;
  283.     e->HitHeight = HitY;
  284. }
  285.  
  286. void SetLWeaponHitbox(lweapon l, int OffX, int OffY, int HitX, int HitY){
  287.     l->HitXOffset = OffX;
  288.     l->HitYOffset = OffY;
  289.     l->HitWidth = HitX;
  290.     l->HitHeight = HitY;
  291. }
  292.  
  293. int SwordDirX(int dir){
  294.     if(dir==DIR_UP)
  295.         return 0;
  296.     else if(dir==DIR_DOWN)
  297.         return 0;
  298.     else if(dir==DIR_LEFT)
  299.         return -15;
  300.     else if(dir==DIR_RIGHT)
  301.         return 15;
  302.     else if(dir==DIR_LEFTUP)
  303.         return -12;
  304.     else if(dir==DIR_RIGHTUP)
  305.         return 12;
  306.     else if(dir==DIR_LEFTDOWN)
  307.         return -12;
  308.     else if(dir==DIR_RIGHTDOWN)
  309.         return 12;
  310. }
  311.  
  312. int SwordDirXBig(int dir, int width){
  313.     if(dir==DIR_UP)
  314.         return -(width-1)*8;
  315.     else if(dir==DIR_DOWN)
  316.         return -(width-1)*8;
  317.     else if(dir==DIR_LEFT)
  318.         return -width*15;
  319.     else if(dir==DIR_RIGHT)
  320.         return 15;
  321.     else if(dir==DIR_LEFTUP)
  322.         return -12-(width-1)*16;
  323.     else if(dir==DIR_RIGHTUP)
  324.         return 12;
  325.     else if(dir==DIR_LEFTDOWN)
  326.         return -12-(width-1)*16;
  327.     else if(dir==DIR_RIGHTDOWN)
  328.         return 12;
  329. }
  330.  
  331. int SwordDirY(int dir){
  332.     if(dir==DIR_UP)
  333.         return -15;
  334.     else if(dir==DIR_DOWN)
  335.         return 15;
  336.     else if(dir==DIR_LEFT)
  337.         return 0;
  338.     else if(dir==DIR_RIGHT)
  339.         return 0;
  340.     else if(dir==DIR_LEFTUP)
  341.         return -12;
  342.     else if(dir==DIR_RIGHTUP)
  343.         return -12;
  344.     else if(dir==DIR_LEFTDOWN)
  345.         return 12;
  346.     else if(dir==DIR_RIGHTDOWN)
  347.         return 12;
  348. }
  349.  
  350. int SwordDirYBig(int dir, int width){
  351.     if(dir==DIR_UP)
  352.         return -width*15;
  353.     else if(dir==DIR_DOWN)
  354.         return 15;
  355.     else if(dir==DIR_LEFT)
  356.         return -(width-1)*8;
  357.     else if(dir==DIR_RIGHT)
  358.         return -(width-1)*8;
  359.     else if(dir==DIR_LEFTUP)
  360.         return -12-(width-1)*16;
  361.     else if(dir==DIR_RIGHTUP)
  362.         return -12-(width-1)*16;
  363.     else if(dir==DIR_LEFTDOWN)
  364.         return 12;
  365.     else if(dir==DIR_RIGHTDOWN)
  366.         return 12;
  367. }
  368.  
  369. int SwordSlashDefault(int dir, int frame, int maxframe){
  370.     int state = Floor(frame/Ceiling(maxframe/3));
  371.     if(dir==DIR_UP){
  372.         if(state==0)
  373.             return DIR_RIGHT;
  374.         else if(state==1)
  375.             return DIR_RIGHTUP;
  376.         else
  377.             return DIR_UP;
  378.     }
  379.     else if(dir==DIR_DOWN){
  380.         if(state==0)
  381.             return DIR_LEFT;
  382.         else if(state==1)
  383.             return DIR_LEFTDOWN;
  384.         else
  385.             return DIR_DOWN;
  386.     }
  387.     else if(dir==DIR_LEFT){
  388.         if(state==0)
  389.             return DIR_UP;
  390.         else if(state==1)
  391.             return DIR_LEFTUP;
  392.         else
  393.             return DIR_LEFT;
  394.     }
  395.     else if(dir==DIR_RIGHT){
  396.         if(state==0)
  397.             return DIR_UP;
  398.         else if(state==1)
  399.             return DIR_RIGHTUP;
  400.         else
  401.             return DIR_RIGHT;
  402.     }
  403. }
  404.  
  405. int SwordSlashLTTP(int dir, int frame, int maxframe){
  406.     int state = Floor(frame/Ceiling(maxframe/3));
  407.     if(dir==DIR_UP){
  408.         if(state==0)
  409.             return DIR_RIGHTUP;
  410.         else if(state==1)
  411.             return DIR_UP;
  412.         else
  413.             return DIR_LEFTUP;
  414.     }
  415.     else if(dir==DIR_DOWN){
  416.         if(state==0)
  417.             return DIR_LEFTDOWN;
  418.         else if(state==1)
  419.             return DIR_DOWN;
  420.         else
  421.             return DIR_RIGHTDOWN;
  422.     }
  423.     else if(dir==DIR_LEFT){
  424.         if(state==0)
  425.             return DIR_LEFTUP;
  426.         else if(state==1)
  427.             return DIR_LEFT;
  428.         else
  429.             return DIR_LEFTDOWN;
  430.     }
  431.     else if(dir==DIR_RIGHT){
  432.         if(state==0)
  433.             return DIR_RIGHTUP;
  434.         else if(state==1)
  435.             return DIR_RIGHT;
  436.         else
  437.             return DIR_RIGHTDOWN;
  438.     }
  439. }
  440.  
  441. int SwordSlash180(int dir, int frame, int maxframe){
  442.     int state = Floor(frame/Ceiling(maxframe/5));
  443.     if(dir==DIR_UP){
  444.         if(state==0)
  445.             return DIR_RIGHT;
  446.         else if(state==1)
  447.             return DIR_RIGHTUP;
  448.         else if(state==2)
  449.             return DIR_UP;
  450.         else if(state==3)
  451.             return DIR_LEFTUP;
  452.         else
  453.             return DIR_LEFT;
  454.     }
  455.     else if(dir==DIR_DOWN){
  456.         if(state==0)
  457.             return DIR_LEFT;
  458.         else if(state==1)
  459.             return DIR_LEFTDOWN;
  460.         else if(state==2)
  461.             return DIR_DOWN;
  462.         else if(state==3)
  463.             return DIR_RIGHTDOWN;
  464.         else
  465.             return DIR_RIGHT;
  466.     }
  467.     else if(dir==DIR_LEFT){
  468.         if(state==0)
  469.             return DIR_UP;
  470.         else if(state==1)
  471.             return DIR_LEFTUP;
  472.         else if(state==2)
  473.             return DIR_LEFT;
  474.         else if(state==3)
  475.             return DIR_LEFTDOWN;
  476.         else
  477.             return DIR_DOWN;
  478.     }
  479.     else if(dir==DIR_RIGHT){
  480.         if(state==0)
  481.             return DIR_UP;
  482.         else if(state==1)
  483.             return DIR_RIGHTUP;
  484.         else if(state==2)
  485.             return DIR_RIGHT;
  486.         else if(state==3)
  487.             return DIR_RIGHTDOWN;
  488.         else
  489.             return DIR_DOWN;
  490.     }
  491. }
  492.  
  493. //const int CMB_MENUSELECT = 2600; //Combo used for the menu selection cursor. Uses the upper left quarter of the tile block.
  494. //const int CS_MENUSELECT = 8; //CSet used for the menu selection cursor
  495. //const int FONT_MENU = 0; //The font used for the menu. FONT_Z1 by default.
  496.  
  497. //const int SFX_MENU = 6; //Sound for navigating a menu
  498. //const int SFX_SELECT = 5; //Sound for making a menu selection
  499. //const int SFX_CANCEL = 5; //Sound for cancelling a selection
  500. //const int SFX_ERROR = 5; //Error sound
  501.  
  502. //Function for setting the arrays for the drawn tile blocks. You can also set them like int Frame[7] = {...};
  503. // - int vars is the array you're setting
  504. // - int layer is the layer to draw to
  505. // - int X is the X position to draw to
  506. // - int Y is the Y position to draw to
  507. // - int Tile is the top left corner of the tile block
  508. // - int CSet is the cset to draw in
  509. // - int Width is the width of the tile block
  510. // - int Height is the height of the tile block
  511. void DefineFrame(int vars, int layer, int X, int Y, int Tile, int CSet, int Width, int Height){
  512.     vars[0] = layer;
  513.     vars[1] = X;
  514.     vars[2] = Y;
  515.     vars[3] = Tile;
  516.     vars[4] = CSet;
  517.     vars[5] = Width;
  518.     vars[6] = Height;
  519. }
  520.  
  521. //Function for just running a regular menu.
  522. // - int choices is an array of strings for the selection choices
  523. // - int textframe is an array for a drawn tile block for the last string displayed. Set to 0 for no text box.
  524. // - int selframe is an array for a drawn tile block for the text box behind the choices.
  525. // - int default is the choice that the selection defaults to. It starts from 0 in the choices array.
  526. // - bool cancel is whether or not the player can cancel the choice by pressing B. A cancel returns -1.
  527. int MenuChoice(int choices, int textframe, int selframe, int default, bool cancel){
  528.     int select = default;
  529.     int numchoices = SizeOfArray(choices);
  530.     while(true){
  531.         if(textframe[3]>0)
  532.             Screen->DrawTile(textframe[0], textframe[1], textframe[2], textframe[3], textframe[5], textframe[6], textframe[4], -1, -1, 0, 0, 0, 0, true, 128);
  533.         if(selframe[3]>0)
  534.             Screen->DrawTile(selframe[0], selframe[1], selframe[2], selframe[3], selframe[5], selframe[6], selframe[4], -1, -1, 0, 0, 0, 0, true, 128);
  535.         for(int i=0; i<numchoices; i++){
  536.             int str = choices[i];
  537.             Screen->DrawString(selframe[0], selframe[1]+16, selframe[2]+12+12*i, FONT_MENU, 1, -1, TF_NORMAL, str, 128);
  538.             if(select==i)
  539.                 Screen->FastCombo(selframe[0], selframe[1]+8, selframe[2]+12+12*i, CMB_MENUSELECT, CS_MENUSELECT, 128);
  540.         }
  541.         if(Link->PressUp){
  542.             Game->PlaySound(SFX_MENU);
  543.             select--;
  544.             if(select<0)
  545.                 select = numchoices-1;
  546.         }
  547.         else if(Link->PressDown){
  548.             Game->PlaySound(SFX_MENU);
  549.             select++;
  550.             if(select>=numchoices)
  551.                 select = 0;
  552.         }
  553.         else if(Link->PressA){
  554.             Link->PressA = false;
  555.             Link->InputA = false;
  556.             Game->PlaySound(SFX_SELECT);
  557.             break;
  558.         }
  559.         else if(Link->PressB&&cancel){
  560.             Link->PressB = false;
  561.             Link->InputB = false;
  562.             Game->PlaySound(SFX_CANCEL);
  563.             select = -1;
  564.             break;
  565.         }
  566.         Link->PressStart = false;
  567.         Link->InputStart = false;
  568.         WaitNoAction();
  569.     }
  570.     return select;
  571. }
  572.  
  573. //Function for running a menu in a single frame
  574. // - int vars is a hack method I used to keep track of stuff I otherwise couldn't in one frame. It's an array with a size of 2.
  575. //      - vars[0] is the current menu selection
  576. //      - vars[1] is whether or not the player has made a selection
  577. // - int choices is an array of strings for the selection choices
  578. // - int textframe is an array for a drawn tile block for the last string displayed. Set to 0 for no text box.
  579. // - int selframe is an array for a drawn tile block for the text box behind the choices.
  580. // - bool cancel is whether or not the player can cancel the choice by pressing B. A cancel returns -1.
  581. //This function is meant to be called in a while loop that runs while vars[1] is 0.
  582. //This function should only be needed if there's something you need to do in the script while the menu is open based on the current menu selection.
  583. int MenuChoice2(int vars, int choices, int textframe, int selframe, bool cancel){
  584.     int numchoices = SizeOfArray(choices);
  585.     if(textframe[3]>0)
  586.         Screen->DrawTile(textframe[0], textframe[1], textframe[2], textframe[3], textframe[5], textframe[6], textframe[4], -1, -1, 0, 0, 0, 0, true, 128);
  587.     if(selframe[3]>0)
  588.         Screen->DrawTile(selframe[0], selframe[1], selframe[2], selframe[3], selframe[5], selframe[6], selframe[4], -1, -1, 0, 0, 0, 0, true, 128);
  589.     for(int i=0; i<numchoices; i++){
  590.         int str = choices[i];
  591.         Screen->DrawString(selframe[0], selframe[1]+16, selframe[2]+12+12*i, FONT_MENU, 1, -1, TF_NORMAL, str, 128);
  592.         if(vars[0]==i)
  593.             Screen->FastCombo(selframe[0], selframe[1]+8, selframe[2]+12+12*i, CMB_MENUSELECT, CS_MENUSELECT, 128);
  594.     }
  595.     if(Link->PressUp){
  596.         Game->PlaySound(SFX_MENU);
  597.         vars[0]--;
  598.         if(vars[0]<0)
  599.             vars[0] = numchoices-1;
  600.     }
  601.     else if(Link->PressDown){
  602.         Game->PlaySound(SFX_MENU);
  603.         vars[0]++;
  604.         if(vars[0]>=numchoices)
  605.             vars[0] = 0;
  606.     }
  607.     else if(Link->PressA){
  608.         Link->PressA = false;
  609.         Link->InputA = false;
  610.         Game->PlaySound(SFX_SELECT);
  611.         vars[1] = 1;
  612.     }
  613.     else if(Link->PressB&&cancel){
  614.         Link->PressB = false;
  615.         Link->InputB = false;
  616.         Game->PlaySound(SFX_CANCEL);
  617.         vars[0] = -1;
  618.         vars[1] = 1;
  619.     }
  620.     Link->PressStart = false;
  621.     Link->InputStart = false;
  622. }
  623.  
  624. bool CanSee(int X, int Y, int Dir, int Width, int X2, int Y2){
  625.     if(Dir==DIR_UP){
  626.         return (X2>=X-Width/2&&X2<=X+Width/2&&Y2<Y);
  627.     }
  628.     else if(Dir==DIR_DOWN){
  629.         return (X2>=X-Width/2&&X2<=X+Width/2&&Y2>Y);
  630.     }
  631.     else if(Dir==DIR_LEFT){
  632.         return (Y2>=Y-Width/2&&Y2<=Y+Width/2&&X2<X);
  633.     }
  634.     else if(Dir==DIR_RIGHT){
  635.         return (Y2>=Y-Width/2&&Y2<=Y+Width/2&&X2>X);
  636.     }
  637. }
  638.  
  639. int ReflectAngleH(int angle){
  640.     int VX = VectorX(10, angle);
  641.     int VY = VectorY(10, angle);
  642.     VX = -VX;
  643.     return Angle(0, 0, VX, VY);
  644. }
  645.  
  646. int ReflectAngleV(int angle){
  647.     int VX = VectorX(10, angle);
  648.     int VY = VectorY(10, angle);
  649.     VY = -VY;
  650.     return Angle(0, 0, VX, VY);
  651. }
  652.  
  653. int DrawDebug(int DebugArray){
  654.     for(int i=0; i<SizeOfArray(DebugArray); i++){
  655.         int y = i*8;
  656.         int op = 128;
  657.         if(Link->InputEx1)
  658.             op = 64;
  659.         Screen->DrawInteger(6, 0, y, FONT_Z3SMALL, 0x01, -1, -1, -1, DebugArray[i], 4, op);
  660.     }
  661. }
  662.  
  663. int DrawDebug(int DebugArray, int DebugStrings){
  664.     for(int i=0; i<SizeOfArray(DebugArray); i++){
  665.         int str = DebugStrings[i];
  666.         int x = SizeOfArray(str)*6+6;
  667.         int y = i*8;
  668.         int op = 128;
  669.         if(Link->InputEx1)
  670.             op = 64;
  671.         Screen->DrawString(6, 0, y, FONT_Z3SMALL, 0x01, -1, TF_NORMAL, str, op);
  672.         Screen->DrawInteger(6, x, y, FONT_Z3SMALL, 0x01, -1, -1, -1, DebugArray[i], 4, op);
  673.     }
  674. }
  675.  
  676. //Turns an LWeapon into an EWeapon
  677. eweapon LWeaponToEWeapon(lweapon a) {
  678.   eweapon b = Screen->CreateEWeapon(a->ID);
  679.   b->X = a->X;
  680.   b->Y = a->Y;
  681.   b->Z = a->Z;
  682.   b->Jump = a->Jump;
  683.   b->Extend = a->Extend;
  684.   b->TileWidth = a->TileWidth;
  685.   b->TileHeight = a->TileHeight;
  686.   b->HitWidth = a->HitWidth;
  687.   b->HitHeight = a->HitHeight;
  688.   b->HitZHeight = a->HitZHeight;
  689.   b->HitXOffset = a->HitXOffset;
  690.   b->HitYOffset = a->HitYOffset;
  691.   b->DrawXOffset = a->DrawXOffset;
  692.   b->DrawYOffset = a->DrawYOffset;
  693.   b->DrawZOffset = a->DrawZOffset;
  694.   b->Tile = a->Tile;
  695.   b->CSet = a->CSet;
  696.   b->DrawStyle = a->DrawStyle;
  697.   b->Dir = a->Dir;
  698.   b->OriginalTile = a->OriginalTile;
  699.   b->OriginalCSet = a->OriginalCSet;
  700.   b->FlashCSet = a->FlashCSet;
  701.   b->NumFrames = a->NumFrames;
  702.   b->Frame = a->Frame;
  703.   b->ASpeed = a->ASpeed;
  704.   b->Damage = a->Damage;
  705.   b->Step = a->Step;
  706.   b->Angle = a->Angle;
  707.   b->Angular = a->Angular;
  708.   b->CollDetection = a->CollDetection;
  709.   b->DeadState = a->DeadState;
  710.   b->Flash = a->Flash;
  711.   b->Flip = a->Flip;
  712.   for (int i = 0; i < 16; i++)
  713.     b->Misc[i] = a->Misc[i];
  714.   return b;
  715. }
  716.  
  717. //Turns an EWeapon into an LWeapon
  718. lweapon EWeaponToLWeapon(eweapon a) {
  719.   lweapon b = Screen->CreateLWeapon(a->ID);
  720.   b->X = a->X;
  721.   b->Y = a->Y;
  722.   b->Z = a->Z;
  723.   b->Jump = a->Jump;
  724.   b->Extend = a->Extend;
  725.   b->TileWidth = a->TileWidth;
  726.   b->TileHeight = a->TileHeight;
  727.   b->HitWidth = a->HitWidth;
  728.   b->HitHeight = a->HitHeight;
  729.   b->HitZHeight = a->HitZHeight;
  730.   b->HitXOffset = a->HitXOffset;
  731.   b->HitYOffset = a->HitYOffset;
  732.   b->DrawXOffset = a->DrawXOffset;
  733.   b->DrawYOffset = a->DrawYOffset;
  734.   b->DrawZOffset = a->DrawZOffset;
  735.   b->Tile = a->Tile;
  736.   b->CSet = a->CSet;
  737.   b->DrawStyle = a->DrawStyle;
  738.   b->Dir = a->Dir;
  739.   b->OriginalTile = a->OriginalTile;
  740.   b->OriginalCSet = a->OriginalCSet;
  741.   b->FlashCSet = a->FlashCSet;
  742.   b->NumFrames = a->NumFrames;
  743.   b->Frame = a->Frame;
  744.   b->ASpeed = a->ASpeed;
  745.   b->Damage = a->Damage;
  746.   b->Step = a->Step;
  747.   b->Angle = a->Angle;
  748.   b->Angular = a->Angular;
  749.   b->CollDetection = a->CollDetection;
  750.   b->DeadState = a->DeadState;
  751.   b->Flash = a->Flash;
  752.   b->Flip = a->Flip;
  753.   for (int i = 0; i < 16; i++)
  754.     b->Misc[i] = a->Misc[i];
  755.   return b;
  756. }
  757.  
  758. void SortLowestToHighestAndReturnOrder(int arrayold, int arrayorder){
  759.     int lowest = 214747;
  760.     int lowestindex = 0;
  761.     bool used[256];
  762.     for(int i=0; i<SizeOfArray(arrayorder); i++){
  763.         for(int j=0; j<SizeOfArray(arrayold); j++){
  764.             if(arrayold[j]<=lowest&&!used[j]){
  765.                 lowest = arrayold[j];
  766.                 lowestindex = j;
  767.             }
  768.         }
  769.         arrayorder[i] = lowestindex;
  770.         used[lowestindex] = true;
  771.         lowest = 214747;
  772.     }
  773. }
  774.  
  775. void PrintArray(int array){
  776.     int strarray[128];
  777.     for(int i=0; i<SizeOfArray(array); i++){
  778.         int strspacing[] = ", ";
  779.         int strval[8];
  780.         itoa(strval, array[i]);
  781.         strcat(strarray, strval);
  782.         strcat(strarray, strspacing);
  783.     }
  784.     Screen->DrawString(6, 128, 8, FONT_Z1, 0x01, 0x00, TF_CENTERED, strarray, 128);
  785. }
  786.  
  787. bool LineCollision(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4){
  788.     // Screen->Line(6, x1, y1, x2, y2, 0x01, 1, 0, 0, 0, 128);
  789.     // Screen->Line(6, x3, y3, x4, y4, 0x01, 1, 0, 0, 0, 128);
  790.     int x[4];
  791.     int y[4];
  792.     if(x1>x2){
  793.         x[0] = x2;
  794.         y[0] = y2;
  795.         x[1] = x1;
  796.         y[1] = y1;
  797.     }
  798.     else{
  799.         x[0] = x1;
  800.         y[0] = y1;
  801.         x[1] = x2;
  802.         y[1] = y2;
  803.     }
  804.     if(x3>x4){
  805.         x[2] = x4;
  806.         y[2] = y4;
  807.         x[3] = x3;
  808.         y[3] = y3;
  809.     }
  810.     else{
  811.         x[2] = x3;
  812.         y[2] = y3;
  813.         x[3] = x4;
  814.         y[3] = y4;
  815.     }
  816.     // x[0] = Min(x1, x2);
  817.     // y[0] = Min(y1, y2);
  818.     // x[1] = Max(x1, x2);
  819.     // y[1] = Max(y1, y2);
  820.     // x[2] = Min(x3, x4);
  821.     // y[2] = Min(y3, y4);
  822.     // x[3] = Max(x3, x4);
  823.     // y[3] = Max(y3, y4);
  824.     float risea = y[1]-y[0];
  825.     float runa = x[1]-x[0];
  826.     float riseb = y[3]-y[2];
  827.     float runb = x[3]-x[2];
  828.     int intersectx;
  829.     int intersecty;
  830.     float slopea;
  831.     float slopeb;
  832.     int startya;
  833.     int startyb;
  834.     if(Abs(runa)>0&&Abs(runb)>0){
  835.         slopea = risea/runa;
  836.         slopeb = riseb/runb;
  837.         startya = y[0]-(slopea*x[0]);
  838.         startyb = y[2]-(slopeb*x[2]);
  839.         if(slopea==slopeb)
  840.             return false;
  841.         //y = slopea*x+startya
  842.         //y = slopeb*x+startyb
  843.        
  844.         //slopea*x+startya = slopeb*x+startyb
  845.        
  846.         //startyb = slopeb*x-slopea*x+startyb
  847.        
  848.         //startya = (slopeb-slopea)*x+startyb
  849.        
  850.         //startya-startyb = (slopeb-slopea)*x
  851.        
  852.         //x = (startya-startyb)/(slopeb-slopea)
  853.        
  854.         intersectx = (startya-startyb)/(slopeb-slopea);
  855.         intersecty = slopea*intersectx+startya;
  856.         if(intersectx>=x[0]&&intersectx<=x[1]&&intersectx>=x[2]&&intersectx<=x[3]){
  857.             return true;
  858.         }
  859.     }
  860.     else{
  861.         int minxa = Min(x1, x2);
  862.         int minya = Min(y1, y2);
  863.         int maxxa = Max(x1, x2);
  864.         int maxya = Max(y1, y2);
  865.         int minxb = Min(x3, x4);
  866.         int minyb = Min(y3, y4);
  867.         int maxxb = Max(x3, x4);
  868.         int maxyb = Max(y3, y4);
  869.         if(Abs(runa)>0){
  870.             slopea = risea/runa;
  871.             startya = y[0]-(slopea*x[0]);
  872.             intersectx = x[2];
  873.             intersecty = startya+slopea*x[2];
  874.             if(minxa<=intersectx&&maxxa>=intersectx&&minyb<=intersecty&&maxyb>=intersecty)
  875.                 return true;
  876.         }
  877.         else if(Abs(runb)>0){
  878.             slopeb = riseb/runb;
  879.             startyb = y[2]-(slopeb*x[2]);
  880.             intersectx = x[0];
  881.             intersecty = startyb+slopeb*x[0];
  882.             if(minxb<=intersectx&&maxxb>=intersectx&&minya<=intersecty&&maxya>=intersecty)
  883.                 return true;
  884.         }
  885.         else if(x[0]==x[2]&&((minya<=maxyb&&minya>=minyb)||(minyb<=maxya&&minyb>=minya)))
  886.             return true;
  887.     }
  888.     return false;
  889. }
  890.  
  891. void DrawTileFix(int layer, int x, int y, int tile, int blockw, int blockh, int cset, int xscale, int yscale, int rx, int ry, int rangle, int flip, bool transparency, int opacity){
  892.     if(ScreenFlag(1, 4)&&layer==2)
  893.         layer = 1;
  894.     else if(ScreenFlag(1, 5)&&layer==3)
  895.         layer = 4;
  896.     Screen->DrawTile(layer, x, y, tile, blockw, blockh, cset, xscale, yscale, rx, ry, rangle, flip, transparency, opacity);
  897. }
  898.  
  899. void DrawComboFix(int layer, int x, int y, int combo, int w, int h, int cset, int xscale, int yscale, int rx, int ry, int rangle, int frame, int flip, bool transparency, int opacity){
  900.     if(ScreenFlag(1, 4)&&layer==2)
  901.         layer = 1;
  902.     else if(ScreenFlag(1, 5)&&layer==3)
  903.         layer = 4;
  904.     Screen->DrawCombo(layer, x, y, combo, w, h, cset, xscale, yscale, rx, ry, rangle, frame, flip, transparency, opacity);
  905. }
  906.  
  907. void FastTileFix(int layer, int x, int y, int tile, int cset, int opacity){
  908.     if(ScreenFlag(1, 4)&&layer==2)
  909.         layer = 1;
  910.     else if(ScreenFlag(1, 5)&&layer==3)
  911.         layer = 4;
  912.     Screen->FastTile(layer, x, y, tile, cset, opacity);
  913. }
  914.  
  915. void FastComboFix(int layer, int x, int y, int combo, int cset, int opacity){
  916.     if(ScreenFlag(1, 4)&&layer==2)
  917.         layer = 1;
  918.     else if(ScreenFlag(1, 5)&&layer==3)
  919.         layer = 4;
  920.     Screen->FastCombo(layer, x, y, combo, cset, opacity);
  921. }
  922.  
  923. //const int WORM_MAX_STEP = 10;
  924.  
  925. void DEATHWORM(int X, int Y, int WormX, int WormY){
  926.     int Length = SizeOfArray(WormX);
  927.     int OldX = WormX[0];
  928.     int OldY = WormY[0];
  929.     int Step = Floor(Distance(X, Y, WormX[0], WormY[0]));
  930.     if(Step>WORM_MAX_STEP){
  931.         for(int i=Length-1; i>0; i--){
  932.             WormX[i] = WormX[i-1];
  933.             WormY[i] = WormY[i-1];
  934.         }
  935.         WormX[0] = X;
  936.         WormY[0] = Y;
  937.     }
  938.     else if(Step>0){
  939.         for(int i=Length-1; i>Step; i--){
  940.             WormX[i] = WormX[i-Step];
  941.             WormY[i] = WormY[i-Step];
  942.         }
  943.         for(int i=0; i<=Step; i++){
  944.             WormX[i] = X+VectorX(i, Angle(X, Y, OldX, OldY));
  945.             WormY[i] = Y+VectorY(i, Angle(X, Y, OldX, OldY));
  946.         }
  947.     }
  948. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×