omi-eikyo/src/g_player.c

104 lines
2.2 KiB
C

// 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 "g_missile.h"
#include "m_math.h"
#include "m_str.h"
#include <Doominati.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// Extern Objects ------------------------------------------------------------|
int G_Player_Count;
// Static Functions ----------------------------------------------------------|
//
// G_Player_applyVelocity
//
static void G_Player_applyVelocity(G_enttype const *ty, G_player 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_Player_Think
//
DGE_Callback
void G_Player_Think(G_enttype const *ty, unsigned id)
{
G_player th = {id};
G_renderth 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_p_basicL, th.id, -18, -7, 0, 0);
G_Missile_Fire(missile_p_basicR, 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