diff --git a/CmakeLists.txt b/CmakeLists.txt index 9d97137..5056f8b 100644 --- a/CmakeLists.txt +++ b/CmakeLists.txt @@ -48,6 +48,17 @@ FetchContent_Declare(cpr GIT_REPOSITORY https://github.com/libcpr/cpr.git GIT_TAG dec9422db3af470641f8b0d90e4b451c4daebf64) # Replace with your desired git commit from: https://github.com/libcpr/cpr/releases FetchContent_MakeAvailable(cpr) +# fetch asio +FetchContent_Declare(asio + GIT_REPOSITORY git@github.com:chriskohlhoff/asio.git + GIT_TAG master + CONFIGURE_COMMAND "" + BUILD_COMMAND "" +) +FetchContent_GetProperties(asio) +if(NOT asio_POPULATED) + FetchContent_Populate(asio) +endif() find_library(GDIPLUS_LIBRARY NAMES libgdiplus gdiplus) set(GDIPLUS_LIBRARY gdiplus) @@ -65,7 +76,7 @@ set(SRC_FILES add_executable(${PROJECT_NAME} WIN32 ${SRC_FILES}) -target_link_libraries(${PROJECT_NAME} PRIVATE cpr::cpr sol2 lua::lua ${LIBS}) +target_link_libraries(${PROJECT_NAME} PRIVATE cpr::cpr sol2 lua::lua ${LIBS} ) diff --git a/lua/script.lua b/lua/script.lua index dd78e89..f18f3e9 100644 --- a/lua/script.lua +++ b/lua/script.lua @@ -37,7 +37,7 @@ local PLAYING = 1 local GAME_OVER = 2 local SUBMITTING_NAME = 3 -local gameState = MAIN_MENU +local gameState = SUBMITTING_NAME local titleScreenBitmap @@ -50,10 +50,14 @@ local leaderboardFrames = {} local leaderboardFrameTimer = 0 local leaderboardFrameIndex = 1 -local leaderboardFreamSpeed = 1 +local leaderboardFreamSpeed = 0.05 +local gameOverBitmap +local pressRBitmap -local yesButton = button.new(300, 400, 100, 50, "Yes", Color.new(0, 255, 0), function() +local enterNameBitmap + +local yesButton = button.new(350, 400, 100, 50, "Yes", Color.new(0, 255, 0), function() print("Sending Post") local playerName = nameTextBox:GetText() @@ -67,7 +71,7 @@ local yesButton = button.new(300, 400, 100, 50, "Yes", Color.new(0, 255, 0), fun print(response) gameState = GAME_OVER end) -local noButton = button.new(300, 500, 100, 50, "No", Color.new(255, 0, 0), function() gameState = GAME_OVER end) +local noButton = button.new(350, 500, 100, 50, "No", Color.new(255, 0, 0), function() gameState = GAME_OVER end) local hasGottenLeaderBoard = false @@ -275,7 +279,10 @@ function start() newPiece() nameTextBox = Textbox.new("") - nameTextBox:SetBounds(250, 200, 200, 25) + -- Center on screen + local width = 175 + local height = 25 + nameTextBox:SetBounds(math.floor((screenWidth - width) / 2) - 10, 300, width, height) nameTextBox:Hide() titleScreenBitmap = Bitmap.new("resources/tetrisLogo.bmp", true) @@ -288,6 +295,15 @@ function start() bmp:SetTransparencyColor(Color.new(255, 0, 255)) table.insert(leaderboardFrames, bmp) end + + gameOverBitmap = Bitmap.new("resources/leaderboard/game_over.bmp", true) + gameOverBitmap:SetTransparencyColor(Color.new(255, 0, 255)) + + pressRBitmap = Bitmap.new("resources/leaderboard/press_r.bmp", true) + pressRBitmap:SetTransparencyColor(Color.new(255, 0, 255)) + + enterNameBitmap = Bitmap.new("resources/leaderboard/enter_name.bmp", true) + enterNameBitmap:SetTransparencyColor(Color.new(255, 0, 255)) end @@ -385,7 +401,6 @@ function update() end function drawScoreBoard() - GameEngine:fillScreen(Color.new(0, 0, 0)) if not hasGottenLeaderBoard then local response = GameEngine:getRequest("https://api.brammie15.dev/leaderboard/tetris") @@ -401,22 +416,20 @@ function drawScoreBoard() if not netError then for line in response:gmatch("[^\r\n]+") do local name, score = line:match("([^%s]+)%s+(%d+)") - table.insert(leaderboard, { name = name, score = score }) + table.insert(leaderboard, { name = name, score = tonumber(score) }) end table.sort(leaderboard, function(a, b) return a.score > b.score end) end hasGottenLeaderBoard = true end - - GameEngine:setColor(Color.new(255, 0, 0)) - GameEngine:drawText("Score: " .. score, 350, 250) + GameEngine:drawText("Score: " .. score, 350, 400) if hasGottenLeaderBoard then - local NamesX = 600 - local ScoresX = 700 - local Y = 100 + local NamesX = 475 + local ScoresX = 625 + local Y = 150 GameEngine:setColor(Color.new(255, 255, 0)) -- GameEngine:drawText("Leaderboard", 600, 60) @@ -451,26 +464,19 @@ end function drawGameOver() nameTextBox:Hide() - GameEngine:setColor(Color.new(255, 0, 0)) GameEngine:fillScreen(Color.new(0, 0, 0)) - GameEngine:drawText("Game Over", 350, 300) - GameEngine:drawText("Press R to restart", 350, 350) + GameEngine:drawBitmap(gameOverBitmap, 0, 0) + GameEngine:drawBitmap(pressRBitmap, 0, 0) drawScoreBoard() end function drawSubmitName() GameEngine:fillScreen(Color.new(0, 0, 0)) - GameEngine:setColor(Color.new(255, 255, 255)) - GameEngine:drawText("Name:", 200, 200) - local charwidth = 8 - local submitText = "Would you like to submit to the leaderboard" - local submitTextWidth = #submitText * charwidth - GameEngine:drawText(submitText, 400 - submitTextWidth / 2, 50) + GameEngine:drawBitmap(enterNameBitmap, 0, 0) nameTextBox:Show() yesButton:draw(GameEngine) noButton:draw(GameEngine) - end function drawMainMenu() diff --git a/resources/Untitled-1.png b/resources/Untitled-1.png new file mode 100644 index 0000000..37e3a9d Binary files /dev/null and b/resources/Untitled-1.png differ diff --git a/resources/leaderboard/enter_name.bmp b/resources/leaderboard/enter_name.bmp new file mode 100644 index 0000000..be44086 Binary files /dev/null and b/resources/leaderboard/enter_name.bmp differ diff --git a/resources/leaderboard/game_over.bmp b/resources/leaderboard/game_over.bmp new file mode 100644 index 0000000..a30fb6a Binary files /dev/null and b/resources/leaderboard/game_over.bmp differ diff --git a/resources/leaderboard/press_r.bmp b/resources/leaderboard/press_r.bmp new file mode 100644 index 0000000..8272dfa Binary files /dev/null and b/resources/leaderboard/press_r.bmp differ diff --git a/src/Game.cpp b/src/Game.cpp index 232042d..49f955b 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -54,7 +54,7 @@ void Game::Initialize() { AbstractGame::Initialize(); // GAME_ENGINE->SetTitle(_T("Game Engine version 8_01")); - this->FunctionCall("setup_window"); + this->FunctionCall("setup_window"); // Set the keys that the game needs to listen to //Get return value from Lua function @@ -233,7 +233,13 @@ void Game::InitialiseBindings() { "fillScreen", &GameEngine::FillWindowRectRGB, "drawText", sol::overload( sol::resolve(&GameEngine::DrawString), - sol::resolve(&GameEngine::DrawString) + sol::resolve(&GameEngine::DrawString), + [] (GameEngine &gameEngine, int number, int x, int y) { + gameEngine.DrawString(std::to_string(number), x, y); + }, + [] (GameEngine &gameEngine, float number, float x, float y) { + gameEngine.DrawString(std::to_string(number), x, y); + } ), "isKeyDown", [] (GameEngine &gameEngine, const std::string &key) { return gameEngine.IsKeyDown(_T(key[0]));