Advertisement
ZoriaRPG

3d Triangle Weapon Script

Apr 30th, 2019
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.21 KB | None | 0 0
  1. ffc script WeaponShooter{
  2.     void run(){
  3.         while(true){
  4.             eweapon e = CreateEWeaponAt(EW_SCRIPT10, this->X, this->Y);
  5.             e->UseSprite(13);
  6.             e->Step = 25;
  7.             e->Angular = true;
  8.             e->Angle = DegtoRad(Angle(this->X, this->Y, Link->X, Link->Y));
  9.             e->DrawYOffset = -1000;
  10.             e->Script = 1;
  11.             e->CollDetection = false;
  12.             Waitframes(120);
  13.            
  14.         }
  15.     }
  16. }
  17.  
  18. int VectorX3D(int distance, int yaw, int pitch){
  19.     return distance*Sin(pitch)*Cos(yaw);
  20. }
  21.  
  22. int VectorY3D(int distance, int yaw, int pitch){
  23.     return distance*Sin(pitch)*Sin(yaw);
  24. }
  25.  
  26. int VectorZ3D(int distance, int yaw, int pitch){
  27.     return distance*Cos(pitch);
  28. }
  29.  
  30. void RotateX3D(int angle, int cx, int cy, int cz){
  31.     for(int i=0; i<SizeOfArray(cx); i++){
  32.         int y = cy[i];
  33.         int z = cz[i];
  34.        
  35.         cy[i] = y * Cos(angle) - z * Sin(angle);
  36.         cz[i] = z * Cos(angle) + y * Sin(angle);
  37.     }
  38. }
  39.  
  40. void RotateY3D(int angle, int cx, int cy, int cz){
  41.     for(int i=0; i<SizeOfArray(cx); i++){
  42.         int x = cx[i];
  43.         int z = cz[i];
  44.        
  45.         cx[i] = x * Cos(angle) - z * Sin(angle);
  46.         cz[i] = z * Cos(angle) + x * Sin(angle);
  47.     }
  48. }
  49.  
  50. void RotateZ3D(int angle, int cx, int cy, int cz){
  51.     for(int i=0; i<SizeOfArray(cx); i++){
  52.         int x = cx[i];
  53.         int y = cy[i];
  54.        
  55.         cx[i] = x * Cos(angle) - y * Sin(angle);
  56.         cy[i] = y * Cos(angle) + x * Sin(angle);
  57.     }
  58. }
  59.  
  60. float LargeDistance3D(int x1, int y1, int z1, int x2, int y2, int z2){
  61.     int c1x = (x1+x2)/2;
  62.     int c1y = (y1+y2)/2;
  63.     int c2x = (x1+c1x)/2;
  64.     int c2y = (y1+c1y)/2;
  65.     int c3x = (x1+c2x)/2;
  66.     int c3y = (y1+c2y)/2;
  67.     int c1z = (z1+z2)/2;
  68.     int c2z = (z1+c1z)/2;
  69.     int c3z = (z1+c2z)/2;
  70.     int dX = x1-c3x;
  71.     int dY = y1-c3y;
  72.     int dZ = z1-c3z;
  73.     return Sqrt(dX*dX+dY*dY+dZ*dZ)*8;
  74. }
  75.  
  76. float AngleYaw(int X1, int Y1, int Z1, int X2, int Y2, int Z2){
  77.     int dX = X1-X2;
  78.     int dY = Y1-Y2;
  79.     int dZ = Z1-Z2;
  80.    
  81.     int yaw = RadtoDeg(ArcTan(dX, dZ));
  82.    
  83.     return yaw;
  84. }
  85.  
  86. float AnglePitch(int X1, int Y1, int Z1, int X2, int Y2, int Z2){
  87.     int dX = X1-X2;
  88.     int dY = Y1-Y2;
  89.     int dZ = Z1-Z2;
  90.    
  91.     float padj = Sqrt(dX*dX + dZ*dZ);
  92.     int pitch = RadtoDeg(ArcTan(padj, dY));
  93.    
  94.    
  95.     return pitch;
  96. }
  97.  
  98. eweapon script TrickyTriangles{
  99.     void run(){
  100.         int a1;
  101.         int a2;
  102.         int a3;
  103.        
  104.         int r1 = Choose(-1, 1);
  105.         int r2 = Choose(-1, 1);
  106.         int r3 = Choose(-1, 1);
  107.    
  108.         int scale = 32;
  109.        
  110.         Trace(this->OriginalTile);
  111.         while(true){
  112.             a1 = WrapDegrees(a1+r1);
  113.             a2 = WrapDegrees(a2+r2);
  114.             a3 = WrapDegrees(a3+r3);
  115.            
  116.             // a1 = -135;
  117.             // a2 = -60;
  118.            
  119.             //scale += 0.1;
  120.             DrawTriforce(this->X+8, this->Y+8, scale, a1, a2, a3);
  121.             if(this->X<-64||this->X>240+64||this->Y<-64||this->Y>160+64){
  122.                 this->DeadState = 0;
  123.                 Quit();
  124.             }
  125.             Waitframe();
  126.         }
  127.     }
  128.     void DrawTriforce(int x, int y, int scale, int r1, int r2, int r3){
  129.         int i; int j; int k;
  130.        
  131.         int triX[6];
  132.         int triY[6];
  133.         int triZ[6];
  134.         int triC[6];
  135.        
  136.         for(i=0; i<3; i++){
  137.             triX[i] = VectorX(scale, i*120-90);
  138.             triY[i] = VectorY(scale, i*120-90);
  139.             triZ[i] = -scale*0.25;
  140.            
  141.             triX[i+3] = VectorX(scale, i*120-90);
  142.             triY[i+3] = VectorY(scale, i*120-90);
  143.             triZ[i+3] = scale*0.25;
  144.         }
  145.        
  146.         RotateX3D(r1, triX, triY, triZ);
  147.         RotateY3D(r2, triX, triY, triZ);
  148.         RotateZ3D(r3, triX, triY, triZ);
  149.        
  150.         // for(i=0; i<6; i++){
  151.             // triX[i] += x;
  152.             // triY[i] += y;
  153.         //}
  154.        
  155.         // for(i=0; i<6; i++){
  156.             // Screen->DrawInteger(6, 0, i*8, FONT_Z1, 0x01, 0x0F, -1, -1, triX[i], 0, 128);
  157.             // Screen->DrawInteger(6, 64, i*8, FONT_Z1, 0x01, 0x0F, -1, -1, triY[i], 0, 128);
  158.             // Screen->DrawInteger(6, 128, i*8, FONT_Z1, 0x01, 0x0F, -1, -1, triZ[i], 0, 128);
  159.         // }
  160.        
  161.         // for(i=0; i<6; i++){
  162.             // triC[i] = GetTriforceVertexColor(triX[i], triY[i], triZ[i], scale);
  163.         // }
  164.        
  165.         DrawTriFace(x, y, triX, triY, triZ, triC, 0, 1, 2);
  166.         DrawTriFace(x, y, triX, triY, triZ, triC, 3, 4, 5);
  167.         DrawQuadFace(x, y, triX, triY, triZ, triC, 0, 1, 4, 3);
  168.         DrawQuadFace(x, y, triX, triY, triZ, triC, 1, 2, 5, 4);
  169.         DrawQuadFace(x, y, triX, triY, triZ, triC, 2, 0, 3, 5);
  170.         //Screen->Circle(6, x, y, 4, 0x01, 1, 0, 0, 0, true, 128);
  171.     }
  172.     void DrawTriFace(int x, int y, int xA, int yA, int zA, int cA, int p1, int p2, int p3){
  173.         int cZ = (zA[p1]+zA[p2]+zA[p3])/3;
  174.         if(cZ>0){
  175.             int cent[3];
  176.             cent[0] = (xA[p1]+xA[p2]+xA[p3])/4;
  177.             cent[1] = (yA[p1]+yA[p2]+yA[p3])/4;
  178.             cent[1] = (zA[p1]+zA[p2]+zA[p3])/4;
  179.             int c = 0x87;
  180.             //int pos[9] = {xA[p1],yA[p1],0,   xA[p2],yA[p2],0,   xA[p3],yA[p3],0};
  181.             int pos[9] = {x+xA[p1],y+yA[p1],zA[p1],   x+xA[p2],y+yA[p2],zA[p2],   x+xA[p3],y+yA[p3],zA[p3]};
  182.             int uv[6] = {0,15,   15,15,   0,7};
  183.             int csets[3] = {c,c,c};
  184.             //int csets[3] = {cA[p1], cA[p2], cA[p3]};
  185.             int size[2] = {1, 1};
  186.             Screen->Triangle3D(2, pos, uv, csets, size, 0, 0, PT_FLATSHADED);
  187.         }
  188.     }
  189.     void DrawQuadFace(int x, int y, int xA, int yA, int zA, int cA, int p1, int p2, int p3, int p4){
  190.         int cZ = (zA[p1]+zA[p2]+zA[p3]+zA[p4])/4;
  191.         if(cZ>0){
  192.             int cent[3];
  193.             cent[0] = (xA[p1]+xA[p2]+xA[p3]+xA[p4])/4;
  194.             cent[1] = (yA[p1]+yA[p2]+yA[p3]+yA[p4])/4;
  195.             cent[1] = (zA[p1]+zA[p2]+zA[p3]+zA[p4])/4;
  196.             int c = GetTriforceVertexColor(cent[0], cent[1], cent[2]);
  197.             int pos[12] = {x+xA[p1],y+yA[p1],zA[p1],   x+xA[p2],y+yA[p2],zA[p2],   x+xA[p3],y+yA[p3],zA[p3],   x+xA[p4],y+yA[p4],zA[p4]};
  198.             int uv[8] = {0,0,   15,0,   15,15,   0,15};
  199.             int csets[4] = {c,c,c,c};
  200.             //int csets[4] = {cA[p1], cA[p2], cA[p3], cA[p4]};
  201.             int size[2] = {1, 1};
  202.             Screen->Quad3D(2, pos, uv, csets, size, 0, 0, PT_FLATSHADED);
  203.         }
  204.     }
  205.     int GetTriforceVertexColor(int x, int y, int z){
  206.         int tX = -512;
  207.         int tY = -512;
  208.         int tZ = 512;
  209.         int tAng1 = AngleYaw(0, 0, 0, tX, tY, tZ);
  210.         int tAng2 = AnglePitch(0, 0, 0, tX, tY, tZ);
  211.        
  212.         int ang1 = AngleYaw(0, 0, 0, x, y, z);
  213.         int ang2 = AnglePitch(0, 0, 0, x, y, z);
  214.        
  215.         int diff1 = Abs(TriforceAngleDiff(ang1, tAng1))/(90/7);
  216.         int diff2 = Abs(TriforceAngleDiff(ang2, tAng2))/(90/7);
  217.        
  218.         int light = Clamp(Round(Sqrt(diff1*diff1 + diff2*diff2)), 0, 13);
  219.        
  220.         int c = 0x8E - light;
  221.         return c;
  222.     }
  223.     int TriforceAngleDiff(int a1, int a2){
  224.         // Get the difference between the two angles
  225.         float dif = WrapDegrees(a2) - WrapDegrees(a1);
  226.        
  227.         // Compensate for the difference being outside of normal bounds
  228.         if(dif >= 180)
  229.             dif -= 360;
  230.         else if(dif <= -180)
  231.             dif += 360;
  232.            
  233.         return dif;
  234.     }
  235. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement