# 資訊專題 block blast遊戲 main ## 程式碼 main.cpp ```cpp= #include <raylib.h> #include "game.h" #include "colors.h" #include <iostream> double lastUpdateTime = 0; bool EventTriggered(double interval) { double currentTime = GetTime(); if (currentTime - lastUpdateTime >= interval) { lastUpdateTime = currentTime; return true; } return false; } int hscore; int main() { InitWindow(1000, 1000, "raylib Block Blast"); SetTargetFPS(60); Font font = LoadFontEx("Font/monogram.ttf", 64, 0, 0); Game game = Game(); while (WindowShouldClose() == false) { UpdateMusicStream(game.music); game.HandleInput(); if (EventTriggered(0.2)) { //game.MoveBlockDown(); } BeginDrawing(); ClearBackground(darkBlue); DrawTextEx(font, "Score", {700, 15}, 38, 2, WHITE); DrawTextEx(font, "Highest Score", {700, 500}, 38, 2, WHITE); DrawTextEx(font, "Next", {705, 175}, 38, 2, WHITE); if (game.gameOver) { DrawTextEx(font, "GAME OVER", {320, 800}, 38, 2, WHITE); } DrawRectangleRounded({750, 55, 100, 60}, 0.3, 6, lightBlue); DrawRectangleRounded({750, 550, 100, 60}, 0.3, 6, lightBlue); char scoreText[10]; sprintf(scoreText, "%d", game.score); hscore = std::max(hscore, game.score); Vector2 textSize = MeasureTextEx(font, scoreText, 38, 2); DrawTextEx(font, scoreText, {700 + (170 - textSize.x) / 2, 65}, 38, 2, WHITE); sprintf(scoreText, "%d", hscore); DrawTextEx(font, scoreText, {700 + (170 - textSize.x) / 2, 560}, 38, 2, WHITE); DrawRectangleRounded({675, 215, 275, 250}, 0.3, 6, lightBlue); game.Draw(); EndDrawing(); } CloseWindow(); } ```