omi-eikyo/src/g_player.c

56 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
//
2017-09-26 14:00:23 -07:00
static void G_Player_applyVelocity(DGE_Entity ent)
2017-09-23 17:21:07 -07:00
{
2017-09-26 14:00:23 -07:00
DGE_Point2R ax = DGE_Input_GetAxis(1);
accum vx = (accum)ax.x, vy = (accum)ax.y;
2017-09-23 17:21:07 -07:00
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-26 14:00:23 -07:00
// TODO: apply animation based on X velocity here
2017-09-23 17:21:07 -07:00
}
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