omi-eikyo/src/g_player.c

57 lines
1.1 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-27 19:26:32 -07:00
#include "g_player.h"
2017-09-20 19:36:30 -07:00
#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>
2017-09-27 18:47:18 -07:00
// Extern Objects ------------------------------------------------------------|
int G_Player_Count = 1;
2017-09-23 17:21:07 -07:00
// Static Functions ----------------------------------------------------------|
//
// G_Player_applyVelocity
//
2017-09-27 18:47:18 -07:00
static void G_Player_applyVelocity(G_playr th)
2017-09-23 17:21:07 -07:00
{
2017-09-27 18:47:18 -07:00
DGE_Point3R ax = DGE_Input_GetAxis(1);
2017-09-26 14:00:23 -07:00
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);
2017-09-27 18:47:18 -07:00
th.vx = th.vx + c * mag * 5;
th.vy = th.vy - s * mag * 5;
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
2017-09-27 18:47:18 -07:00
void G_Player_Think(unsigned id)
2017-09-20 19:36:30 -07:00
{
2017-09-27 18:47:18 -07:00
DGE_Object_RefAdd(id);
2017-09-20 19:36:30 -07:00
2017-09-27 18:47:18 -07:00
for(G_playr th = {id}; th.health > 0;)
2017-09-20 19:36:30 -07:00
{
2017-09-27 18:47:18 -07:00
G_Player_applyVelocity(th);
2017-09-20 19:36:30 -07:00
DGE_Task_Sleep(0, 1);
}
2017-09-27 18:47:18 -07:00
DGE_Object_RefSub(id);
2017-09-20 19:36:30 -07:00
}
// EOF