-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentity.h
More file actions
82 lines (58 loc) · 1.61 KB
/
entity.h
File metadata and controls
82 lines (58 loc) · 1.61 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
80
81
82
#ifndef _ENTITY_H
#define _ENTITY_H
#include <stdbool.h>
#include "vec2.h"
#include "gfx.h"
#define ENTITY_INITIAL_CACHE_SIZE 256
typedef enum
{
ROOT,
TAG_START,
TAG_END,
SHIP,
BULLET_SHIP,
ASTEROID,
SPARK
} ENTITY_TYPE;
typedef struct Entity Entity;
struct Entity
{
ENTITY_TYPE type;
bool is_enabled;
bool is_destroyed;
bool is_invincible;
uint32_t invincible_time;
uint32_t life_time;
//used for circle-circle collision detection
int32_t radius_collision;
// used to wrap position of this entity
int32_t radius_wrap;
Vec2 position;
Vec2 velocity;
Vec2 acceleration;
fixed angle;
fixed angular_speed;
Polygon *polygon;
void (*hit)(Entity *entity);
void (*fixed_update)(Entity *entity);
void (*render)(Entity *entity);
void (*destroy)(Entity *entity);
Entity *previous_entity;
Entity *next_entity;
};
extern void entity_init();
extern Entity* entity_create();
extern Entity* entity_get_from_cache();
extern void entity_add(Entity *entity);
extern void entity_add_after(Entity *entity_after, Entity *entity);
extern void entity_remove(Entity *entity);
extern void entity_remove_all();
extern Entity* entity_find_first_type(ENTITY_TYPE type);
extern void entity_update_all();
extern void entity_render(Entity* entity);
extern void entity_render_all();
extern void entity_destroy(Entity* entity);
extern void entity_wrap_position(Entity *entity);
extern bool entity_is_out_of_display_area(Entity *entity);
extern bool entity_check_collision(Entity *entity_a, Entity *entity_b);
#endif /* _ENTITY_H */