96 lines
2.1 KiB
C++
96 lines
2.1 KiB
C++
#include "game.h"
|
|
#include "level.h"
|
|
|
|
//===== Player implementation =======//
|
|
|
|
num player::world_angle() const
|
|
{
|
|
num arc = space_platform_arc();
|
|
num angle = this->platform * arc;
|
|
|
|
if(this->airborne()) {
|
|
/* Time spent rotating; caps at the full rotation time */
|
|
num t = num_clamp(this->jump_t, 0, TIME_ROTATION);
|
|
angle += this->jump_dir * arc * t / TIME_ROTATION;
|
|
}
|
|
|
|
return angle;
|
|
}
|
|
|
|
vec2 player::world_angle_vector() const
|
|
{
|
|
num angle = this->world_angle();
|
|
return vec2(num_cos(angle), num_sin(angle));
|
|
}
|
|
|
|
vec3 player::pos() const
|
|
{
|
|
/* Local position without accounting for current platform's angle */
|
|
vec3 pos(0, -space_platform_distance() + this->height, this->z);
|
|
|
|
return vec_rotate_around_z(pos, this->world_angle_vector());
|
|
}
|
|
|
|
vec3 player::forward() const
|
|
{
|
|
return vec3(0, 0, 1);
|
|
}
|
|
|
|
vec3 player::backward() const
|
|
{
|
|
return -this->forward();
|
|
}
|
|
|
|
vec3 player::up() const
|
|
{
|
|
return vec_rotate_around_z(vec3(0, 1, 0), this->world_angle_vector());
|
|
}
|
|
|
|
vec3 player::down() const
|
|
{
|
|
return -this->up();
|
|
}
|
|
|
|
//======= Game implementation =======//
|
|
|
|
//======= General utilities =======//
|
|
|
|
|
|
static vec2 platform_rotations[PLATFORM_COUNT];
|
|
static num platform_distance;
|
|
|
|
num space_platform_distance(void)
|
|
{
|
|
return platform_distance;
|
|
}
|
|
|
|
/* We can't use a constructor function because g++ already generates a call to
|
|
the default constructor, which would run after us and override the data. */
|
|
void game_init(void)
|
|
{
|
|
num arc = space_platform_arc();
|
|
|
|
for(int i = 0; i < PLATFORM_COUNT; i++) {
|
|
num angle = arc * i - (arc / 2);
|
|
platform_rotations[i] = vec2(num_cos(angle), num_sin(angle));
|
|
}
|
|
|
|
platform_distance = LEVEL_RADIUS * num_cos(arc / 2);
|
|
}
|
|
|
|
struct prect space_platform_position(int platform_id, num z)
|
|
{
|
|
struct prect r;
|
|
vec3 radius(0, -LEVEL_RADIUS, z);
|
|
|
|
int angle_l = platform_id;
|
|
int angle_r = (platform_id + 1) % PLATFORM_COUNT;
|
|
|
|
r.nl = r.fl = vec_rotate_around_z(radius, platform_rotations[angle_l]);
|
|
r.nr = r.fr = vec_rotate_around_z(radius, platform_rotations[angle_r]);
|
|
|
|
r.fl.z += SECTION_LENGTH;
|
|
r.fr.z += SECTION_LENGTH;
|
|
return r;
|
|
}
|