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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
#pragma once
#include <raylib.h>
#include <stdbool.h>
#include <stdint.h>
#include "constants.h"
#define ENTITY_ALLOCATED 1
#define ENTITY_VISIBLE (1 << 1)
#define ENTITY_PHYSICS_ACTIVE (1 << 2)
typedef enum EntityType {
Player_Entity,
Wall_Entity,
Background_Entity,
Barrel_Entity
} EntityType;
typedef enum DrawLayer {
Background_Layer = 0,
Foreground_Layer = 1
} DrawLayer;
typedef struct Animation {
int numFrames;
bool isLooping;
bool isComplete;
Rectangle srcRects[MAX_FRAMES];
float frameTimes[MAX_FRAMES];
int currentFrame;
float currentFrameTimer;
} Animation;
typedef struct Sprite {
Texture2D texture;
DrawLayer layer;
Rectangle destRect; //Destination rectangle relative to player position
Rectangle srcRect; //For un-animated sprites only
bool flipX;
bool flipY;
int numAnimations; //Zero for static spritesx
Animation animations[MAX_ANIMATIONS];
int currentAnimation;
} Sprite;
typedef struct Entity {
int id;
EntityType type;
uint16_t flags;
Vector2 position;
Vector2 velocity;
//Physics information
Rectangle physicsCollider;
int numHitBoxes;
Rectangle hitBoxes[MAX_AREA_COUNT];
int numHurtBoxes;
Rectangle hurtBoxes[MAX_AREA_COUNT];
Sprite sprites[MAX_SPRITE_COUNT];
int numSprites;
#ifdef BEATEMUP_DEBUG
//Debug information
Color physicsColliderColor;
#endif
//Human entity information
int bodySpriteIndex;
} Entity;
typedef struct Game {
bool paused;
Entity entities[MAX_ENTITY_COUNT];
Camera2D camera;
#ifdef BEATEMUP_DEBUG
//Debug information
bool enableDebugOverlay;
#endif
} Game;
//Entity Stuff
void AddEntity(Entity* e);
void AddWall(float xpos, float ypos, float width, float height);
//Game Stuff
void InitGame();
void UpdateGame(float deltaTime);
void DrawGame();
//Sprite Stuff
void UpdateCurrentSpriteAnimation(Sprite* sprite, float dt);
void DrawEntitySprite(const Entity* e, int spriteIndex);
Rectangle GetSrcRectFromIndex
(
Texture texture,
int framesX,
int framesY,
int index
);
typedef struct {
Texture texture;
int framesX;
int framesY;
int numFrames;
bool isLooping;
int* indices;
float* frameTimes;
} AnimationFromIndicesParams;
Animation AnimationFromIndices(AnimationFromIndicesParams params);
#ifdef BEATEMUP_DEBUG
void DebugHighlights(const Entity* e);
#endif
|