Cirno2022/script/sample/SampleRC01.txt

79 lines
2.0 KiB
Plaintext
Raw Permalink Normal View History

#TouhouDanmakufu[Stage]
#ScriptVersion[3]
#Title["SampleRC01"]
#Text["SampleRC01: Particle Rendering"]
@Initialize {
TSample();
}
@MainLoop {
yield;
}
task TSample() {
let dir = GetCurrentScriptDirectory();
let obj = ObjParticleList_Create(OBJ_PARTICLE_LIST_2D);
Obj_SetRenderPriorityI(obj, 21);
ObjPrim_SetTexture(obj, dir ~ "Effect01.png");
ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
//You may treat a 2D particle list object as a 2D primitive object.
ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLELIST);
ObjPrim_SetVertexCount(obj, 4);
ObjPrim_SetVertexUVT(obj, 0, 140, 39);
ObjPrim_SetVertexUVT(obj, 1, 186, 39);
ObjPrim_SetVertexUVT(obj, 2, 140, 86);
ObjPrim_SetVertexUVT(obj, 3, 186, 86);
ObjPrim_SetVertexPosition(obj, 0, -46 / 2, -47 / 2, 1);
ObjPrim_SetVertexPosition(obj, 1, 46 / 2, -47 / 2, 1);
ObjPrim_SetVertexPosition(obj, 2, -46 / 2, 47 / 2, 1);
ObjPrim_SetVertexPosition(obj, 3, 46 / 2, 47 / 2, 1);
//This is absolutely necessary, rendering will not be performed otherwise.
ObjPrim_SetVertexIndex(obj, [0, 1, 2, 1, 2, 3]);
loop {
CreateParticle();
yield;
}
task CreateParticle() {
let x = rand(0, 384);
let y = rand(0, 448);
let x_speed = rand(-1, 1);
let y_speed = rand(-1, 1);
let z_angle = rand(0, 360);
let z_add = rand(-5, 5);
let scale = rand(0.3, 0.7);
let timer_begin = floor(rand(10, 30 + 1));
ascent (i in 0..timer_begin) Update(Interpolate_Smooth(0, 1, i / (timer_begin - 1)));
loop (rand(30, 90)) Update(1);
let timer_end = floor(rand(10, 30 + 1));
descent (i in 0..timer_end) Update(Interpolate_Smooth(0, 1, i / (timer_end - 1)));
function Update(mul_scale) {
//Sets up instance data.
ObjParticleList_SetScale(obj, scale * mul_scale, scale * mul_scale, 1);
ObjParticleList_SetAngle(obj, 0, 0, z_angle);
ObjParticleList_SetPosition(obj, x, y, 1);
//Submits the current data to an instance, cleared every frame.
ObjParticleList_AddInstance(obj);
x += x_speed;
y += y_speed;
z_angle += z_add;
yield;
}
}
}