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
|
#include "utils.h"
// Pretty much any object in the game.
#ifndef ENTITY_H
#define ENTITY_H
#define ENTITY_COUNT 14
#define INTERACTION_MENU_MAX 9
#define INTERACTION_LABEL_MAX 64
#define ENTITY_DEFAULT_STATE -1
typedef int8_t EntityId;
typedef int16_t EntityState;
typedef struct Entity Entity;
typedef void (*InteractionCallback)(Entity* entity, Game* game);
typedef void (*InitEntityCallback)(Entity* entity);
typedef void (*UpdateEntityCallback)(Entity* entity, Game* game);
typedef void (*CloseEntityCallback)(Entity* entity);
enum {
ENTITY_NONE = -1,
OLD_MINT,
STICKY_NICKEL,
TREE,
BUSH,
FLOWER,
POND,
UTILITY_POLE,
SAMANTHA,
SAMANTHAS_SPOT,
TRASHCAN,
TRASH,
MEDICAL_TRASH,
JOHN,
RON
};
typedef enum {
INTERACTION_TALK,
INTERACTION_SHOW_MENU,
INTERACTION_END
} InteractionCommand;
typedef enum {
SELECTION_INTERACT,
SELECTION_NEXT_MESSAGE,
SELECTION_MENU_ITEM, // +x to select any given menu entry
SELECTION_LEAVE
} Selection;
struct Entity {
EntityId id;
Vector3 position; // Shouldnt be changed directly.
BoundingBox box;
EntityState state;
void* data;
};
typedef struct {
InitEntityCallback initCallback;
UpdateEntityCallback updateCallback;
CloseEntityCallback closeCallback;
bool isPlace;
bool canBeSelected;
} EntityEntry;
typedef struct {
char label[INTERACTION_LABEL_MAX];
InteractionCallback callback;
} InteractionMenuEntry;
extern const EntityEntry entityEntries[ENTITY_COUNT];
Entity createEntity(EntityId id, Vector3 position);
void updateEntity(Entity* entity, Game* game);
void closeEntity(Entity* entity);
void setEntityPosition(Entity* entity, Vector3 position);
void placeEntityOnGround(Entity* entity, const World* world);
bool entityIsPlace(EntityId id);
bool entityCanBeSelected(EntityId id);
InteractionCommand interactWithEntity(Entity* entity, Game* game,
Selection selection);
BoundingBox entityBoxFromScale(float scale, float width, float height);
#endif
|