summaryrefslogtreecommitdiff
path: root/inc/entity.h
blob: ee8b935c9cd59ef06b61ce3795cbe348b5f808b9 (plain)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#pragma once

enum { MAX_GROUP_WORDS = 8 };
enum { EVENT_INIT, EVENT_JUMP, EVENT_DOUBLEJUMP, EVENT_DEATH, EVENT_LASTKEY };

typedef struct EntityColor {
	f32 r, g, b;
} EntityColor;

typedef struct Entity {
	ETable *table;
	u64 uuid;
	u32 super_depth;
	char name[32];
	u32 tile;
	u32 group[MAX_GROUP_WORDS];
	const Tiled2cObject *t2c;

	bool visible;
	bool visible_next;
	bool flip_x;
	bool flip_y;
	vec2 pos;
	vec2 rem;
	vec2 vel;
	vec2 dim;

	// player
	i8 reverseGravity;
	i32 jump_buffer;
	i32 grace;
	bool djump;
	u32 air;
	u32 animation;
	bool dead;

	// trigger
	u64 prev;
	u64 next;
	u32 target;
	u32 tick;
	u8 type;
	bool on;
	bool multi;
	bool leave;
	bool do_x;
	bool do_y;
	u8 color_group;
	u32 fade_in;
	EntityColor initial_color;
	EntityColor color;
} Entity;

vec_decl(EntityP, Entity *);

void entity_method(Entity *, const char *method);
void entity_super(Entity *, const char *method);
[[deprecated("replaced by entities")]] bool entity_collide(Entity *, vec2 off,
                                                           u32 type);
bool entity_collide_solid(Entity *, vec2 off);
bool entity_collide_spike(Entity *, vec2 off);
bool entity_intersect(Entity *, vec2 off, Entity *);
vec2 entity_move(Entity *, vec2 force);
Entity *entity_place_meeting(Entity *, vec2 off, const char *type,
                             bool visible);
VecEntityP *entity_place_meeting_list(Entity *, vec2 off, const char *type,
                                      bool visible);
i32 entity_propertyi(Entity *, const char *property);
i32 entity_propertyi_default(Entity *, const char *property, i32 def);
i32 entity_propertyo(Entity *, const char *property);
i32 entity_propertyo_default(Entity *, const char *property, i32 def);
f32 entity_propertyf(Entity *, const char *property, f32 def);
bool entity_propertyb(Entity *, const char *property);
const char *entity_propertyc(Entity *, const char *property);
void entity_append_group(Entity *, u32 gid);
void entity_append_groups(Entity *, const char *);
void entity_copy_groups(Entity *, Entity *);
bool entity_in_group(Entity *, u32 gid);

#define method(X)              entity_method(this, (X))
#define super(X)               entity_super(this, (X))
#define collide(O, T)          entity_collide(this, (O), (T))
#define collide_solid(O)       entity_collide_solid(this, (O))
#define collide_spike(O)       entity_collide_spike(this, (O))
#define move(X)                entity_move(this, (X));
#define intersect(O, E)        entity_intersect(this, (O), (E))
#define place_meeting(O, T, V) entity_place_meeting(this, (O), (T), (V))
#define place_meeting_list(O, T, V)                                            \
	entity_place_meeting_list(this, (O), (T), (V))
#define propertyi(X)            entity_propertyi(this, (X))
#define propertyi_default(X, V) entity_propertyi_default(this, (X), (V))
#define propertyo(X)            entity_propertyo(this, (X))
#define propertyo_default(X, V) entity_propertyo_default(this, (X), (V))
#define propertyf(X, V)         entity_propertyf(this, (X), (V))
#define propertyb(X)            entity_propertyb(this, (X))
#define propertyc(X)            entity_propertyc(this, (X))
#define draw_hitbox(...)                                                       \
	TZR_DrawSetColor(__VA_ARGS__, .a = 0.5),                               \
	    TZR_DrawRectangle((i32)POS.x, (i32)POS.y, DIM.x, DIM.y, true,      \
	                      true),                                           \
	    TZR_DrawRectangle((i32)POS.x, (i32)POS.y, DIM.x, DIM.y, false,     \
	                      true),                                           \
	    TZR_DrawSetColor(.a = 1)