70 lines
1.9 KiB
C
70 lines
1.9 KiB
C
//---
|
|
// mechanical: Component for objects with continuous motion
|
|
//
|
|
// Mechanical entities (which must also be physical) have kinematic properties
|
|
// that carry over from frame to frame, such as speed. The mechanical component
|
|
// itself only holds simulation data, and is controlled by another component
|
|
// (either player input or an AI).
|
|
//---
|
|
|
|
#pragma once
|
|
|
|
#include "comp/entity.h"
|
|
#include "geometry.h"
|
|
#include "map.h"
|
|
|
|
typedef struct
|
|
{
|
|
/* Maximum walking speed (m/s) */
|
|
fixed_t max_speed;
|
|
/* Friction coefficient */
|
|
fixed_t friction;
|
|
|
|
/* Peak dash speed (m/s) */
|
|
fixed_t dash_speed;
|
|
/* Dash duration (s) */
|
|
fixed_t dash_duration;
|
|
|
|
/* Maximum disruption speed, mainly avoids extreme knockback on players
|
|
when attacked for multiple sides at once */
|
|
fixed_t max_disruption_speed;
|
|
|
|
} mechanical_limits_t;
|
|
|
|
typedef struct
|
|
{
|
|
mechanical_limits_t const *limits;
|
|
|
|
/* Position of the mechanical entity is specified in physical.x/y! */
|
|
|
|
/* Current speed */
|
|
fixed_t vx, vy;
|
|
/* Disruption speed to be integrated next frame (eg. knockback) */
|
|
fixed_t vdx, vdy;
|
|
/* Dash time remaining (if positive) or cooldown remaining (if negative) */
|
|
fixed_t dash;
|
|
/* Dash direction */
|
|
uint8_t dash_facing;
|
|
|
|
} mechanical_t;
|
|
|
|
// Movement functions
|
|
|
|
/* Update movement for a 4-directional control (stand still if direction = -1).
|
|
Both the [mechanical] and [physical] components are affected. */
|
|
void mechanical_move4(entity_t *e, int direction, fixed_t dt,map_t const *map);
|
|
|
|
/* Update movement for a full-directional control (for AIs). */
|
|
void mechanical_move(entity_t *e, vec2 direction, fixed_t dt,map_t const *map);
|
|
|
|
/* Start dashing in the specified direction */
|
|
void mechanical_dash(entity_t *e, int direction);
|
|
|
|
// Information functions
|
|
|
|
/* Check if the entity is currently moving */
|
|
bool mechanical_moving(entity_t const *e);
|
|
|
|
/* Check if the entity is currently dashing */
|
|
bool mechanical_dashing(entity_t const *e);
|