Cirno2022/script/KevinSystem/kevin_system/Kevin_EffectLib.dnh

115 lines
3.1 KiB
Plaintext
Raw Normal View History

//let imgEffect = dirCurrent ~ "./img/Kevin_Effect.png";
int PetalEffect = ObjParticleList_Create(OBJ_PARTICLE_LIST_2D);
task InitEffect(){
_EffectListPreRender(PetalEffect, imgEffect, [0, 0, 256, 256]);
}
let imgEffect = dirCurrent ~ "./img/Kevin_Effect.png";
// Enemy deletion/explosion effects.
// This particle list is used for all instances of the effect.
task _EffectListPreRender(
int targetList,
texture, int[] rect
){
ObjPrim_SetTexture(targetList, texture);
Obj_SetRenderPriorityI(targetList, 39);
ObjPrim_SetPrimitiveType(targetList, PRIMITIVE_TRIANGLELIST);
ObjPrim_SetVertexCount(targetList, 4);
ObjRender_SetBlendType(targetList, BLEND_ALPHA);
// Left-top, right-top, left-bottom, right-bottom
ObjPrim_SetVertexUVT(targetList, 0, rect[0], rect[1]);
ObjPrim_SetVertexUVT(targetList, 1, rect[2], rect[1]);
ObjPrim_SetVertexUVT(targetList, 2, rect[0], rect[3]);
ObjPrim_SetVertexUVT(targetList, 3, rect[2], rect[3]);
// Vertex positions are offset with deltas so that the sprite is centered
float dU = (rect[2] - rect[0])/2;
float dV = (rect[3] - rect[1])/2;
ObjPrim_SetVertexPosition(targetList, 0, -dU, -dV, 1);
ObjPrim_SetVertexPosition(targetList, 1, dU, -dV, 1);
ObjPrim_SetVertexPosition(targetList, 2, -dU, dV, 1);
ObjPrim_SetVertexPosition(targetList, 3, dU, dV, 1);
ObjPrim_SetVertexIndex(targetList, [0, 1, 2, 1, 2, 3]);
}
// Enemy go Boom
/*
5 flower petals appear from the enemy and spin outwards.
Their angle constantly changes and their alpha lowers over time.
*/
task _ExplosionEffect(float enmX, float enmY, int targetList){
int i = 0;
int effectLength = 45;
int effectNum = 5;
int dir = 1;
Obj_SetRenderPriorityI(targetList, 40);
//TExplosionA(enmX, enmY, 255/effectLength, 9/effectLength);
/*ascent(i in 0..effectNum){
_CreatePetal(prand(5, 10)*dir, prand(5, 10)*dir, prand(0, 360));
dir *= -1;
//_CreatePetal(prand(50, 80), prand(-80, -50), prand(0, 360));
}*/
_CreatePetal(prand(8, 11), prand(-8, -11), prand(0, 360));
_CreatePetal(prand(-11, -8), prand(-2, 2), prand(0, 360));
_CreatePetal(prand(8, 8), prand(-2, 2), prand(0, 360));
_CreatePetal(prand(-11, -8), prand(8, 11), prand(0, 360));
_CreatePetal(prand(8, 11), prand(8, 11), prand(0, 360));
ObjSound_Play(sfxBoom);
// Create a petal with:
// x offset every frame, y offset every frame
task _CreatePetal(float spdX, float spdY, float baseAng){
float x = enmX, y = enmY;
let x_speed = spdX;
let y_speed = spdY;
let z_add = prand(-5, 5);
ascent(i in 0..effectLength){
_PetalMovement(Interpolate_Decelerate(1.5, 0.5, i/effectLength), Interpolate_Decelerate(255, 0, i/effectLength));
yield;
}
task _PetalMovement(scale, alpha){
ObjParticleList_SetScale(targetList, scale);
ObjParticleList_SetAngleZ(targetList, baseAng);
ObjParticleList_SetPosition(targetList, x, y, 1);
ObjParticleList_SetAlpha(targetList, alpha);
//Submits the current data to an instance, cleared every frame.
ObjParticleList_AddInstance(targetList);
x += x_speed;
y += y_speed;
baseAng += z_add;
yield;
}
}
}