// Copyright © 2017 Project Golan, all rights reserved. // See COPYING for more information. #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 "m_str.h" #include #include #include #include // Types ---------------------------------------------------------------------| enum G_mslty { missile_playerL, missile_playerR, }; // Extern Objects ------------------------------------------------------------| int G_Player_Count; // Static Functions ----------------------------------------------------------| // // G_Player_applyVelocity // static void G_Player_applyVelocity(G_entty const *ty, G_playr th) { DGE_Point3R ax = DGE_Input_GetAxis(1); accum vx = (accum)ax.x, vy = (accum)ax.y; float mag = sqrtf(vx * vx + vy * vy); float ang = atan2f(vy, vx); float s, c; sincosf(ang, &s, &c); if(mag > 1) mag = 1; if(mag < -1) mag = -1; th.vx = th.vx + c * mag * 5; th.vy = th.vy - s * mag * 5; if(th.vx < 0) th.setAnim(ty->getAnim("Left")); else if(th.vx > 0) th.setAnim(ty->getAnim("Righ")); else if(th.lvx < 0) th.setAnim(ty->getAnim("FLef")); else if(th.lvx > 0) th.setAnim(ty->getAnim("FRig")); th.lvx = th.vx; } // Extern Functions ----------------------------------------------------------| // // G_Missile_Fire // void G_Missile_Fire(enum G_mslty type, unsigned owner, fixed x, fixed y, fixed z, ulfra yaw) { G_entit ot = {owner}; G_missl th = {DGE_MissileEntity_Create(0)}; th.subtype = subtype_missile; th.x = ot.x + x; th.y = ot.y + y; th.z = ot.z + z; th.yaw = yaw; th.health = 1; th.damage = 1; th.owner = owner; th.sz = 4; float s, c; sincosf(M_angle(yaw), &s, &c); switch(type) { case missile_playerL: th.sprite = DGE_Texture_Get(s"ent/shotl"); goto player; case missile_playerR: th.sprite = DGE_Texture_Get(s"ent/shotr"); goto player; player: th.cr = 0.3ulr; th.cg = 0.9ulr; th.cb = 0.1ulr; th.ca = 0.7ulr; th.rsx = 6; th.rsy = 16; th.sx = 6; th.sy = 18; th.vx = c * 14; th.vy = s * 14; break; } } // // G_Player_Think // DGE_Callback void G_Player_Think(G_entty const *ty, unsigned id) { G_playr th = {id}; G_rthnk shot = {DGE_RenderThinker_Create(0)}; shot.rsx = 30; shot.rsy = 24; th.lives = 5; th.setAnim(ty->getAnim("Idle")); DGE_Object_RefAdd(id); DGE_Object_RefAdd(shot.id); while(th.health > 0) { G_Player_applyVelocity(ty, th); if(G_Time < 70) th.y = th.y + log(G_Time / 70.0) * 0.7hk; else if(th.nextfire < G_Time) { shot.fsetAnim(G_ObjDef_GetAnim("PlayerShot")); G_Missile_Fire(missile_playerL, th.id, -18, -7, 0, 0); G_Missile_Fire(missile_playerR, th.id, +18, -7, 0, 0); th.nextfire = G_Time + 3; } shot.x = th.x; shot.y = th.y - 20; shot.z = th.z; shot.animate(); th .animate(); DGE_Task_Sleep(0, 1); } DGE_Object_RefSub(id); DGE_Object_RefSub(shot.id); DGE_Thinker_Unlink(shot.id); } // EOF