omi-eikyo/src/g_player.c

54 lines
1.0 KiB
C

// Copyright © 2017 Project Golan, all rights reserved.
#define _GNU_SOURCE // Required for sincos(3). See feature_test_macros(7)
#include "g_object.h"
#include <Doominati.h>
#include <stdio.h>
#include <math.h>
// Static Functions ----------------------------------------------------------|
//
// G_Player_applyVelocity
//
void G_Player_applyVelocity(DGE_Entity ent)
{
accum vx = (accum)DGE_GetInputAxis(0, DGE_Axis_X);
accum vy = (accum)DGE_GetInputAxis(0, DGE_Axis_Y);
float mag = sqrtf(vx * vx + vy * vy);
float ang = atan2f(vy, vx);
float s, c;
sincosf(ang, &s, &c);
ent.vx = ent.vx + c * mag * 1.1;
ent.vy = ent.vy - s * mag * 1.1;
}
// Extern Functions ----------------------------------------------------------|
//
// G_Player_Think
//
DGE_Callback
void G_Player_Think(DGE_Entity ent)
{
DGE_Object_RefAdd(ent.id);
for(;;)
{
if(ent.health <= 0)
break;
G_Player_applyVelocity(ent);
DGE_Task_Sleep(0, 1);
}
DGE_Object_RefSub(ent.id);
}
// EOF