From 20fec4e3cfc9408d299ed10a46229db2ff01fcc4 Mon Sep 17 00:00:00 2001 From: Marrub Date: Fri, 29 Sep 2017 07:50:36 -0400 Subject: [PATCH] Add missiles and test enemies --- data/objdefs/testobj.dod | 1 + data/resdecl.rd | 4 +++ maps/stage1.gmf9 | 18 +++++++++-- src/g_object.h | 19 +++++++++--- src/g_player.c | 66 ++++++++++++++++++++++++++++++++++++++-- src/g_player.h | 10 ++++-- src/m_math.c | 11 +++++++ src/m_math.h | 9 ++++++ src/main.c | 49 +++++++++++++++++++++++++++++ src/r_draw.c | 22 +++++++++++--- 10 files changed, 192 insertions(+), 17 deletions(-) diff --git a/data/objdefs/testobj.dod b/data/objdefs/testobj.dod index f59d355..8ee6dfc 100644 --- a/data/objdefs/testobj.dod +++ b/data/objdefs/testobj.dod @@ -1,6 +1,7 @@ // Copyright © 2017 Project Golan, all rights reserved. entity TestObj { + subtype Test health 1 size 10 drawsize 16 diff --git a/data/resdecl.rd b/data/resdecl.rd index 9031c12..76e41de 100644 --- a/data/resdecl.rd +++ b/data/resdecl.rd @@ -5,6 +5,10 @@ texture "gui/border" = "textures/Border.png" texture "ent/player" = "sprites/Particle3_Pointer.png" texture "ent/testobj" = "sprites/Particle3.png" +texture "ent/missile" = "sprites/Particle4.png" +texture "ent/explosion1" = "sprites/Explosion1.png" +texture "ent/explosion2" = "sprites/Explosion2.png" +texture "ent/explosion3" = "sprites/Explosion3.png" texture "box" = "textures/Box.png" texture "empty" = "textures/Empty.png" diff --git a/maps/stage1.gmf9 b/maps/stage1.gmf9 index d25a28b..9f4e1d0 100644 --- a/maps/stage1.gmf9 +++ b/maps/stage1.gmf9 @@ -1,5 +1,19 @@ // Copyright © 2017 Project Golan, all rights reserved. -{50 TestObj -200 0 16} -{50 TestObj -200 100 16} +{ 50 TestObj -300 -200 16} +{ 60 TestObj -250 -200 16} +{100 TestObj -150 -200 16} +{110 TestObj -100 -200 16} +{150 TestObj -200 -200 16} +{160 TestObj -250 -200 16} +{200 TestObj -300 -200 16} +{210 TestObj -250 -200 16} +{250 TestObj -300 -200 16} +{260 TestObj -250 -200 16} +{300 TestObj -150 -200 16} +{310 TestObj -100 -200 16} +{350 TestObj -200 -200 16} +{360 TestObj -250 -200 16} +{400 TestObj -300 -200 16} +{410 TestObj -250 -200 16} // EOF diff --git a/src/g_object.h b/src/g_object.h index 9753691..43fcac7 100644 --- a/src/g_object.h +++ b/src/g_object.h @@ -13,21 +13,21 @@ #define G_propMemExt(base, ofs, t, name) \ G_propMemOfs(DGE_OME_##base + (ofs), t, name) -#define G_Entity_propMem(ofs, t, name) \ - G_propMemExt(Entity, ofs, t, name) - -#define G_Entity_props() DGE_EntityProps() \ - G_propMemOfs(DGE_OME(Entity.subtype), int, subtype) +#define G_Entity_propMem(ofs, t, name) G_propMemExt(Entity, ofs, t, name) // Types ---------------------------------------------------------------------| enum G_subty { subtype_none, + subtype_missile, + subtype_test, subtype_player, subtype_max, }; +#define G_Entity_props() DGE_EntityProps() \ + G_propMemOfs(DGE_OME(Entity.subtype), int, subtype) typedef struct G_entit // Entity { int id; @@ -35,6 +35,15 @@ typedef struct G_entit // Entity G_Entity_props() } G_entit; +#define G_Missile_props() DGE_MissileEntityProps() \ + G_propMemOfs(DGE_OME(Entity.subtype), int, subtype) +typedef struct G_missl // Missile +{ + int id; + + G_Missile_props() +} G_missl; + // Extern Functions ----------------------------------------------------------| void G_Entity_Create(union G_mfdat *info); diff --git a/src/g_player.c b/src/g_player.c index 89ac55b..2bd1d19 100644 --- a/src/g_player.c +++ b/src/g_player.c @@ -2,14 +2,26 @@ #define _GNU_SOURCE // Required for sincos(3). See feature_test_macros(7) #include "g_player.h" +#include "g_stage.h" +#include "m_math.h" + #include #include +#include #include +// Types ---------------------------------------------------------------------| + +enum G_mslty +{ + missile_player, +}; + // Extern Objects ------------------------------------------------------------| -int G_Player_Count = 1; +int G_Player_Count; +G_playr G_Player_InGame[G_Player_max]; // Static Functions ----------------------------------------------------------| @@ -35,21 +47,69 @@ static void G_Player_applyVelocity(G_playr th) // Extern Functions ----------------------------------------------------------| +// +// G_Missile_Fire +// +void G_Missile_Fire(enum G_mslty type, unsigned owner, fixed x, fixed y, fixed z, ulfra yaw) +{ + G_missl th = {DGE_MissileEntity_Create(0)}; + th.subtype = subtype_missile; + + th.x = x; + th.y = y; + th.z = z; + th.yaw = yaw; + th.health = 1; + th.damage = 1; + th.owner = owner; + + float s, c; + sincosf(M_angle(yaw), &s, &c); + + switch(type) + { + case missile_player: + th.sprite = DGE_Texture_Get(s"ent/missile"); + th.rsx = 3; + th.rsy = 16; + th.sx = 4; + th.sy = 4; + th.sz = 4; + th.vx = c * 14; + th.vy = s * 14; + break; + } +} + // // G_Player_Think // DGE_Callback void G_Player_Think(unsigned id) { - DGE_Object_RefAdd(id); + G_playr th = {id}; + // TODO: remove if david makes IEMs 0-init + th.ammo = 0; + th.lives = 5; + th.nextfire = 0; - for(G_playr th = {id}; th.health > 0;) + DGE_Object_RefAdd(id); + G_Player_InGame[G_Player_Count++] = th; + + while(th.health > 0) { G_Player_applyVelocity(th); + if(th.nextfire < G_Time) { + G_Missile_Fire(missile_player, th.id, th.x - 7, th.y - 10, th.z, 0); + G_Missile_Fire(missile_player, th.id, th.x + 7, th.y - 10, th.z, 0); + th.nextfire = G_Time + 3; + } + DGE_Task_Sleep(0, 1); } + G_Player_InGame[--G_Player_Count] = (G_playr){0}; DGE_Object_RefSub(id); } diff --git a/src/g_player.h b/src/g_player.h index 77f1e72..bee484e 100644 --- a/src/g_player.h +++ b/src/g_player.h @@ -4,6 +4,7 @@ #include "g_object.h" +#define G_Player_max 2 #define G_Player_propMem(t, name) G_Entity_propMem(G_Player_##name, t, name) // Types ---------------------------------------------------------------------| @@ -11,11 +12,15 @@ enum { G_Player_ammo, + G_Player_lives, + G_Player_nextfire, G_Player_propC }; #define G_Player_props() G_Entity_props() \ - G_Player_propMem(unsigned, ammo) + G_Player_propMem(unsigned, ammo) \ + G_Player_propMem(unsigned, lives) \ + G_Player_propMem(unsigned, nextfire) typedef struct G_playr // Player { int id; @@ -25,7 +30,8 @@ typedef struct G_playr // Player // Extern Objects ------------------------------------------------------------| -extern int G_Player_Count; +extern int G_Player_Count; +extern G_playr G_Player_InGame[G_Player_max]; // Extern Functions ----------------------------------------------------------| diff --git a/src/m_math.c b/src/m_math.c index 2ff75db..f8fd01b 100644 --- a/src/m_math.c +++ b/src/m_math.c @@ -1,6 +1,8 @@ // Copyright © 2017 Project Golan, all rights reserved. #include "m_math.h" +#include + // Extern Functions ----------------------------------------------------------| // @@ -11,4 +13,13 @@ bool M_AABBPoint(fixed xl, fixed yl, fixed xu, fixed yu, fixed xp, fixed yp) return xp > xl && yp > yl && xp < xu && yp < yu; } +// +// M_Random_Float +// +float M_Random_Float(float min, float max) +{ + if(max < min) {float min_ = min; min = max; max = min_;} + return (rand() / (double)RAND_MAX) * (max - min) + min; +} + // EOF diff --git a/src/m_math.h b/src/m_math.h index 3eb69b6..ee8912c 100644 --- a/src/m_math.h +++ b/src/m_math.h @@ -4,8 +4,17 @@ #include "m_types.h" +#include + +#define M_pi (3.14159265359) +#define M_pi2 (M_pi / 2.0) +#define M_tau (M_pi * 2.0) + +#define M_angle(n) (fmod((n) * M_tau - M_pi2, M_tau)) + // Extern Functions ----------------------------------------------------------| bool M_AABBPoint(fixed xl, fixed yl, fixed xu, fixed yu, fixed xp, fixed yp); +float M_Random_Float(float min, float max); #endif diff --git a/src/main.c b/src/main.c index 4851cf0..20b4891 100644 --- a/src/main.c +++ b/src/main.c @@ -3,6 +3,7 @@ #include "g_object.h" #include "g_player.h" #include "r_draw.h" +#include "m_math.h" #include @@ -10,6 +11,53 @@ // Extern Functions ----------------------------------------------------------| +// +// G_TestObj_Think +// +DGE_Callback +void G_TestObj_Think(unsigned id) +{ + G_entit 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 // @@ -29,6 +77,7 @@ void GInit(char const *resdecl) printf("Loading object function table...\n"); G_ObjDef_Init(); G_ObjDef_AddType("Player", subtype_player, G_Player_propC, (DGE_CallbackType)G_Player_Think); + G_ObjDef_AddType("Test", subtype_test, 0, (DGE_CallbackType)G_TestObj_Think); printf("Loading object definitions...\n"); G_ObjDef_Load("objdefs.dod"); diff --git a/src/r_draw.c b/src/r_draw.c index cf53038..3d2820e 100644 --- a/src/r_draw.c +++ b/src/r_draw.c @@ -2,6 +2,8 @@ #include "r_draw.h" #include "g_stage.h" +#include "g_object.h" +#include "g_player.h" #include "m_str.h" #include @@ -57,12 +59,22 @@ void R_DrawPost(ulfra delta) DGE_Font_Bind(DGE_Font_Get(s"base")); DGE_Draw_SetTextAlign(DGE_Align_Center, DGE_Align_Top); DGE_Draw_Text(760, 20, G_Place); - DGE_Draw_SetTextAlign(DGE_Align_Left); - DGE_Draw_Text(585, 70, u8"ハイスコア\nスコア\n\n残り再試行回"); - DGE_Draw_SetTextAlign(DGE_Align_Right); - DGE_Draw_Text(945, 70, M_StrFmt("%.15i\n%.15i\n\n%i", 0, 0, 5)); - R_drawHitboxes(); + DGE_Draw_SetTextAlign(DGE_Align_Left); + DGE_Draw_Text(585, 70, u8"ハイスコア"); + DGE_Draw_SetTextAlign(DGE_Align_Right); + DGE_Draw_Text(945, 70, M_StrFmt("%.15i", 0)); + + for(int i = 0; i < G_Player_Count; i++) + { + DGE_Draw_SetTextAlign(DGE_Align_Left); + DGE_Draw_Text(585, 120 + i * 20, + M_StrFmt(u8"PLAYER %i\nスコア\n残り再試行回", i + 1)); + DGE_Draw_SetTextAlign(DGE_Align_Right); + DGE_Draw_Text(945, 140 + i * 20, M_StrFmt("%.15i\n%i", 0, 5)); + } + + //R_drawHitboxes(); } // EOF