Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Constants
- //------------------------------------------------------------
- // Maximum effect width
- let MAX_WIDTH = 160;
- // Effect color RGB values, adjust to your liking
- let EFF_COLOR_R = 192;
- let EFF_COLOR_G = 255;
- let EFF_COLOR_B = 255;
- // Variables
- //------------------------------------------------------------
- // Boss object ID, pass to this script using SetScriptArgument().
- let nParentID = GetScriptArgument( 0 );
- let nParentX = ObjMove_GetX( nParentID );
- let nParentY = ObjMove_GetY( nParentID );
- let nOldX = ObjMove_GetX( nParentID );
- let nOldY = ObjMove_GetY( nParentID );
- // Main
- //------------------------------------------------------------
- @Event
- {
- }
- @Initialize
- {
- // Color correction
- EFF_COLOR_R = 255 - EFF_COLOR_R;
- EFF_COLOR_G = 255 - EFF_COLOR_G;
- EFF_COLOR_B = 255 - EFF_COLOR_B;
- TWaveCircle();
- }
- @MainLoop
- {
- nParentX = ObjMove_GetX( nParentID );
- nParentY = ObjMove_GetY( nParentID );
- yield;
- nOldX = nParentX;
- nOldY = nParentY;
- }
- @Finalize
- {
- }
- // Functions
- //------------------------------------------------------------
- task TWaveCircle()
- {
- // Variables
- //------------------------------------------------------------
- let renderTexture = GetReservedRenderTargetName( 0 );
- // Stores the primitive objects making up the effect
- let a_nObj = [];
- // Current effect width
- let nWidth = 16;
- // Effect width plus 20
- let nWidth2;
- // X oscillator, controls wobble along the X axis
- let nOscX = 0;
- // Y oscillator, controls wobble along the Y axis
- let nOscY = 0;
- // X oscillator phase offset, used to add ripples
- let nPhaseX = 0;
- // Y oscillator phase offset, used to add ripples
- let nPhaseY = 0;
- // Whether the effect is still expanding
- let bExpand = true;
- // Begin
- //------------------------------------------------------------
- loop ( 16 )
- {
- let obj = ObjPrim_Create( OBJ_PRIMITIVE_2D );
- Obj_SetRenderPriority( obj, 0.29 );
- ObjPrim_SetTexture( obj, renderTexture );
- ObjPrim_SetPrimitiveType( obj, PRIMITIVE_TRIANGLESTRIP );
- ObjPrim_SetVertexCount( obj, 34 );
- a_nObj = a_nObj ~ [obj];
- }
- // Hack to prevent index going out of bounds
- a_nObj = a_nObj ~ [ID_INVALID];
- while ( !Obj_IsDeleted( nParentID ) )
- {
- // Update texture
- RenderToTextureA1( renderTexture, 20, 28, true );
- // Increase effect width
- if ( nWidth < 160 )
- {
- nWidth += 2;
- } else if ( bExpand )
- {
- bExpand = false;
- }
- // Update object positions
- ascent ( i in 0..16 )
- {
- ObjRender_SetPosition( a_nObj[i], nParentX, nParentY, 0 );
- }
- // Update vertices
- //------------------------------------------------------------
- // Size of effect
- let nEffSize = nWidth * nWidth;
- nPhaseX = nOscX;
- nPhaseY = nOscY;
- // Texture UV offsets
- let nBiasX = nParentX + 32 - 180;
- let nBiasY = nParentY + 16 - 180;
- nWidth2 = nWidth + 20;
- // I'm willing to wager 80% of this code is optimization
- let i = 0;
- loop ( 17 )
- {
- // Previous primitive
- let obj1;
- // Current primitive
- let obj2 = a_nObj[i];
- if ( i > 0 )
- {
- obj1 = a_nObj[min( i - 1, 15 )];
- } else
- {
- obj1 = a_nObj[0];
- }
- let j = 0;
- // Vertex X coordinate
- let nX = ( 0.125*i - 1.0 ) * nWidth2;
- // Vertex texture U
- let nU = 22.5*i + nBiasX;
- loop ( 17 )
- {
- // Vertex Y coordinate
- let nY = ( 0.125*j - 1.0 ) * nWidth2;
- // Vertex texture V
- let nV = 22.5*j + nBiasY;
- // Vertex's distance (squared) from the effect's center
- let nDistance = nX*nX + nY*nY;
- // Vertex indices
- let nIndex1 = j*2;
- let nIndex2 = j*2 + 1;
- if ( bExpand )
- {
- ObjPrim_SetVertexUVT( obj1, nIndex2, nU, nV );
- ObjPrim_SetVertexUVT( obj2, nIndex1, nU, nV );
- } else if ( nOldX != nParentX || nOldY != nParentY )
- {
- ObjPrim_SetVertexUVT( obj1, nIndex2, nU, nV );
- ObjPrim_SetVertexUVT( obj2, nIndex1, nU, nV );
- }
- if ( nDistance < nEffSize )
- {
- // Multiplier to scale calculations to fit the bulge
- let nMult = ( nEffSize - nDistance ) / nEffSize;
- // X and Y components of a vector from the effect's center to the vertex's position
- let nVectorX;
- let nVectorY;
- // Calculate vector components
- if ( nDistance != 0 )
- {
- nDistance ^= -0.5;
- nVectorX = nX * nDistance;
- nVectorY = nY * nDistance;
- } else
- {
- nVectorX = 0;
- nVectorY = 0;
- }
- let nMult2 = 32 * nMult;
- let nMult3 = 8 * nMult;
- // Offset vertex position
- let nX2 = nX + nMult2*nVectorX + nMult3*sin( nPhaseX );
- nY += nMult2*nVectorY + nMult3*sin( nPhaseY );
- ObjPrim_SetVertexPosition( obj1, nIndex2, nX2, nY, 0 );
- if ( i < 16 )
- {
- ObjPrim_SetVertexPosition( obj2, nIndex1, nX2, nY, 0 );
- }
- // Calculate and apply color gradient
- if ( bExpand )
- {
- let nRed = 255 - nMult*EFF_COLOR_R;
- let nGreen = 255 - nMult*EFF_COLOR_G;
- let nBlue = 255 - nMult*EFF_COLOR_B;
- ObjPrim_SetVertexColor( obj1, nIndex2, nRed, nGreen, nBlue );
- ObjPrim_SetVertexAlpha( obj1, nIndex2, 255 );
- if ( i < 16 )
- {
- ObjPrim_SetVertexColor( obj2, nIndex1, nRed, nGreen, nBlue );
- ObjPrim_SetVertexAlpha( obj2, nIndex1, 255 );
- }
- }
- } else
- {
- if ( bExpand )
- {
- ObjPrim_SetVertexPosition( obj1, nIndex2, nX, nY, 0 );
- ObjPrim_SetVertexColor( obj1, nIndex2, 255, 255, 255 );
- ObjPrim_SetVertexAlpha( obj1, nIndex2, 0 );
- if ( i < 16 )
- {
- ObjPrim_SetVertexPosition( obj2, nIndex1, nX, nY, 0 );
- ObjPrim_SetVertexColor( obj2, nIndex1, 255, 255, 255 );
- ObjPrim_SetVertexAlpha( obj2, nIndex1, 0 );
- }
- } else
- {
- if ( nOldX != nParentX || nOldY != nParentY )
- {
- ObjPrim_SetVertexPosition( obj1, nIndex2, nX, nY, 0 );
- if ( i < 16 )
- {
- ObjPrim_SetVertexPosition( obj2, nIndex1, nX, nY, 0 );
- }
- }
- }
- }
- nPhaseX += 5.625;
- nPhaseY -= 2.8125;
- j++;
- }
- i++;
- }
- nOscX += 11.25;
- nOscY += 5.625;
- yield;
- }
- ascent ( i in 0..16 )
- {
- Obj_Delete( a_nObj[i] );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement