-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTheMoving.c
More file actions
238 lines (206 loc) · 8.17 KB
/
Copy pathTheMoving.c
File metadata and controls
238 lines (206 loc) · 8.17 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*******************************************************************************************
*
* The Moving - A game
*
* This game has been created using raylib 2.5 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2021 Chair050 (@Chair050)
*
********************************************************************************************/
#include "raylib.h"
#include<stdio.h>
int main(void)
{
const int screenWidth = 1000;
const int screenHeight = 650;
InitWindow(screenWidth, screenHeight, "The Moving");
//Boxes That makes the labyrinth
Rectangle boxA = { 65, 50, 30, 570 };
Rectangle boxB = { 950, 50, 30, 570 };
Rectangle boxC = { 65, 590, 915, 30 };
Rectangle boxD = { 160, 50, 790, 30 };
Rectangle boxE = { 160, 50, 30, 480 };
Rectangle boxF = { 160, 500, 740, 30 };
Rectangle boxG = { 870, 130, 30, 400 };
Rectangle boxH = { 250, 130, 640, 30 };
Rectangle boxI = { 250, 130, 30, 315 };
Rectangle boxL = { 250, 415, 550, 30 };
Rectangle boxM = { 790, 205, 30, 240 };
Rectangle boxN = { 350, 205, 450, 30};
Rectangle boxO = { 330, 205, 30, 160};
Rectangle VictoryBox = {550, 300, 50, 50};
// Box B: Mouse moved box
Rectangle Box = {10, 10, 40, 40 };
/*Roba Utile
Rectangle NameRectangle = {Xpos ,Ypos ,Width,Height};
DrawText(TextFormat("SCORE: %i", score), 280, 130, 40, MAROON);-->Per stampare come se fosse in un printf
*/
bool collision = false; // Collision detection
bool victory = false; //Victory Detection
bool pause = false; //Pause Detector
int x=0,y=0; //For Movement
int Time = 0;
int score = 0;
int hiscore= 100000000;
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
while (!WindowShouldClose())
{
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("Press S to start",250,280, 60, MAROON);
EndDrawing();
if(IsKeyDown('S')){
while(1<2){
if(!collision && !victory && !pause){
Box.x+=x;
Box.y+=y;
if(IsKeyReleased(KEY_W)){
y=-3;
x=0;
}
else if(IsKeyReleased(KEY_A)){
x=-3;
y=0;
}
else if(IsKeyReleased(KEY_D)){
x=+3;
y=0;
}
else if(IsKeyPressed(KEY_S)){
y=+3;
x=0;
}
Time++;
}
// Check boxes collision
if(!collision){
collision = CheckCollisionRecs(boxA,Box);
if(collision){
goto collision;
}
collision = CheckCollisionRecs(boxB,Box);
if(collision){
goto collision;
}
collision = CheckCollisionRecs(boxC,Box);
if(collision){
goto collision;
}
collision = CheckCollisionRecs(boxD,Box);
if(collision){
goto collision;
}
collision = CheckCollisionRecs(boxE,Box);
if(collision){
goto collision;
}
collision = CheckCollisionRecs(boxF,Box);
if(collision){
goto collision;
}
collision = CheckCollisionRecs(boxG,Box);
if(collision){
goto collision;
}
collision = CheckCollisionRecs(boxH,Box);
if(collision){
goto collision;
}
collision = CheckCollisionRecs(boxI,Box);
if(collision){
goto collision;
}
collision = CheckCollisionRecs(boxL,Box);
if(collision){
goto collision;
}
collision = CheckCollisionRecs(boxM,Box);
if(collision){
goto collision;
}
collision = CheckCollisionRecs(boxN,Box);
if(collision){
goto collision;
}
collision = CheckCollisionRecs(boxO,Box);
if(collision){
goto collision;
}
victory = CheckCollisionRecs(VictoryBox,Box);
}
BeginDrawing();
ClearBackground(RAYWHITE);
DrawRectangleRec(boxA, GOLD);
DrawRectangleRec(boxB, GOLD);
DrawRectangleRec(boxC, GOLD);
DrawRectangleRec(boxD, GOLD);
DrawRectangleRec(boxE, GOLD);
DrawRectangleRec(boxF, GOLD);
DrawRectangleRec(boxG, GOLD);
DrawRectangleRec(boxH, GOLD);
DrawRectangleRec(boxI, GOLD);
DrawRectangleRec(boxL, GOLD);
DrawRectangleRec(boxM, GOLD);
DrawRectangleRec(boxN, GOLD);
DrawRectangleRec(boxO, GOLD);
DrawRectangleRec(VictoryBox, SKYBLUE);
DrawRectangleRec(Box, BLUE);
if(victory){
score=Time;
if(score<hiscore){
hiscore=score;
}
DrawText("VICTORY!",400,280, 60, BLACK);
DrawText("Press X to Exit or Press M to play again",320,340, 20, BLACK);
DrawText(TextFormat("SCORE: %i", score), 360, 380, 20, BLACK);
DrawText(TextFormat("HI-SCORE: %i", hiscore), 360, 410, 30, BLACK);
if(IsKeyDown('X')){
EndDrawing();
CloseWindow();
}
else if(IsKeyDown('M')){
EndDrawing();
victory = !victory;
Box.x=10;
Box.y=10;
x=0;
y=0;
Time = 0;
score = 0;
}
}
collision:if (collision)
{
DrawText("GAME OVER!",400,280, 40, RED);
DrawText("Press X to Exit or Press M to play again",320,320, 20, RED);
if(IsKeyDown('X')){
EndDrawing();
CloseWindow();
}
else if(IsKeyDown('M')){
EndDrawing();
collision = !collision;
Box.x=10;
Box.y=10;
y=0;
x=0;
Time = 0;
}
}
DrawText(TextFormat("Time: %i", Time), 800, 10, 20, LIME);
if(pause){
DrawText("Game Paused",400,280, 40, GRAY);
DrawText("Press X to return to the game",360,320, 20, GRAY);
if(IsKeyDown('X')){
EndDrawing();
pause = !pause;
}
}
EndDrawing();
}
}
}
CloseWindow();
return 0;
}