Browse Source

Move test object to g_enemy

master
Marrub 5 years ago
parent
commit
996bb982ba
  1. 67
      src/g_enemy.c
  2. 12
      src/g_enemy.h
  3. 49
      src/main.c

67
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

12
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

49
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 <Doominati.h>
@ -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
//

Loading…
Cancel
Save