forked from raysan5/raylib-intro-course
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01_blocks_game_intro.c
More file actions
171 lines (134 loc) · 6.21 KB
/
01_blocks_game_intro.c
File metadata and controls
171 lines (134 loc) · 6.21 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*******************************************************************************************
*
* PROJECT: BLOCKS GAME
* LESSON 01: raylib intro
* DESCRIPTION: Introduction to raylib and the basic videogames life cycle
*
* COMPILATION (Windows - MinGW):
* gcc -o $(NAME_PART).exe $(FILE_NAME) -lraylib -lopengl32 -lgdi32 -lwinmm -Wall -std=c99
*
* COMPILATION (Linux - GCC):
* gcc -o $(NAME_PART).exe $(FILE_NAME) -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
*
* Example originally created with raylib 2.0, last time updated with raylib 4.2
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2017-2022 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#include "raylib.h"
//----------------------------------------------------------------------------------
// Types and Structures Definition
//----------------------------------------------------------------------------------
// LESSON 01: Window initialization and screens management
typedef enum GameScreen { LOGO, TITLE, GAMEPLAY, ENDING } GameScreen;
// TODO: Define required structs
//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------
int main()
{
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
// LESSON 01: Window initialization and screens management
InitWindow(screenWidth, screenHeight, "PROJECT: BLOCKS GAME");
// NOTE: Load resources (textures, fonts, audio) after Window initialization
// Game required variables
GameScreen screen = LOGO; // Current game screen state
int framesCounter = 0; // General pourpose frames counter
int gameResult = -1; // Game result: 0 - Loose, 1 - Win, -1 - Not defined
bool gamePaused = false; // Game paused state toggle
// TODO: Define and Initialize game variables
SetTargetFPS(60); // Set desired framerate (frames per second)
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
switch(screen)
{
case LOGO:
{
// Update LOGO screen data here!
framesCounter++;
if (framesCounter > 180)
{
screen = TITLE; // Change to TITLE screen after 3 seconds
framesCounter = 0;
}
} break;
case TITLE:
{
// Update TITLE screen data here!
framesCounter++;
// LESSON 03: Inputs management (keyboard, mouse)
if (IsKeyPressed(KEY_ENTER)) screen = GAMEPLAY;
} break;
case GAMEPLAY:
{
// Update GAMEPLAY screen data here!
if (!gamePaused)
{
// TODO: Gameplay logic
}
if (IsKeyPressed(KEY_ENTER)) screen = ENDING;
} break;
case ENDING:
{
// Update END screen data here!
framesCounter++;
// LESSON 03: Inputs management (keyboard, mouse)
if (IsKeyPressed(KEY_ENTER)) screen = TITLE;
} break;
default: break;
}
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
switch(screen)
{
case LOGO:
{
// TODO: Draw LOGO screen here!
DrawText("LOGO SCREEN", 20, 20, 40, LIGHTGRAY);
DrawText("WAIT for 3 SECONDS...", 290, 220, 20, GRAY);
} break;
case TITLE:
{
// TODO: Draw TITLE screen here!
DrawRectangle(0, 0, screenWidth, screenHeight, GREEN);
DrawText("TITLE SCREEN", 20, 20, 40, DARKGREEN);
DrawText("PRESS ENTER or TAP to JUMP to GAMEPLAY SCREEN", 120, 220, 20, DARKGREEN);
} break;
case GAMEPLAY:
{
// TODO: Draw GAMEPLAY screen here!
DrawRectangle(0, 0, screenWidth, screenHeight, PURPLE);
DrawText("GAMEPLAY SCREEN", 20, 20, 40, MAROON);
DrawText("PRESS ENTER or TAP to JUMP to ENDING SCREEN", 130, 220, 20, MAROON);
} break;
case ENDING:
{
// TODO: Draw ENDING screen here!
DrawRectangle(0, 0, screenWidth, screenHeight, BLUE);
DrawText("ENDING SCREEN", 20, 20, 40, DARKBLUE);
DrawText("PRESS ENTER or TAP to RETURN to TITLE SCREEN", 120, 220, 20, DARKBLUE);
} break;
default: break;
}
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
// NOTE: Unload any loaded resources (texture, fonts, audio)
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}