-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentities.h
More file actions
79 lines (56 loc) · 1.94 KB
/
entities.h
File metadata and controls
79 lines (56 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef ENTITIES
#define ENTITIES
#define MAX_ENTITIES 100
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
typedef enum entity_type{
ship, // 0
asteroid, // 1
bullet, // 2
null // 3
} entity_type_t;
// Orientation from north, in radians.
typedef float orientation_t;
typedef struct positional_entity{
entity_type_t type;
float x;
float y;
// function pointer to render, perhaps?
// Velocity, vector encoded
float dx;
float dy;
// orientation.
orientation_t orientation;
orientation_t dor; // angular momentum
// Size and bounding box
float size; // a radius for now...
// Lifespan in physics ticks
int lifespan;
// True if this should collide with stuff, else false
// NB: colliding entities can hit non-colliding ones,
// but not vice versa (NC+NC = nil, NC+C = C)
bool collides;
bool friction;
} positional_entity_t;
// Keeps a list of entities.
typedef struct scene{
unsigned int max; // Don't bother rendering over this number
positional_entity_t entities[MAX_ENTITIES]; // pointer to head of array
} scene_t;
void eoptimise_scene(scene_t* scene);
void new_entity_raw(positional_entity_t* new, entity_type_t type,
float x, float y, float dx, float dy,
orientation_t orientation, orientation_t dorientation,
float size,
int lifespan, bool collides, bool friction);
positional_entity_t* new_entity(scene_t* scene, entity_type_t type,
float x, float y, float dx, float dy,
orientation_t orientation, orientation_t dorientation,
float size,
int lifespan, bool collides, bool friction);
positional_entity_t* enew_ship(scene_t* scene, float x, float y, float size, bool collides, bool friction);
float eget_fwd_x(positional_entity_t* e, orientation_t o);
float eget_fwd_y(positional_entity_t* e, orientation_t o);
scene_t* enew_scene();
#endif