Advertisement
ZoriaRPG

ZScript 3D Portal v0.5 (for ywkls)

May 14th, 2017
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 12.03 KB | None | 0 0
  1. //Warp Aperture Animation FFC
  2. //for ywkls, by ZoriaRPG
  3. //15th May, 201
  4. //v0.5
  5.  
  6. const int SCREEN_CENTRE_X = 128;
  7. const int SCREEN_CENTRE_Y = 88;
  8. const int CUBE_TEXT_TIMER_DUR = 200;
  9.  
  10. //General Warp Aperture Settings
  11. const int APERTURE_LAYER = 1;
  12. const int APERTURE_TILE_WIDTH = 6; 
  13. const int APERTURE_TILE_HEIGHT = 7;
  14. const float APERTURE_DEFAULT_OPEN_RATE = 0.3;
  15.  
  16. //Left Warp Aperture
  17. const int APERTURE_LEFT_X = 0;
  18. const int APERTURE_LEFT_Y = 0;
  19. const int APERTURE_LEFT_BASE_TILE = 15860;
  20. const int APERTURE_LEFT_CSET = 0;
  21. const int APERTURE_LEFT_XSCALE = -1;
  22. const int APERTURE_LEFT_YSCALE = -1;
  23. const int APERTURE_LEFT_RX = 0;
  24. const int APERTURE_LEFT_RY = 0;
  25. const int APERTURE_LEFT_RANGLE = 0;
  26. const int APERTURE_LEFT_FLIP = 0;
  27. const int APERTURE_LEFT_OPACITY = 64;
  28.  
  29. //Right Warp Aperture
  30.  
  31. const int APERTURE_RIGHT_X = 96;
  32. const int APERTURE_RIGHT_Y = 96;
  33. const int APERTURE_RIGHT_BASE_TILE = 15866;
  34. const int APERTURE_RIGHT_CSET = 0;
  35. const int APERTURE_RIGHT_XSCALE = -1;
  36. const int APERTURE_RIGHT_YSCALE = -1;
  37. const int APERTURE_RIGHT_RX = 0;
  38. const int APERTURE_RIGHT_RY = 0;
  39. const int APERTURE_RIGHT_RANGLE = 0;
  40. const int APERTURE_RIGHT_FLIP = 0;
  41. const int APERTURE_RIGHT_OPACITY = 128;
  42.  
  43. //Cube animation 2x2 tile textures (tile page 61)
  44. const int CUBE_TEX_1 = 16020;
  45. const int CUBE_TEX_2 = 16022;
  46. const int CUBE_TEX_3 = 16024;
  47. const int CUBE_TEX_4 = 16026;
  48. const int CUBE_TEX_5 = 16028;
  49.  
  50. const int CUBE_ROTATION_X_DEGREES = 1; //one degree of rotation per 'modulus' frames?
  51.  
  52. const int SFX_WARP_APERTURE_ACTIVATE = 0;
  53. const int SFX_WARP_APERTURE_OPEN = 0;
  54.  
  55. const int I_APERTURE = 0; //Require this item.
  56.  
  57. ffc script portal{
  58.     //degrees of rotation per 'modulus' frames
  59.     //time for cube rotational effect
  60.     //modulus value for 'ror_x'
  61.     //texture change timer
  62.     //pixels per frame that the aperture opens (this is a decimal value with a default of 0.3).
  63.     void run(int rot_x, int cubetimer, int modulus, int textime, int open_rate, int reg, int active_sound, int open_sound){
  64.         int rot[3]; //x, y, z angles.
  65.         //Warp Gate Aperture Values Array
  66.         int aperture_pos[18];   //0,1: left x, y;
  67.                     //2,3: right x,y,
  68.                     //4,5: left xscale, yscale;
  69.                     //6,7: right xscale, yscale
  70.                     //8,9,  left rx, ry
  71.                     //10, 11: right rx, ry
  72.                     //12, 13: left rangle, flip
  73.                     //14, 15: right rangle, flip
  74.        
  75.         if ( open_rate <= 0 ) { open_rate = APERTURE_DEFAULT_OPEN_RATE; }
  76.        
  77.         if ( active_sound <= 0 ) { active_sound = SFX_WARP_APERTURE_ACTIVATE; }
  78.         if ( open_sound <= 0 ) { open_sound = SFX_WARP_APERTURE_OPEN; }
  79.                
  80.         if ( rot_x <= 0 ) { rot_x = CUBE_ROTATION_X_DEGREES; }
  81.        
  82.         int cube[12]={SCREEN_CENTRE_X+30,SCREEN_CENTRE_Y+30, 1,  
  83.             SCREEN_CENTRE_X+30,SCREEN_CENTRE_Y-30, 1,
  84.             SCREEN_CENTRE_X-30,SCREEN_CENTRE_Y-30, 1,
  85.             SCREEN_CENTRE_X-30,SCREEN_CENTRE_Y+30, 1};
  86.            
  87.         int cube_uv[8]={0,0, 31,0, 31, 31, 31, 0}; //Texture coordinates.
  88.         //How mdo these work?
  89.         //!
  90.        
  91.         int cube_csets[4]={0,0,0,0}; //Csets
  92.        
  93.         int textures[10]={CUBE_TEX_1,CUBE_TEX_2,CUBE_TEX_3,CUBE_TEX_4,CUBE_TEX_5,CUBE_TEX_1,CUBE_TEX_2,CUBE_TEX_3,CUBE_TEX_4,CUBE_TEX_5}; //Holds textures.
  94.         int tex_state; //Which texture to use this frame.
  95.        
  96.         int cube_tex[2]={2,2}; //Texture size.
  97.        
  98.         //Draw each half of the aperture, using DrawTile, and slowly move them to open.
  99.        
  100.         int aperture_left_x; int aperture_right_x;
  101.         int aperture_timer;
  102.         int cube_rot_timer;
  103.         if ( modulus <= 0 ) modulus = 30;
  104.        
  105.         if ( cubetimer <= 0 ) cubetimer = 60000;
  106.         cube_rot_timer = cubetimer;
  107.        
  108.         if ( textime <= 0 ) textime = CUBE_TEXT_TIMER_DUR;
  109.  
  110.         //Cannot interact
  111.         while(!Link->Item[I_APERTURE] ] && I_APERTURE > 0 ) { //if a lockout item is required, check for it
  112.             //DrawTile(left side)
  113.                 //Move it left to open it
  114.             Screen->DrawTile(APERTURE_LAYER, ((APERTURE_RIGHT_X+aperture_pos[2])<<0), ((APERTURE_RIGHT_Y+aperture_pos[3])<<0),
  115.                 APERTURE_RIGHT_BASE_TILE, APERTURE_TILE_WIDTH, APERTURE_TILE_HEIGHT,
  116.                 APERTURE_RIGHT_CSET, ((APERTURE_RIGHT_XSCALE+aperture_pos[6])<<0), ((APERTURE_RIGHT_YSCALE+aperture_pos[7])<<0),
  117.                 ((APERTURE_RIGHT_RX+aperture_pos[10])), ((APERTURE_RIGHT_RY+aperture_pos[11])), ((APERTURE_RIGHT_RANGLE+aperture_pos[14])),
  118.                 ((APERTURE_RIGHT_FLIP+aperture_pos[15])<<0),
  119.                 true, ((APERTURE_RIGHT_OPACITY+aperture_pos[17])<<0));
  120.            
  121.             //DrawTile(right side)
  122.                 //move it right to open it
  123.             Screen->DrawTile(APERTURE_LAYER, ((APERTURE_LEFT_X+aperture_pos[0])<<0), ((APERTURE_LEFT_Y+aperture_pos[1])<<0),
  124.                 APERTURE_LEFT_BASE_TILE, APERTURE_TILE_WIDTH, APERTURE_TILE_HEIGHT,
  125.                 APERTURE_LEFT_CSET, ((APERTURE_LEFT_XSCALE+aperture_pos[4])<<0), ((APERTURE_LEFT_YSCALE+aperture_pos[5])<<0),
  126.                 ((APERTURE_LEFT_RX+aperture_pos[8])), ((APERTURE_LEFT_RY+aperture_pos[9])), ((APERTURE_LEFT_RANGLE+aperture_pos[12])),
  127.                 ((APERTURE_LEFT_FLIP+aperture_pos[13])<<0),
  128.                 true, ((APERTURE_LEFT_OPACITY+aperture_pos[16])<<0));
  129.             Waitframe();
  130.         }
  131.        
  132.         //Can interact, but has not activated.
  133.        
  134.         while(!Screen->D[reg]) {
  135.             //DrawTile(left side)
  136.                 //Move it left to open it
  137.             Screen->DrawTile(APERTURE_LAYER, ((APERTURE_RIGHT_X+aperture_pos[2])<<0), ((APERTURE_RIGHT_Y+aperture_pos[3])<<0),
  138.                 APERTURE_RIGHT_BASE_TILE, APERTURE_TILE_WIDTH, APERTURE_TILE_HEIGHT,
  139.                 APERTURE_RIGHT_CSET, ((APERTURE_RIGHT_XSCALE+aperture_pos[6])<<0), ((APERTURE_RIGHT_YSCALE+aperture_pos[7])<<0),
  140.                 ((APERTURE_RIGHT_RX+aperture_pos[10])), ((APERTURE_RIGHT_RY+aperture_pos[11])), ((APERTURE_RIGHT_RANGLE+aperture_pos[14])),
  141.                 ((APERTURE_RIGHT_FLIP+aperture_pos[15])<<0),
  142.                 true, ((APERTURE_RIGHT_OPACITY+aperture_pos[17])<<0));
  143.            
  144.             //DrawTile(right side)
  145.                 //move it right to open it
  146.             Screen->DrawTile(APERTURE_LAYER, ((APERTURE_LEFT_X+aperture_pos[0])<<0), ((APERTURE_LEFT_Y+aperture_pos[1])<<0),
  147.                 APERTURE_LEFT_BASE_TILE, APERTURE_TILE_WIDTH, APERTURE_TILE_HEIGHT,
  148.                 APERTURE_LEFT_CSET, ((APERTURE_LEFT_XSCALE+aperture_pos[4])<<0), ((APERTURE_LEFT_YSCALE+aperture_pos[5])<<0),
  149.                 ((APERTURE_LEFT_RX+aperture_pos[8])), ((APERTURE_LEFT_RY+aperture_pos[9])), ((APERTURE_LEFT_RANGLE+aperture_pos[12])),
  150.                 ((APERTURE_LEFT_FLIP+aperture_pos[13])<<0),
  151.                 true, ((APERTURE_LEFT_OPACITY+aperture_pos[16])<<0));
  152.            
  153.             if ( DistXY(this, max_dist) && Link->PressA ) {
  154.                 if ( active_sound ) Game->PlaySound(active_sound);
  155.                 Screen->D[reg] = 1;
  156.                 break;
  157.            
  158.             }
  159.             Waitframe();
  160.         }
  161.        
  162.         if ( open_sound ) Game->PlaySound(open_sound); //Play the aperture slide-open sound.
  163.        
  164.         //Start the aperture opening animation.
  165.         while(aperture_timer--){
  166.            
  167.             //Draw the aperture...
  168.            
  169.             //Left side...updating the positions every frame. Floored as we increment in decimals.
  170.             //Truncation here, is to avoid any glitch potential.
  171.            
  172.             //DrawTile(left side)
  173.                 //Move it left to open it
  174.             Screen->DrawTile(APERTURE_LAYER, ((APERTURE_RIGHT_X+aperture_pos[2])<<0), ((APERTURE_RIGHT_Y+aperture_pos[3])<<0),
  175.                 APERTURE_RIGHT_BASE_TILE, APERTURE_TILE_WIDTH, APERTURE_TILE_HEIGHT,
  176.                 APERTURE_RIGHT_CSET, ((APERTURE_RIGHT_XSCALE+aperture_pos[6])<<0), ((APERTURE_RIGHT_YSCALE+aperture_pos[7])<<0),
  177.                 ((APERTURE_RIGHT_RX+aperture_pos[10])), ((APERTURE_RIGHT_RY+aperture_pos[11])), ((APERTURE_RIGHT_RANGLE+aperture_pos[14])),
  178.                 ((APERTURE_RIGHT_FLIP+aperture_pos[15])<<0),
  179.                 true, ((APERTURE_RIGHT_OPACITY+aperture_pos[17])<<0));
  180.            
  181.             //DrawTile(right side)
  182.                 //move it right to open it
  183.             Screen->DrawTile(APERTURE_LAYER, ((APERTURE_LEFT_X+aperture_pos[0])<<0), ((APERTURE_LEFT_Y+aperture_pos[1])<<0),
  184.                 APERTURE_LEFT_BASE_TILE, APERTURE_TILE_WIDTH, APERTURE_TILE_HEIGHT,
  185.                 APERTURE_LEFT_CSET, ((APERTURE_LEFT_XSCALE+aperture_pos[4])<<0), ((APERTURE_LEFT_YSCALE+aperture_pos[5])<<0),
  186.                 ((APERTURE_LEFT_RX+aperture_pos[8])), ((APERTURE_LEFT_RY+aperture_pos[9])), ((APERTURE_LEFT_RANGLE+aperture_pos[12])),
  187.                 ((APERTURE_LEFT_FLIP+aperture_pos[13])<<0),
  188.                 true, ((APERTURE_LEFT_OPACITY+aperture_pos[16])<<0));
  189.            
  190.            
  191.             //Every frame, increase the aperture opening. This is a decimal increase, trhat is truncated, so that it opens in whole pixels.
  192.             //The decimal + truncation approach allows more freedom in timing.
  193.             openWarpAperture(aperture_pos, open_rate); //array, and opening rate in pixels per frame. Default is '0.3'.
  194.            
  195.             Waitframe();
  196.            
  197.         }
  198.        
  199.         //The aperture animation cycle is over, draw the cube...
  200.         while(aperture_timer <= 0 ){
  201.             if ( cube_rot_timer <= 0 ) {
  202.                 //Reset the timer for cube rotation base don if D1 was set.
  203.                 if ( cubetimer ) cube_rot_timer= 60000;
  204.                 else cube_rot_timer = cubetimer;
  205.             }
  206.             cube_timer--; //A monulus of this determines if we rotate the cube this frame.
  207.             //the aperture has opened.
  208.            
  209.            
  210.             //Draw both halves of the aperture in an open state.
  211.            
  212.             //DrawTile(left side)
  213.                 //Move it left to open it
  214.             Screen->DrawTile(APERTURE_LAYER, ((APERTURE_RIGHT_X+aperture_pos[2])<<0), ((APERTURE_RIGHT_Y+aperture_pos[3])<<0),
  215.                 APERTURE_RIGHT_BASE_TILE, APERTURE_TILE_WIDTH, APERTURE_TILE_HEIGHT,
  216.                 APERTURE_RIGHT_CSET, ((APERTURE_RIGHT_XSCALE+aperture_pos[6])<<0), ((APERTURE_RIGHT_YSCALE+aperture_pos[7])<<0),
  217.                 ((APERTURE_RIGHT_RX+aperture_pos[10])), ((APERTURE_RIGHT_RY+aperture_pos[11])), ((APERTURE_RIGHT_RANGLE+aperture_pos[14])),
  218.                 ((APERTURE_RIGHT_FLIP+aperture_pos[15])<<0),
  219.                 true, ((APERTURE_RIGHT_OPACITY+aperture_pos[17])<<0));
  220.            
  221.             //DrawTile(right side)
  222.                 //move it right to open it
  223.             Screen->DrawTile(APERTURE_LAYER, ((APERTURE_LEFT_X+aperture_pos[0])<<0), ((APERTURE_LEFT_Y+aperture_pos[1])<<0),
  224.                 APERTURE_LEFT_BASE_TILE, APERTURE_TILE_WIDTH, APERTURE_TILE_HEIGHT,
  225.                 APERTURE_LEFT_CSET, ((APERTURE_LEFT_XSCALE+aperture_pos[4])<<0), ((APERTURE_LEFT_YSCALE+aperture_pos[5])<<0),
  226.                 ((APERTURE_LEFT_RX+aperture_pos[8])), ((APERTURE_LEFT_RY+aperture_pos[9])), ((APERTURE_LEFT_RANGLE+aperture_pos[12])),
  227.                 ((APERTURE_LEFT_FLIP+aperture_pos[13])<<0),
  228.                 true, ((APERTURE_LEFT_OPACITY+aperture_pos[16])<<0));
  229.             //Handle texture change timer.
  230.            
  231.             if ( textime > 0 ) { textime--; } //Tick off the texture timer.
  232.            
  233.             else {      //The timer has elapsed.
  234.                 if ( this->InitD[3] <= 0 ) textime = CUBE_TEXT_TIMER_DUR;
  235.                 else textime = this->InitD[3];
  236.  
  237.                 //Advance the array texture.
  238.                
  239.                 if ( tex_state < 9 ) { tex_state++; }
  240.                 else tex_state = 0; //Wrap to index 0.
  241.             }
  242.            
  243.             //Decide if we rotate the cube:
  244.            
  245.             if ( cube_rot_timer != cubetimer && cube_rot_timer % modulus == 0 ) {
  246.                 //if this is not the initial frame, check if the rotation
  247.                 //timer modulus. Defualt move every 30 frames.
  248.                
  249.                 //Do rotational effect to cube[]
  250.                 ___RotateQuad3D_X(rot_x, cube);
  251.             }
  252.            
  253.             //Draw the cube.
  254.            
  255.             Screen->Quad3D(3,cube,cube_uv, cube_csets,cube_tex, 0, textures[tex_state], 0);
  256.        
  257.            
  258.             //! Do we do anything fancy for warping on collision with the cube??
  259.             //! If som i=t goes here.
  260.            
  261.             Waitframe();
  262.  
  263.            
  264.         }
  265.     }
  266.     void ___RotateQuad3D_X(int angle, int pos} {
  267.         //int cx, int cy, int cz){
  268.         for(int i=0; i<3; i++){
  269.             int y = pos[(i*3)+1];
  270.             int z = pos[(i*3)+2];
  271.            
  272.             pos[(i*3)+1] = y * Cos(angle) - z * Sin(angle);
  273.             pos[(i*3)+2] = z * Cos(angle) + y * Sin(angle);
  274.         }
  275.     }
  276.     //'amount' should be positive to open, negative to close.
  277.     void openWarpAperture(int aperture_pos, int amount){
  278.         aperture_pos[0]-=amount;
  279.         aperture_pos[2]+= amount;
  280.     }
  281.    
  282.     void ___RotateQuad3D_Y(int angle, int pos){
  283.         for(int i=0; i<3; i++){
  284.             int x = pos[i*3];
  285.             int z = pos[(i*3)+2];
  286.            
  287.             pos[i*3] = x * Cos(angle) - z * Sin(angle);
  288.             pos[(i*3)+2] = z * Cos(angle) + x * Sin(angle);
  289.  
  290.  
  291.  
  292.             }
  293.     }
  294.  
  295.     void ___RotateQuad3D_Z(int angle, int cx, int cy, int cz){
  296.         for(int i=0; i<3 i++){
  297.             int x = pos[i*3];
  298.             int y = pos[(i*3)+1];
  299.            
  300.             pos[i*3] = x * Cos(angle) - y * Sin(angle);
  301.             pos[(i*3)+1] = y * Cos(angle) + x * Sin(angle);
  302.         }
  303.     }
  304. }
  305.  
  306.  
  307. /*
  308.            
  309.         //Find a free bitmap to use
  310.        
  311.         //We want a circle of shimmering blue and white
  312.        
  313.         //We want some tiles copies to it
  314.        
  315.         //We need to make the area around it translucent.
  316.        
  317.         //Triangle 3D might do better?
  318.        
  319.         //Or a cube?
  320.        
  321.        
  322.        
  323. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement