Add ghrapics

This commit is contained in:
2025-01-22 02:48:46 +01:00
parent af2f573d60
commit 020985a1bb
7 changed files with 49 additions and 26 deletions

View File

@@ -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} )

View File

@@ -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()

BIN
resources/Untitled-1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

View File

@@ -54,7 +54,7 @@ void Game::Initialize() {
AbstractGame::Initialize();
// GAME_ENGINE->SetTitle(_T("Game Engine version 8_01"));
this->FunctionCall("setup_window");
this->FunctionCall<void>("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<int(const std::string &, int, int) const>(&GameEngine::DrawString),
sol::resolve<int(const std::string &, float, float) const>(&GameEngine::DrawString)
sol::resolve<int(const std::string &, float, float) const>(&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]));