Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Warp Aperture Animation FFC
- //for ywkls, by ZoriaRPG
- //15th May, 201
- //v0.5
- const int SCREEN_CENTRE_X = 128;
- const int SCREEN_CENTRE_Y = 88;
- const int CUBE_TEXT_TIMER_DUR = 200;
- //General Warp Aperture Settings
- const int APERTURE_LAYER = 1;
- const int APERTURE_TILE_WIDTH = 6;
- const int APERTURE_TILE_HEIGHT = 7;
- const float APERTURE_DEFAULT_OPEN_RATE = 0.3;
- //Left Warp Aperture
- const int APERTURE_LEFT_X = 0;
- const int APERTURE_LEFT_Y = 0;
- const int APERTURE_LEFT_BASE_TILE = 15860;
- const int APERTURE_LEFT_CSET = 0;
- const int APERTURE_LEFT_XSCALE = -1;
- const int APERTURE_LEFT_YSCALE = -1;
- const int APERTURE_LEFT_RX = 0;
- const int APERTURE_LEFT_RY = 0;
- const int APERTURE_LEFT_RANGLE = 0;
- const int APERTURE_LEFT_FLIP = 0;
- const int APERTURE_LEFT_OPACITY = 64;
- //Right Warp Aperture
- const int APERTURE_RIGHT_X = 96;
- const int APERTURE_RIGHT_Y = 96;
- const int APERTURE_RIGHT_BASE_TILE = 15866;
- const int APERTURE_RIGHT_CSET = 0;
- const int APERTURE_RIGHT_XSCALE = -1;
- const int APERTURE_RIGHT_YSCALE = -1;
- const int APERTURE_RIGHT_RX = 0;
- const int APERTURE_RIGHT_RY = 0;
- const int APERTURE_RIGHT_RANGLE = 0;
- const int APERTURE_RIGHT_FLIP = 0;
- const int APERTURE_RIGHT_OPACITY = 128;
- //Cube animation 2x2 tile textures (tile page 61)
- const int CUBE_TEX_1 = 16020;
- const int CUBE_TEX_2 = 16022;
- const int CUBE_TEX_3 = 16024;
- const int CUBE_TEX_4 = 16026;
- const int CUBE_TEX_5 = 16028;
- const int CUBE_ROTATION_X_DEGREES = 1; //one degree of rotation per 'modulus' frames?
- const int SFX_WARP_APERTURE_ACTIVATE = 0;
- const int SFX_WARP_APERTURE_OPEN = 0;
- const int I_APERTURE = 0; //Require this item.
- ffc script portal{
- //degrees of rotation per 'modulus' frames
- //time for cube rotational effect
- //modulus value for 'ror_x'
- //texture change timer
- //pixels per frame that the aperture opens (this is a decimal value with a default of 0.3).
- void run(int rot_x, int cubetimer, int modulus, int textime, int open_rate, int reg, int active_sound, int open_sound){
- int rot[3]; //x, y, z angles.
- //Warp Gate Aperture Values Array
- int aperture_pos[18]; //0,1: left x, y;
- //2,3: right x,y,
- //4,5: left xscale, yscale;
- //6,7: right xscale, yscale
- //8,9, left rx, ry
- //10, 11: right rx, ry
- //12, 13: left rangle, flip
- //14, 15: right rangle, flip
- if ( open_rate <= 0 ) { open_rate = APERTURE_DEFAULT_OPEN_RATE; }
- if ( active_sound <= 0 ) { active_sound = SFX_WARP_APERTURE_ACTIVATE; }
- if ( open_sound <= 0 ) { open_sound = SFX_WARP_APERTURE_OPEN; }
- if ( rot_x <= 0 ) { rot_x = CUBE_ROTATION_X_DEGREES; }
- int cube[12]={SCREEN_CENTRE_X+30,SCREEN_CENTRE_Y+30, 1,
- SCREEN_CENTRE_X+30,SCREEN_CENTRE_Y-30, 1,
- SCREEN_CENTRE_X-30,SCREEN_CENTRE_Y-30, 1,
- SCREEN_CENTRE_X-30,SCREEN_CENTRE_Y+30, 1};
- int cube_uv[8]={0,0, 31,0, 31, 31, 31, 0}; //Texture coordinates.
- //How mdo these work?
- //!
- int cube_csets[4]={0,0,0,0}; //Csets
- 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.
- int tex_state; //Which texture to use this frame.
- int cube_tex[2]={2,2}; //Texture size.
- //Draw each half of the aperture, using DrawTile, and slowly move them to open.
- int aperture_left_x; int aperture_right_x;
- int aperture_timer;
- int cube_rot_timer;
- if ( modulus <= 0 ) modulus = 30;
- if ( cubetimer <= 0 ) cubetimer = 60000;
- cube_rot_timer = cubetimer;
- if ( textime <= 0 ) textime = CUBE_TEXT_TIMER_DUR;
- //Cannot interact
- while(!Link->Item[I_APERTURE] ] && I_APERTURE > 0 ) { //if a lockout item is required, check for it
- //DrawTile(left side)
- //Move it left to open it
- Screen->DrawTile(APERTURE_LAYER, ((APERTURE_RIGHT_X+aperture_pos[2])<<0), ((APERTURE_RIGHT_Y+aperture_pos[3])<<0),
- APERTURE_RIGHT_BASE_TILE, APERTURE_TILE_WIDTH, APERTURE_TILE_HEIGHT,
- APERTURE_RIGHT_CSET, ((APERTURE_RIGHT_XSCALE+aperture_pos[6])<<0), ((APERTURE_RIGHT_YSCALE+aperture_pos[7])<<0),
- ((APERTURE_RIGHT_RX+aperture_pos[10])), ((APERTURE_RIGHT_RY+aperture_pos[11])), ((APERTURE_RIGHT_RANGLE+aperture_pos[14])),
- ((APERTURE_RIGHT_FLIP+aperture_pos[15])<<0),
- true, ((APERTURE_RIGHT_OPACITY+aperture_pos[17])<<0));
- //DrawTile(right side)
- //move it right to open it
- Screen->DrawTile(APERTURE_LAYER, ((APERTURE_LEFT_X+aperture_pos[0])<<0), ((APERTURE_LEFT_Y+aperture_pos[1])<<0),
- APERTURE_LEFT_BASE_TILE, APERTURE_TILE_WIDTH, APERTURE_TILE_HEIGHT,
- APERTURE_LEFT_CSET, ((APERTURE_LEFT_XSCALE+aperture_pos[4])<<0), ((APERTURE_LEFT_YSCALE+aperture_pos[5])<<0),
- ((APERTURE_LEFT_RX+aperture_pos[8])), ((APERTURE_LEFT_RY+aperture_pos[9])), ((APERTURE_LEFT_RANGLE+aperture_pos[12])),
- ((APERTURE_LEFT_FLIP+aperture_pos[13])<<0),
- true, ((APERTURE_LEFT_OPACITY+aperture_pos[16])<<0));
- Waitframe();
- }
- //Can interact, but has not activated.
- while(!Screen->D[reg]) {
- //DrawTile(left side)
- //Move it left to open it
- Screen->DrawTile(APERTURE_LAYER, ((APERTURE_RIGHT_X+aperture_pos[2])<<0), ((APERTURE_RIGHT_Y+aperture_pos[3])<<0),
- APERTURE_RIGHT_BASE_TILE, APERTURE_TILE_WIDTH, APERTURE_TILE_HEIGHT,
- APERTURE_RIGHT_CSET, ((APERTURE_RIGHT_XSCALE+aperture_pos[6])<<0), ((APERTURE_RIGHT_YSCALE+aperture_pos[7])<<0),
- ((APERTURE_RIGHT_RX+aperture_pos[10])), ((APERTURE_RIGHT_RY+aperture_pos[11])), ((APERTURE_RIGHT_RANGLE+aperture_pos[14])),
- ((APERTURE_RIGHT_FLIP+aperture_pos[15])<<0),
- true, ((APERTURE_RIGHT_OPACITY+aperture_pos[17])<<0));
- //DrawTile(right side)
- //move it right to open it
- Screen->DrawTile(APERTURE_LAYER, ((APERTURE_LEFT_X+aperture_pos[0])<<0), ((APERTURE_LEFT_Y+aperture_pos[1])<<0),
- APERTURE_LEFT_BASE_TILE, APERTURE_TILE_WIDTH, APERTURE_TILE_HEIGHT,
- APERTURE_LEFT_CSET, ((APERTURE_LEFT_XSCALE+aperture_pos[4])<<0), ((APERTURE_LEFT_YSCALE+aperture_pos[5])<<0),
- ((APERTURE_LEFT_RX+aperture_pos[8])), ((APERTURE_LEFT_RY+aperture_pos[9])), ((APERTURE_LEFT_RANGLE+aperture_pos[12])),
- ((APERTURE_LEFT_FLIP+aperture_pos[13])<<0),
- true, ((APERTURE_LEFT_OPACITY+aperture_pos[16])<<0));
- if ( DistXY(this, max_dist) && Link->PressA ) {
- if ( active_sound ) Game->PlaySound(active_sound);
- Screen->D[reg] = 1;
- break;
- }
- Waitframe();
- }
- if ( open_sound ) Game->PlaySound(open_sound); //Play the aperture slide-open sound.
- //Start the aperture opening animation.
- while(aperture_timer--){
- //Draw the aperture...
- //Left side...updating the positions every frame. Floored as we increment in decimals.
- //Truncation here, is to avoid any glitch potential.
- //DrawTile(left side)
- //Move it left to open it
- Screen->DrawTile(APERTURE_LAYER, ((APERTURE_RIGHT_X+aperture_pos[2])<<0), ((APERTURE_RIGHT_Y+aperture_pos[3])<<0),
- APERTURE_RIGHT_BASE_TILE, APERTURE_TILE_WIDTH, APERTURE_TILE_HEIGHT,
- APERTURE_RIGHT_CSET, ((APERTURE_RIGHT_XSCALE+aperture_pos[6])<<0), ((APERTURE_RIGHT_YSCALE+aperture_pos[7])<<0),
- ((APERTURE_RIGHT_RX+aperture_pos[10])), ((APERTURE_RIGHT_RY+aperture_pos[11])), ((APERTURE_RIGHT_RANGLE+aperture_pos[14])),
- ((APERTURE_RIGHT_FLIP+aperture_pos[15])<<0),
- true, ((APERTURE_RIGHT_OPACITY+aperture_pos[17])<<0));
- //DrawTile(right side)
- //move it right to open it
- Screen->DrawTile(APERTURE_LAYER, ((APERTURE_LEFT_X+aperture_pos[0])<<0), ((APERTURE_LEFT_Y+aperture_pos[1])<<0),
- APERTURE_LEFT_BASE_TILE, APERTURE_TILE_WIDTH, APERTURE_TILE_HEIGHT,
- APERTURE_LEFT_CSET, ((APERTURE_LEFT_XSCALE+aperture_pos[4])<<0), ((APERTURE_LEFT_YSCALE+aperture_pos[5])<<0),
- ((APERTURE_LEFT_RX+aperture_pos[8])), ((APERTURE_LEFT_RY+aperture_pos[9])), ((APERTURE_LEFT_RANGLE+aperture_pos[12])),
- ((APERTURE_LEFT_FLIP+aperture_pos[13])<<0),
- true, ((APERTURE_LEFT_OPACITY+aperture_pos[16])<<0));
- //Every frame, increase the aperture opening. This is a decimal increase, trhat is truncated, so that it opens in whole pixels.
- //The decimal + truncation approach allows more freedom in timing.
- openWarpAperture(aperture_pos, open_rate); //array, and opening rate in pixels per frame. Default is '0.3'.
- Waitframe();
- }
- //The aperture animation cycle is over, draw the cube...
- while(aperture_timer <= 0 ){
- if ( cube_rot_timer <= 0 ) {
- //Reset the timer for cube rotation base don if D1 was set.
- if ( cubetimer ) cube_rot_timer= 60000;
- else cube_rot_timer = cubetimer;
- }
- cube_timer--; //A monulus of this determines if we rotate the cube this frame.
- //the aperture has opened.
- //Draw both halves of the aperture in an open state.
- //DrawTile(left side)
- //Move it left to open it
- Screen->DrawTile(APERTURE_LAYER, ((APERTURE_RIGHT_X+aperture_pos[2])<<0), ((APERTURE_RIGHT_Y+aperture_pos[3])<<0),
- APERTURE_RIGHT_BASE_TILE, APERTURE_TILE_WIDTH, APERTURE_TILE_HEIGHT,
- APERTURE_RIGHT_CSET, ((APERTURE_RIGHT_XSCALE+aperture_pos[6])<<0), ((APERTURE_RIGHT_YSCALE+aperture_pos[7])<<0),
- ((APERTURE_RIGHT_RX+aperture_pos[10])), ((APERTURE_RIGHT_RY+aperture_pos[11])), ((APERTURE_RIGHT_RANGLE+aperture_pos[14])),
- ((APERTURE_RIGHT_FLIP+aperture_pos[15])<<0),
- true, ((APERTURE_RIGHT_OPACITY+aperture_pos[17])<<0));
- //DrawTile(right side)
- //move it right to open it
- Screen->DrawTile(APERTURE_LAYER, ((APERTURE_LEFT_X+aperture_pos[0])<<0), ((APERTURE_LEFT_Y+aperture_pos[1])<<0),
- APERTURE_LEFT_BASE_TILE, APERTURE_TILE_WIDTH, APERTURE_TILE_HEIGHT,
- APERTURE_LEFT_CSET, ((APERTURE_LEFT_XSCALE+aperture_pos[4])<<0), ((APERTURE_LEFT_YSCALE+aperture_pos[5])<<0),
- ((APERTURE_LEFT_RX+aperture_pos[8])), ((APERTURE_LEFT_RY+aperture_pos[9])), ((APERTURE_LEFT_RANGLE+aperture_pos[12])),
- ((APERTURE_LEFT_FLIP+aperture_pos[13])<<0),
- true, ((APERTURE_LEFT_OPACITY+aperture_pos[16])<<0));
- //Handle texture change timer.
- if ( textime > 0 ) { textime--; } //Tick off the texture timer.
- else { //The timer has elapsed.
- if ( this->InitD[3] <= 0 ) textime = CUBE_TEXT_TIMER_DUR;
- else textime = this->InitD[3];
- //Advance the array texture.
- if ( tex_state < 9 ) { tex_state++; }
- else tex_state = 0; //Wrap to index 0.
- }
- //Decide if we rotate the cube:
- if ( cube_rot_timer != cubetimer && cube_rot_timer % modulus == 0 ) {
- //if this is not the initial frame, check if the rotation
- //timer modulus. Defualt move every 30 frames.
- //Do rotational effect to cube[]
- ___RotateQuad3D_X(rot_x, cube);
- }
- //Draw the cube.
- Screen->Quad3D(3,cube,cube_uv, cube_csets,cube_tex, 0, textures[tex_state], 0);
- //! Do we do anything fancy for warping on collision with the cube??
- //! If som i=t goes here.
- Waitframe();
- }
- }
- void ___RotateQuad3D_X(int angle, int pos} {
- //int cx, int cy, int cz){
- for(int i=0; i<3; i++){
- int y = pos[(i*3)+1];
- int z = pos[(i*3)+2];
- pos[(i*3)+1] = y * Cos(angle) - z * Sin(angle);
- pos[(i*3)+2] = z * Cos(angle) + y * Sin(angle);
- }
- }
- //'amount' should be positive to open, negative to close.
- void openWarpAperture(int aperture_pos, int amount){
- aperture_pos[0]-=amount;
- aperture_pos[2]+= amount;
- }
- void ___RotateQuad3D_Y(int angle, int pos){
- for(int i=0; i<3; i++){
- int x = pos[i*3];
- int z = pos[(i*3)+2];
- pos[i*3] = x * Cos(angle) - z * Sin(angle);
- pos[(i*3)+2] = z * Cos(angle) + x * Sin(angle);
- }
- }
- void ___RotateQuad3D_Z(int angle, int cx, int cy, int cz){
- for(int i=0; i<3 i++){
- int x = pos[i*3];
- int y = pos[(i*3)+1];
- pos[i*3] = x * Cos(angle) - y * Sin(angle);
- pos[(i*3)+1] = y * Cos(angle) + x * Sin(angle);
- }
- }
- }
- /*
- //Find a free bitmap to use
- //We want a circle of shimmering blue and white
- //We want some tiles copies to it
- //We need to make the area around it translucent.
- //Triangle 3D might do better?
- //Or a cube?
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement