-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
57 lines (46 loc) · 1.42 KB
/
Copy pathmain.cpp
File metadata and controls
57 lines (46 loc) · 1.42 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
#include <cstdio>
#include <raylib.h>
#include "lib/game.h"
#include "lib/colors.h"
double LastUpdatTime = 0;
bool EventTriggered(double interval){
double currentTime = GetTime();
if(currentTime - LastUpdatTime >= interval){
LastUpdatTime = currentTime;
return true;
}
return false;
}
int main(){
int ScreenWidth = 500;
int ScreenHeight = 620;
InitWindow(ScreenWidth,ScreenHeight,"Raylib Tetris");
SetTargetFPS(60);
Font font = LoadFontEx("fonts/monogram.ttf",64,0,0);
// block.Move(4,3);
Game game = Game();
while (!WindowShouldClose())
{
UpdateMusicStream(game.music);
game.HandleInput();
if(EventTriggered(0.3)){
game.MoveBlockDown();
}
BeginDrawing();
ClearBackground(darkblue);
DrawTextEx(font,"Score",{365, 15},38,2,WHITE);
DrawTextEx(font,"Next",{370, 175},38,2,WHITE);
if(game.GameOver){
DrawTextEx(font,"GAME OVER",{320, 450},38,2,WHITE);
}
DrawRectangleRounded({320,55,170,60},0.3,6,lightblue);
char scoretext[10];
sprintf(scoretext,"%d",game.score);
Vector2 textsize = MeasureTextEx(font,scoretext,38,2);
DrawTextEx(font,scoretext,{320 + (170 - textsize.x)/2, 65},38,2,WHITE);
DrawRectangleRounded({320,215,170,180},0.3,6,lightblue);
game.Draw();
EndDrawing();
}
CloseWindow();
}