2021-06-01 17:49:29 +02:00
|
|
|
//---
|
|
|
|
// entities: Objects that move around the map
|
|
|
|
//---
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "geometry.h"
|
|
|
|
|
2021-06-02 16:45:02 +02:00
|
|
|
/* Entity types */
|
|
|
|
enum {
|
|
|
|
ENTITY_AGENT,
|
|
|
|
ENTITY_PARTICLE,
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
/* Entity type */
|
|
|
|
uint16_t type;
|
|
|
|
|
2021-06-01 17:49:29 +02:00
|
|
|
/* Coordinates of the entity's hitbox center on the map */
|
2021-06-02 16:45:02 +02:00
|
|
|
fixed_t x, y;
|
2021-06-01 17:49:29 +02:00
|
|
|
|
2021-06-02 16:45:02 +02:00
|
|
|
union {
|
|
|
|
/* ENTITY_AGENT */
|
|
|
|
struct {
|
|
|
|
/* Entity's hitbox */
|
|
|
|
shape_t hitbox;
|
|
|
|
/* Facing */
|
|
|
|
uint8_t facing;
|
|
|
|
} agent;
|
|
|
|
|
|
|
|
/* ENTITY_PARTICLE */
|
|
|
|
struct {
|
|
|
|
fixed_t z;
|
|
|
|
fixed_t vx, vy, vz;
|
|
|
|
} part;
|
|
|
|
};
|
|
|
|
|
|
|
|
} entity_t;
|
2021-06-01 22:06:58 +02:00
|
|
|
|
|
|
|
/* Move an entity in the map space, assumes no collisions. */
|
2021-06-02 16:45:02 +02:00
|
|
|
void entity_move(entity_t *e, fixed_t dx, fixed_t dy);
|
|
|
|
|
|
|
|
/* Distance quared between two entities */
|
|
|
|
fixed_t entity_distance2(entity_t const *e1, entity_t const *e2);
|
|
|
|
|
|
|
|
/* Unit vector in the direction the agent is facing */
|
|
|
|
fpoint_t entity_facing(entity_t const *e);
|