Advertisement
ZoriaRPG

ZScript 3D Portal v0.3 (for ywkls)

May 14th, 2017
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.80 KB | None | 0 0
  1. //Warp Aperature Animation FFC
  2. //for ywkls, by ZoriaRPG
  3. //14th May, 201
  4. //v0.2
  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 Aperature Settings
  11. const int APERATURE_LAYER = 1;
  12. const int APERATURE_TILE_WIDTH = 6;
  13. const int APERATURE_TILE_HEIGHT = 7;
  14. const float APERATURE_DEFAULT_OPEN_RATE = 0.3;
  15.  
  16. //Left Warp Aperature
  17. const int APERATURE_LEFT_X = 0;
  18. const int APERATURE_LEFT_Y = 0;
  19. const int APERATURE_LEFT_BASE_TILE = 15860;
  20. const int APERATURE_LEFT_CSET = 0;
  21. const int APERATURE_LEFT_XSCALE = -1;
  22. const int APERATURE_LEFT_YSCALE = -1;
  23. const int APERATURE_LEFT_RX = 0;
  24. const int APERATURE_LEFT_RY = 0;
  25. const int APERATURE_LEFT_RANGLE = 0;
  26. const int APERATURE_LEFT_FLIP = 0;
  27. const int APERATURE_LEFT_OPACITY = 64;
  28.  
  29. //Right Warp Aperature
  30.  
  31. const int APERATURE_RIGHT_X = 96;
  32. const int APERATURE_RIGHT_Y = 96;
  33. const int APERATURE_RIGHT_BASE_TILE = 15866;
  34. const int APERATURE_RIGHT_CSET = 0;
  35. const int APERATURE_RIGHT_XSCALE = -1;
  36. const int APERATURE_RIGHT_YSCALE = -1;
  37. const int APERATURE_RIGHT_RX = 0;
  38. const int APERATURE_RIGHT_RY = 0;
  39. const int APERATURE_RIGHT_RANGLE = 0;
  40. const int APERATURE_RIGHT_FLIP = 0;
  41. const int APERATURE_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. ffc script portal{
  53.     //degrees of rotation per 'modulus' frames
  54.     //time for cube rotational effect
  55.     //modulus value for 'ror_x'
  56.     //texture change timer
  57.     //pixels per frame that the aperature opens (this is a decimal value with a default of 0.3).
  58.     void run(int rot_x, int cubetimer, int modulus, int textime, int open_rate){
  59.         int rot[3]; //x, y, z angles.
  60.         //Warp Gate Aperature Values Array
  61.         int aperature_pos[18];  //0,1: left x, y;
  62.                     //2,3: right x,y,
  63.                     //4,5: left xscale, yscale;
  64.                     //6,7: right xscale, yscale
  65.                     //8,9,  left rx, ry
  66.                     //10, 11: right rx, ry
  67.                     //12, 13: left rangle, flip
  68.                     //14, 15: right rangle, flip
  69.        
  70.         if ( open_rate <= 0 ) { open_rate = APERATURE_DEFAULT_OPEN_RATE; }
  71.                
  72.         if ( rot_x <= 0 ) { rot_x = CUBE_ROTATION_X_DEGREES; }
  73.        
  74.         int cube[12]={SCREEN_CENTRE_X+30,SCREEN_CENTRE_Y+30, 1,  
  75.             SCREEN_CENTRE_X+30,SCREEN_CENTRE_Y-30, 1,
  76.             SCREEN_CENTRE_X-30,SCREEN_CENTRE_Y-30, 1,
  77.             SCREEN_CENTRE_X-30,SCREEN_CENTRE_Y+30, 1};
  78.            
  79.         int cube_uv[8]={0,0, 31,0, 31, 31, 31, 0}; //Texture coordinates.
  80.         //How mdo these work?
  81.         //!
  82.        
  83.         int cube_csets[4]={0,0,0,0}; //Csets
  84.        
  85.         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.
  86.         int tex_state; //Which texture to use this frame.
  87.        
  88.         int cube_tex[2]={2,2}; //Texture size.
  89.        
  90.         //Draw each half of the aperature, using DrawTile, and slowly move them to open.
  91.        
  92.         int aperature_left_x; int aperature_right_x;
  93.         int aperature_timer;
  94.         int cube_rot_timer;
  95.         if ( modulus <= 0 ) modulus = 30;
  96.        
  97.         if ( cubetimer <= 0 ) cubetimer = 60000;
  98.         cube_rot_timer = cubetimer;
  99.        
  100.         if ( textime <= 0 ) textime = CUBE_TEXT_TIMER_DUR;
  101.        
  102.         //Start the aperature opening animation.
  103.         while(aperature_timer--){
  104.            
  105.             //Draw the aperature...
  106.            
  107.             //Left side...updating the positions every frame. Floored as we increment in decimals.
  108.             //Truncation here, is to avoid any glitch potential.
  109.            
  110.             //DrawTile(left side)
  111.                 //Move it left to open it
  112.             Screen->DrawTile(APERATURE_LAYER, ((APERATURE_RIGHT_X+aperature_pos[2])<<0), ((APERATURE_RIGHT_Y+aperature_pos[3])<<0),
  113.                 APERATURE_RIGHT_BASE_TILE, APERATURE_TILE_WIDTH, APERATURE_TILE_HEIGHT,
  114.                 APERATURE_RIGHT_CSET, ((APERATURE_RIGHT_XSCALE+aperature_pos[6])<<0), ((APERATURE_RIGHT_YSCALE+aperature_pos[7])<<0),
  115.                 ((APERATURE_RIGHT_RX+aperature_pos[10])), ((APERATURE_RIGHT_RY+aperature_pos[11])), ((APERATURE_RIGHT_RANGLE+aperature_pos[14])),
  116.                 ((APERATURE_RIGHT_FLIP+aperature_pos[15])<<0),
  117.                 true, ((APERATURE_RIGHT_OPACITY+aperature_pos[17])<<));
  118.            
  119.             //DrawTile(right side)
  120.                 //move it right to open it
  121.             Screen->DrawTile(APERATURE_LAYER, ((APERATURE_LEFT_X+aperature_pos[0])<<0), ((APERATURE_LEFT_Y+aperature_pos[1])<<0),
  122.                 APERATURE_LEFT_BASE_TILE, APERATURE_TILE_WIDTH, APERATURE_TILE_HEIGHT,
  123.                 APERATURE_LEFT_CSET, ((APERATURE_LEFT_XSCALE+aperature_pos[4])<<0), ((APERATURE_LEFT_YSCALE+aperature_pos[5])<<0),
  124.                 ((APERATURE_LEFT_RX+aperature_pos[8])), ((APERATURE_LEFT_RY+aperature_pos[9])), ((APERATURE_LEFT_RANGLE+aperature_pos[12])),
  125.                 ((APERATURE_LEFT_FLIP+aperature_pos[13])<<0),
  126.                 true, APERATURE_LEFT_OPACITY+aperature_pos[16]);
  127.            
  128.            
  129.             //Every frame, increase the aperature opening. This is a decimal increase, trhat is truncated, so that it opens in whole pixels.
  130.             //The decimal + truncation approach allows more freedom in timing.
  131.             openWarpAperature(aperature_pos, open_rate); //array, and opening rate in pixels per frame. Default is '0.3'.
  132.            
  133.             Waitframe();
  134.            
  135.         }
  136.        
  137.         //The aperature animation cycle is over, draw the cube...
  138.         while(aperature_timer <= 0 ){
  139.             if ( cube_rot_timer <= 0 ) {
  140.                 //Reset the timer for cube rotation base don if D1 was set.
  141.                 if ( cubetimer ) cube_rot_timer= 60000;
  142.                 else cube_rot_timer = cubetimer;
  143.             }
  144.             cube_timer--; //A monulus of this determines if we rotate the cube this frame.
  145.             //the aperature has opened.
  146.            
  147.            
  148.             //Draw both halves of the aperature in an open state.
  149.            
  150.             //Left Side.
  151.             Screen->DrawTile(APERATURE_LAYER, APERATURE_RIGHT_X+aperature_pos[2], APERATURE_RIGHT_Y+aperature_pos[3],
  152.                 APERATURE_RIGHT_BASE_TILE, APERATURE_TILE_WIDTH, APERATURE_TILE_HEIGHT,
  153.                 APERATURE_RIGHT_CSET, APERATURE_RIGHT_XSCALE+aperature_pos[6], APERATURE_RIGHT_YSCALE+aperature_pos[7],
  154.                 APERATURE_RIGHT_RX+aperature_pos[10], APERATURE_RIGHT_RY+aperature_pos[11], APERATURE_RIGHT_RANGLE+aperature_pos[14],
  155.                 APERATURE_RIGHT_FLIP+aperature_pos[15],
  156.                 true, APERATURE_RIGHT_OPACITY+aperature_pos[17]);
  157.  
  158.             //Right Side.
  159.             Screen->DrawTile(APERATURE_LAYER, APERATURE_LEFT_X+aperature_pos[0], APERATURE_LEFT_Y+aperature_pos[1],
  160.                 APERATURE_LEFT_BASE_TILE, APERATURE_TILE_WIDTH, APERATURE_TILE_HEIGHT,
  161.                 APERATURE_LEFT_CSET, APERATURE_LEFT_XSCALE+aperature_pos[4], APERATURE_LEFT_YSCALE+aperature_pos[5],
  162.                 APERATURE_LEFT_RX+aperature_pos[8], APERATURE_LEFT_RY+aperature_pos[9], APERATURE_LEFT_RANGLE+aperature_pos[12],
  163.                 APERATURE_LEFT_FLIP+aperature_pos[13],
  164.                 true, APERATURE_LEFT_OPACITY+aperature_pos[16]);
  165.            
  166.             //Handle texture change timer.
  167.            
  168.             if ( textime > 0 ) { textime--; } //Tick off the texture timer.
  169.            
  170.             else {      //The timer has elapsed.
  171.                 if ( this->InitD[3] <= 0 ) textime = CUBE_TEXT_TIMER_DUR;
  172.                 else textime = this->InitD[3];
  173.  
  174.                 //Advance the array texture.
  175.                
  176.                 if ( tex_state < 9 ) { tex_state++; }
  177.                 else tex_state = 0; //Wrap to index 0.
  178.             }
  179.            
  180.             //Decide if we rotate the cube:
  181.            
  182.             if ( cube_rot_timer != cubetimer && cube_rot_timer % modulus == 0 ) {
  183.                 //if this is not the initial frame, check if the rotation
  184.                 //timer modulus. Defualt move every 30 frames.
  185.                
  186.                 //Do rotational effect to cube[]
  187.                 ___RotateQuad3D_X(rot_x, cube);
  188.             }
  189.            
  190.             //Draw the cube.
  191.            
  192.             Screen->Quad3D(3,cube,cube_uv, cube_csets,cube_tex, 0, textures[tex_state], 0);
  193.        
  194.            
  195.             //! Do we do anything fancy for warping on collision with the cube??
  196.             //! If som i=t goes here.
  197.            
  198.             Waitframe();
  199.  
  200.            
  201.         }
  202.     }
  203.     void ___RotateQuad3D_X(int angle, int pos} {
  204.         //int cx, int cy, int cz){
  205.         for(int i=0; i<3; i++){
  206.             int y = pos[(i*3)+1];
  207.             int z = pos[(i*3)+2];
  208.            
  209.             pos[(i*3)+1] = y * Cos(angle) - z * Sin(angle);
  210.             pos[(i*3)+2] = z * Cos(angle) + y * Sin(angle);
  211.         }
  212.     }
  213.     //'amount' should be positive to open, negative to close.
  214.     void openWarpAperature(int aperature_pos, int amount){
  215.         aperature_pos[0]-=amount;
  216.         aperature_pos[2]+= amount;
  217.     }
  218.    
  219.     void ___RotateQuad3D_Y(int angle, int pos){
  220.         for(int i=0; i<3; i++){
  221.             int x = pos[i*3];
  222.             int z = pos[(i*3)+2];
  223.            
  224.             pos[i*3] = x * Cos(angle) - z * Sin(angle);
  225.             pos[(i*3)+2] = z * Cos(angle) + x * Sin(angle);
  226.  
  227.  
  228.  
  229.             }
  230.     }
  231.  
  232.     void ___RotateQuad3D_Z(int angle, int cx, int cy, int cz){
  233.         for(int i=0; i<3 i++){
  234.             int x = pos[i*3];
  235.             int y = pos[(i*3)+1];
  236.            
  237.             pos[i*3] = x * Cos(angle) - y * Sin(angle);
  238.             pos[(i*3)+1] = y * Cos(angle) + x * Sin(angle);
  239.         }
  240.     }
  241. }
  242.  
  243.  
  244. /*
  245.            
  246.         //Find a free bitmap to use
  247.        
  248.         //We want a circle of shimmering blue and white
  249.        
  250.         //We want some tiles copies to it
  251.        
  252.         //We need to make the area around it translucent.
  253.        
  254.         //Triangle 3D might do better?
  255.        
  256.         //Or a cube?
  257.        
  258.        
  259.        
  260. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement