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
|
#pragma once
#include <SDL2/SDL.h>
#define from_fixed(a) ((a) / 16)
#define to_fixed(a) ((a) * 16)
struct hitbox {
unsigned left, right, top, bottom;
};
static inline int hitbox_overlap(struct hitbox const a, struct hitbox const b) {
return a.left <= b.right && a.right >= b.left && a.top <= b.bottom && a.bottom >= b.top;
}
struct vec2 {
signed x, y;
};
struct anim {
unsigned frame;
SDL_Rect rect;
unsigned length;
};
enum factions {
FACTION_PLAYER,
FACTION_ENEMY,
};
struct damage {
int damage, iframes;
};
struct entity {
int (*update)(struct entity *self);
int (*hurt)(struct entity *self, struct damage damage);
int (*draw)(struct entity *self, int camx, int camy);
void (*free)(struct entity *self);
int x, y; // unsigned results in a bunch of weird edge cases
struct vec2 velocity;
struct hitbox hitbox;
struct anim anim;
unsigned state;
int hp;
int timer;
int iframes;
signed facing;
enum factions faction;
void *texture;
void *ext;
};
struct warp {
int (*update)(struct warp *);
int x, y;
unsigned w, h;
int tox, toy;
struct hitbox hitbox;
unsigned timer;
void *ext;
};
struct projectile {
int (*update)(struct projectile *self);
int (*draw)(struct projectile *self, int camx, int camy);
void (*free)(struct projectile *self);
int x, y; // unsigned results in a bunch of weird edge cases
struct vec2 velocity;
struct hitbox hitbox;
struct anim anim;
unsigned state;
int hp;
int timer;
int iframes;
signed facing;
enum factions faction;
void *texture;
void *ext;
};
struct particle {
int x, y;
struct vec2 velocity;
struct vec2 acceleration;
SDL_Rect rect;
int hp;
};
|