From 996bb982bae4d6d9229c023fe803b8355f96abd8 Mon Sep 17 00:00:00 2001 From: Marrub Date: Sat, 7 Oct 2017 07:27:57 -0400 Subject: [PATCH] Move test object to g_enemy --- src/g_enemy.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/g_enemy.h | 12 +++++++++ src/main.c | 49 +------------------------------------ 3 files changed, 80 insertions(+), 48 deletions(-) create mode 100644 src/g_enemy.c create mode 100644 src/g_enemy.h diff --git a/src/g_enemy.c b/src/g_enemy.c new file mode 100644 index 0000000..3ba0e43 --- /dev/null +++ b/src/g_enemy.c @@ -0,0 +1,67 @@ +// 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 diff --git a/src/g_enemy.h b/src/g_enemy.h new file mode 100644 index 0000000..317d279 --- /dev/null +++ b/src/g_enemy.h @@ -0,0 +1,12 @@ +// Copyright © 2017 Project Golan, all rights reserved. +// See COPYING for more information. +#ifndef g_enemy_h +#define g_enemy_h + +#include "g_object.h" + +// Extern Functions ----------------------------------------------------------| + +DGE_Callback void G_TestObj_Think(G_enttype const *ty, unsigned id); + +#endif diff --git a/src/main.c b/src/main.c index a69a071..105e1fd 100644 --- a/src/main.c +++ b/src/main.c @@ -3,7 +3,7 @@ #include "g_stage.h" #include "g_object.h" #include "g_player.h" -#include "m_math.h" +#include "g_enemy.h" #include @@ -11,53 +11,6 @@ // Extern Functions ----------------------------------------------------------| -// -// G_TestObj_Think -// -DGE_Callback -void G_TestObj_Think(G_enttype const *ty, unsigned id) -{ - G_entity th = {id}; - - DGE_Object_RefAdd(id); - - while(th.health > 0) - DGE_Task_Sleep(0, 1); - - fixed x = th.x, y = th.y; - - DGE_Object_RefSub(id); - - DGE_ParticleSys ps = {DGE_ParticleSys_Create(0, 128)}; - - ps.sprite = DGE_Texture_Get(s"ent/explosion1"); - ps.x = x; - ps.y = y; - - 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); - } - - 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); -} - // // GInit //