-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.h
144 lines (117 loc) · 3.78 KB
/
game.h
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#pragma once
#include <furi.h>
#include <engine/game_engine.h>
#include <engine/game_manager_i.h>
#include "game_menu.h"
#include "reinforcement_learning_logic.h"
#include "game_level.h"
#include "tutorial_level.h"
/* Global game defines go here */
#define WORLD_BORDER_LEFT_X 6
#define WORLD_BORDER_RIGHT_X 120
#define WORLD_BORDER_TOP_Y 6
#define WORLD_BORDER_BOTTOM_Y 53
#define WORLD_TRANSITION_LEFT_STARTING_POINT 0
#define WORLD_TRANSITION_LEFT_ENDING_POINT 4
#define BULLET_DISTANCE_THRESHOLD 8
#define STARTING_PLAYER_HEALTH 11
#define STARTING_ENEMY_HEALTH 5
#ifdef __cplusplus
extern "C" {
#endif
//#define DEBUGGING
//Configurable variables
//While debugging we increase all lives for longer testing/gameplay.
static const EntityDescription player_desc;
static const EntityDescription enemy_desc;
//Enemy structure
typedef struct {
Entity* instance;
bool direction;
bool jumping;
float targetY;
int lives;
uint32_t spawnTime;
uint32_t mercyTicks;
uint32_t lastShot;
} Enemy;
#define MAX_ENEMIES 30
extern Enemy enemies[MAX_ENEMIES];
extern int ENEMY_LIVES;
extern uint32_t shootingDelay;
extern uint32_t enemyShootingDelay;
extern float bulletMoveSpeed;
extern float speed;
extern float enemySpeed;
extern float jumpHeight;
extern float jumpSpeed;
extern float enemyJumpHeight;
//Tracking player data
extern int health;
extern uint32_t kills;
extern bool jumping;
extern float targetY;
extern float targetX;
extern bool horizontalGame;
extern bool horizontalView;
#define TRANSITION_FRAMES 15
extern int16_t transitionLeftTicks;
extern int16_t transitionRightTicks;
//Internals
extern int firstMobSpawnTicks;
extern uint32_t firstKillTick;
extern uint32_t secondKillTick;
extern uint32_t gameBeginningTick;
extern Level* gameLevel;
extern GameManager* globalGameManager;
//Functions
float lerp(float y1, float y2, float t);
void enemy_spawn(
Level* level,
GameManager* manager,
Vector spawnPosition,
uint32_t mercyTicks,
bool right);
bool damage_player(Entity* self);
void player_update(Entity* self, GameManager* manager, void* context);
void player_render(Entity* self, GameManager* manager, Canvas* canvas, void* context);
void enemy_render(Entity* self, GameManager* manager, Canvas* canvas, void* context);
void enemy_update(Entity* self, GameManager* manager, void* context);
typedef struct {
Sprite* sprite;
Sprite* sprite_left;
Sprite* sprite_left_shadowed;
Sprite* sprite_left_recoil;
Sprite* sprite_right;
Sprite* sprite_right_shadowed;
Sprite* sprite_right_recoil;
Sprite* sprite_jump;
Sprite* sprite_stand;
Sprite* sprite_forward;
} PlayerContext;
typedef struct {
uint32_t score;
} GameContext;
static const EntityDescription player_desc = {
.start = NULL, // called when entity is added to the level
.stop = NULL, // called when entity is removed from the level
.update = player_update, // called every frame
.render = player_render, // called every frame, after update
.collision = NULL, // called when entity collides with another entity
.event = NULL, // called when entity receives an event
.context_size =
sizeof(PlayerContext), // size of entity context, will be automatically allocated and freed
};
static const EntityDescription enemy_desc = {
.start = NULL, // called when entity is added to the level
.stop = NULL, // called when entity is removed from the level
.update = enemy_update, // called every frame
.render = enemy_render, // called every frame, after update
.collision = NULL, // called when entity collides with another entity
.event = NULL, // called when entity receives an event
.context_size =
sizeof(PlayerContext), // size of entity context, will be automatically allocated and freed
};
#ifdef __cplusplus
}
#endif