omi-eikyo/src/g_enemy.c

68 lines
1.5 KiB
C

// Copyright © 2017 Project Golan, all rights reserved.
// See COPYING for more information.
#include "g_enemy.h"
#include "m_math.h"
// Static Functions ----------------------------------------------------------|
//
// G_TestObj_explode
//
static void G_TestObj_explode(fixed x, fixed y)
{
DGE_ParticleSys ps = {DGE_ParticleSys_Create(0, 128)};
DGE_Particle prt = {
.life = 30,
.size = {20, 20},
.color = {1ulr, 1ulr, 0ulr, 1ulr}, {1ulr, 1ulr, 0ulr, 0ulr}, 0.05};
for(int i = 0; i < 7; i++)
{
prt.vel.x = M_Random_Float(-2, 2);
prt.vel.y = M_Random_Float(-2, 2);
prt.pos.x = M_Random_Float(-4, 4);
prt.pos.y = M_Random_Float(-4, 4);
DGE_ParticleSys_Add(ps.id, prt);
}
ps.x = x;
ps.y = y;
ps.sprite = DGE_Texture_Get(s"ent/explosion1");
DGE_Task_Sleep(0, 10); ps.sprite = DGE_Texture_Get(s"ent/explosion2");
DGE_Task_Sleep(0, 10); ps.sprite = DGE_Texture_Get(s"ent/explosion3");
DGE_Task_Sleep(0, 20); DGE_Thinker_Unlink(ps.id);
}
// Extern Functions ----------------------------------------------------------|
//
// G_TestObj_Think
//
DGE_Callback
void G_TestObj_Think(G_enttype const *ty, unsigned id)
{
G_entity th = {id};
fixed sx = th.x;
DGE_Object_RefAdd(id);
for(dword ticks = 0; th.health > 0; ticks++)
{
th.x = sx + cos(ticks / 7.0) * 23;
th.y = th.y + 2.6;
DGE_Task_Sleep(0, 1);
}
fixed x = th.x, y = th.y;
DGE_Object_RefSub(id);
G_TestObj_explode(x, y);
}
// EOF