generated from psywave-games/c-game-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_game.c
112 lines (95 loc) · 2.96 KB
/
simple_game.c
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
/*******************************************************************************************
*
* raylib
*
* Coco Battle Royale
* <Game description>
*
********************************************************************************************/
#include "src/color.c"
#include "src/input.c"
#include "src/player.c"
#include "src/ia_bot.c"
static Tick game_tickets;
static player_t game_rank;
int main(void)
{
const int screenWidth = DEFAULT_SCREEN_WIDTH;
const int screenHeight = DEFAULT_SCREEN_HEIGHT;
InitWindow(screenWidth, screenHeight, GAME_TITLE);
SetTargetFPS(GAME_FPS);
while (!WindowShouldClose())
{
/// PREPARE GAME
static bool pause = false;
static bool reset = true;
static bool fps = false;
// RESET GAME
if (reset) {
ColorBackground(true);
for (player_t i = 0; i < MAX_PLAYERS; PlayerInit(i), i++);
for (player_t i = 1; i < MAX_PLAYERS; BotIaInit(i), i++);
game_tickets = 0;
pause = false;
reset = false;
}
// PRE-STEP GAME
InputStep();
PlayerMediatorStep();
PlayerCountStep();
game_tickets += !pause;
// STEP GAME
if (!pause && IsGameStarted()) {
for (player_t i = 0; i < MAX_PLAYERS; PlayerStep(i), i++);
for (player_t i = 0; i < MAX_PLAYERS; BotIaStep(i), i++);
}
// PLAYER SCORE
if (!PlayerDeath(0)) {
game_rank = PlayerCount();
}
// -------------------------------------------------------- //
BeginDrawing();
ClearBackground(ColorBackground(false));
// players draw
for (
player_t i = 0, j = IsGameStarted()? MAX_PLAYERS: 1;
i < j; PlayerDraw(i), i++
);
// draw text pause
if (pause){
DrawText("PAUSED!", 10, 64, 32, LIGHTGRAY);
}
// draw text fp
if (fps) {
DrawFPS(10,0);
}
// draw wait time
if (!IsGameStarted()){
const char* text = TextFormat("starting at %02d...", GAME_AWAIT - (game_tickets/GAME_FPS));
DrawText(text, screenWidth/2, screenHeight/2, 32, LIGHTGRAY);
}
// draw game over
if (PlayerCount() <= 1){
const char* text = PlayerDeath(0)?
TextFormat("#%02d\nYou were fried.", game_rank):
"#1\nYou Are\nUltimate\nHot Chicken!!";
DrawText(text, screenWidth/2, screenHeight/2, 32, LIGHTGRAY);
}
EndDrawing();
// -------------------------------------------------------- //
// END STEP
fps = IsKeyPressed(KEY_F)? !fps: fps;
pause = IsKeyPressed(KEY_P)? !pause: pause;
reset = IsKeyPressed(KEY_R);
}
CloseWindow();
return 0;
}
bool IsGameStarted()
{
return (GAME_FPS * GAME_AWAIT) < game_tickets;
}
Tick GameStep()
{
return game_tickets;
}