// Copyright © 2017 Project Golan, all rights reserved. #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; G_playr G_Player_InGame[G_Player_max]; // Static Functions ----------------------------------------------------------| // // G_Player_applyVelocity // static void G_Player_applyVelocity(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); th.vx = th.vx + c * mag * 5; th.vy = th.vy - s * mag * 5; // TODO: apply animation based on X velocity here } // 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) { G_playr th = {id}; // TODO: remove if david makes IEMs 0-init th.ammo = 0; th.lives = 5; th.nextfire = 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); } // EOF