omi-eikyo/src/g_player.c

54 lines
1.0 KiB
C
Raw Normal View History

2017-09-20 19:36:30 -07:00
// Copyright © 2017 Project Golan, all rights reserved.
2017-09-23 17:21:07 -07:00
#define _GNU_SOURCE // Required for sincos(3). See feature_test_macros(7)
2017-09-20 19:36:30 -07:00
#include "g_object.h"
#include <Doominati.h>
2017-09-23 12:43:54 -07:00
#include <stdio.h>
2017-09-23 17:21:07 -07:00
#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;
}
2017-09-23 12:43:54 -07:00
2017-09-20 19:36:30 -07:00
// Extern Functions ----------------------------------------------------------|
//
// G_Player_Think
//
2017-09-23 12:43:54 -07:00
DGE_Callback
void G_Player_Think(DGE_Entity ent)
2017-09-20 19:36:30 -07:00
{
DGE_Object_RefAdd(ent.id);
for(;;)
{
if(ent.health <= 0)
break;
2017-09-23 17:21:07 -07:00
G_Player_applyVelocity(ent);
2017-09-20 19:36:30 -07:00
DGE_Task_Sleep(0, 1);
}
DGE_Object_RefSub(ent.id);
}
// EOF