omi-eikyo/src/g_player.c

57 lines
1.1 KiB
C

// Copyright © 2017 Project Golan, all rights reserved.
#define _GNU_SOURCE // Required for sincos(3). See feature_test_macros(7)
#include "g_player.h"
#include <Doominati.h>
#include <stdio.h>
#include <math.h>
// Extern Objects ------------------------------------------------------------|
int G_Player_Count = 1;
// 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_Player_Think
//
DGE_Callback
void G_Player_Think(unsigned id)
{
DGE_Object_RefAdd(id);
for(G_playr th = {id}; th.health > 0;)
{
G_Player_applyVelocity(th);
DGE_Task_Sleep(0, 1);
}
DGE_Object_RefSub(id);
}
// EOF