Advertisement
ZoriaRPG

ZScript 3D Portal v0.2 (for ywkls)

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