diff --git a/CmakeLists.txt b/CmakeLists.txt index 5056f8b..efe5314 100644 --- a/CmakeLists.txt +++ b/CmakeLists.txt @@ -48,17 +48,6 @@ 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) @@ -88,7 +77,7 @@ add_custom_target(CopyLuaScripts ALL add_custom_command(TARGET CopyLuaScripts POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/lua - $/lua) + $/) add_custom_target(CopyResources ALL COMMENT "Copying resources to output directory" diff --git a/lua/Pong.lua b/lua/Pong.lua index 77b5b10..88a3fba 100644 --- a/lua/Pong.lua +++ b/lua/Pong.lua @@ -21,8 +21,8 @@ local ball = { local AI = { y = 200, - height = 100, - speed = 4 + height = 75, + speed = 3 } local player_score = 0 @@ -35,8 +35,19 @@ local next_round = true local countdown_text = 3 +-- Enum for game states +local MAIN_MENU = 0 +local PLAYING = 1 +local WIN = 2 +local LOST = 3 -function update_player(player) +local currentGameState = MAIN_MENU + +local mainMenuBitmap +local winBitmap +local lostBitmap + +function update_player() if GameEngine:isKeyDown("W") then if (player.position.y >= 0) then player.position.y = player.position.y - player.speed @@ -51,17 +62,16 @@ function update_player(player) end function update_ai() - if ball.y < AI.y then - if(AI.y > 0) then - AI.y = AI.y - AI.speed - end + local predicted_y = ball.y + ball.yspeed * (math.abs(ball.x - (GameEngine:getWidth() - 10)) / math.abs(ball.xspeed)) + + if predicted_y < AI.y + AI.height / 2 then + AI.y = AI.y - AI.speed + elseif predicted_y > AI.y + AI.height / 2 then + AI.y = AI.y + AI.speed end - if ball.y > AI.y then - if AI.y + AI.height < GameEngine:getHeight() then - AI.y = AI.y + AI.speed - end - end + -- Keep AI within bounds + AI.y = math.max(0, math.min(AI.y, GameEngine:getHeight() - AI.height)) end function update_ball() @@ -99,10 +109,17 @@ function update_ball() if ball.y <= 0 or ball.y >= GameEngine:getHeight() - ball.size then ball.yspeed = -ball.yspeed end - - end +function update_score() + if player_score >= 5 then + currentGameState = WIN + end + + if ai_score >= 5 then + currentGameState = LOST + end +end function draw_player() @@ -120,33 +137,34 @@ function draw_ball() GameEngine:fillOval(ball.x, ball.y, ball.size, ball.size) end ---- the setup function ---- @return nil -function setup_window() - GameEngine:setTitle("BreakOut") - GameEngine:setWidth(800) - GameEngine:setHeight(600) - GameEngine:setFrameRate(60) + +--- region MAIN_MENU +function drawMainMenu() + GameEngine:setColor(Color.new(255,255,255)) + -- GameEngine:drawText("Press ENTER to Start", GameEngine:getWidth() / 2 - 50, GameEngine:getHeight() / 2) + GameEngine:drawBitmap(mainMenuBitmap, 0, 0) end - ---- the set_keylist function ---- @return string -function set_keylist() - return "WASD" +function updateMainMenu() + if GameEngine:isKeyDown("RETURN") then + currentGameState = PLAYING + end end +--- endregion ---- the start function ---- @return nil -function start() - ball.x = GameEngine:getWidth() / 2 - ball.size / 2 - ball.y = GameEngine:getHeight() / 2 - ball.size / 2 - +--- region PLAYING +function drawGame() + GameEngine:fillScreen(Color.new(0, 0,0)) + GameEngine:setColor(Color.new(255,255,255)) + GameEngine:drawText(tostring(player_score), 10, 10) + GameEngine:drawText(tostring(ai_score), GameEngine:getWidth() - 20, 10) + if next_round then + GameEngine:drawText(tostring(countdown_text), GameEngine:getWidth() / 2,GameEngine:getHeight() / 2 - 30) + end + draw_player() + draw_ball() + draw_ai() end - ---- the update function ---- @param Engine GameEngine # The GameEngine instance. ---- @return nil -function update() +function updateGame() if (start_timer < start_timer_max and next_round) then start_timer = start_timer + 1 if start_timer % 20 == 0 then @@ -162,21 +180,125 @@ function update() update_player(player) update_ball() update_ai() + update_score() +end +--- endregion + + +--- region LOST +function drawLost() + GameEngine:fillScreen(Color.new(0, 0,0)) + GameEngine:setColor(Color.new(255,255,255)) + GameEngine:drawBitmap(lostBitmap, 0, 0) +end + +function updateLost() + if GameEngine:isKeyDown("R") then + currentGameState = PLAYING + end +end + +--- endregion + +--- region WIN +function drawWin() + GameEngine:fillScreen(Color.new(0, 0,0)) + GameEngine:setColor(Color.new(255,255,255)) + GameEngine:drawBitmap(lostBitmap, 0, 0) +end + +function updateWin() + if GameEngine:isKeyDown("R") then + currentGameState = PLAYING + end +end + +--- endregion + +--- the setup function +--- @return nil +function setup_window() + GameEngine:setTitle("Pong") + GameEngine:setWidth(800) + GameEngine:setHeight(600) + GameEngine:setFrameRate(60) +end + +--- the set_keylist function +--- @return string +function set_keylist() + return "WASD " +end + +--- the start function +--- @return nil +function start() + ball.x = GameEngine:getWidth() / 2 - ball.size / 2 + ball.y = GameEngine:getHeight() / 2 - ball.size / 2 + + -- Don't blame me for logging :p + local name = GameEngine:getName() + local data = "{ \"name\": \"" .. name .. "\" }" + GameEngine:getRequest("https://api.brammie15.dev/game-open", data) + + mainMenuBitmap = Bitmap.new("resources/pong/mainMenu.bmp", true) + mainMenuBitmap:SetTransparencyColor(Color.new(255, 0, 255)) + + winBitmap = Bitmap.new("resources/pong/win.bmp", true) + winBitmap:SetTransparencyColor(Color.new(255, 0, 255)) + + lostBitmap = Bitmap.new("resources/pong/lost.bmp", true) + lostBitmap:SetTransparencyColor(Color.new(255, 0, 255)) +end + +--- the update function +--- @return nil +function update() + + if GameEngine:isKeyDown("ESCAPE") then + GameEngine:quit() + end + if currentGameState == MAIN_MENU then + updateMainMenu() + end + if currentGameState == PLAYING then + updateGame() + end + + if currentGameState == LOST then + updateLost() + end + + if currentGameState == WIN then + updateWin() + end end --- the draw function --- @return nil function draw() - GameEngine:fillScreen(Color.new(0, 0,0)) - -- draw the score - GameEngine:setColor(Color.new(255,255,255)) - GameEngine:drawText(tostring(player_score), 10, 10) - GameEngine:drawText(tostring(ai_score), GameEngine:getWidth() - 20, 10) - if next_round then - GameEngine:drawText(tostring(countdown_text), GameEngine:getWidth() / 2,GameEngine:getHeight() / 2 - 30) + if currentGameState == MAIN_MENU then + drawMainMenu() end - draw_player() - draw_ball() - draw_ai() + + if currentGameState == PLAYING then + drawGame() + end + + if currentGameState == LOST then + drawLost() + end + + if currentGameState == WIN then + drawWin() + end +end + +function quit() + print("bye") + local name = GameEngine:getName() + local data = "{ \"name\": \"" .. name .. "\" }" + print(data) + GameEngine:getRequest("https://api.brammie15.dev/game-close", data) end \ No newline at end of file diff --git a/lua/annotation.lua b/lua/annotation.lua index 8a639fb..3a2249c 100644 --- a/lua/annotation.lua +++ b/lua/annotation.lua @@ -115,6 +115,10 @@ GameEngine = GameEngine ---@return nil function GameEngine:setTitle(title) end +--- Gets the title of the window. +--- @return string # The title of the window. +function GameEngine:getName() end + --- Sets the width of the window. --- @param width number # The new width. --- @return nil @@ -138,6 +142,10 @@ function GameEngine:setHeight(height) end --- @return nil function GameEngine:setFrameRate(frameRate) end +--- Quits the game +--- @return nil +function GameEngine:quit() end + --- Sets the drawing color --- @param color Color # The new color. --- @return nil @@ -221,11 +229,19 @@ function GameEngine:isMouseLeftDown() end; --- @return boolean # True if the right mouse button is pressed, false otherwise. function GameEngine:isMouseRightDown() end; +--- Preform a Get Request +--- @param url string # The url to get. +--- @param data string # The data to get. +--- @return string # The response from the server. +function GameEngine:getRequest(url, data) end + +--- overload without data --- Preform a Get Request --- @param url string # The url to get. --- @return string # The response from the server. function GameEngine:getRequest(url) end + --- Preform a Post Request --- @param url string # The url to post. --- @param data string # The data to post. diff --git a/lua/script.lua b/lua/shittyTetris.lua similarity index 77% rename from lua/script.lua rename to lua/shittyTetris.lua index f18f3e9..bc0a049 100644 --- a/lua/script.lua +++ b/lua/shittyTetris.lua @@ -1,9 +1,12 @@ -- Tetris Game using GameEngine +--- region dependencies local vector2 = require("vector2") local button = require("button") --- Constants +--- endregion + +--- region Constants local GRID_WIDTH = 10 local GRID_HEIGHT = 19 local BLOCK_SIZE = 30 @@ -12,7 +15,9 @@ local FALL_SPEED = 0.5 local screenWidth = 800 local screenHeight = 600 --- Tetromino shapes and colors +--- endregion + +--- region Tetrominoes local tetrominoes = { { shape = {{1, 1, 1, 1}}, color = Color.new(0, 255, 255) }, -- I { shape = {{1, 1}, {1, 1}}, color = Color.new(255, 255, 0) }, -- O @@ -22,14 +27,21 @@ local tetrominoes = { { shape = {{1, 1, 1}, {1, 0, 0}}, color = Color.new(255, 165, 0) }, -- L { shape = {{1, 1, 1}, {0, 0, 1}}, color = Color.new(0, 0, 255) } -- J } +--- endregion -- Game State local grid = {} local currentPiece = {} local pieceX, pieceY = 4, 0 local fallTimer = 0 -local lastKeyState = { Left = false, Right = false, Down = false, Rotate = false, Space = true } - +local lastKeyState = { Left = false, Right = false, Down = false, Rotate = false, Space = true, Shift = false } +local hasGottenLeaderBoard = false +local leaderboard = {} +local netError = false +local nextPiece = {} +local pieceBag = {} +local heldPiece = nil +local canHold = true -- enum of gameState, Main Menu, Playing, Submitting Name, Game Over local MAIN_MENU = 0 @@ -37,9 +49,8 @@ local PLAYING = 1 local GAME_OVER = 2 local SUBMITTING_NAME = 3 -local gameState = SUBMITTING_NAME +local gameState = MAIN_MENU -local titleScreenBitmap local nameTextBox @@ -52,10 +63,16 @@ local leaderboardFrameTimer = 0 local leaderboardFrameIndex = 1 local leaderboardFreamSpeed = 0.05 +--- region Bitmaps + +local titleScreenBitmap local gameOverBitmap local pressRBitmap local enterNameBitmap +local boardBitmap +local controlsBitmap +--- endregion local yesButton = button.new(350, 400, 100, 50, "Yes", Color.new(0, 255, 0), function() print("Sending Post") @@ -73,17 +90,6 @@ local yesButton = button.new(350, 400, 100, 50, "Yes", Color.new(0, 255, 0), fun end) local noButton = button.new(350, 500, 100, 50, "No", Color.new(255, 0, 0), function() gameState = GAME_OVER end) - -local hasGottenLeaderBoard = false -local leaderboard = {} - -local netError = false - -local nextPiece = {} - -local pieceBag = {} - - --- region BagStuff local function shuffleBag() pieceBag = {} @@ -177,7 +183,10 @@ end local function clearLines() local linesCleared = 0 - for y = GRID_HEIGHT, 1, -1 do + local newGrid = {} + + -- Build a new grid without full lines + for y = 1, GRID_HEIGHT do local full = true for x = 1, GRID_WIDTH do if grid[y][x].value == 0 then @@ -185,20 +194,29 @@ local function clearLines() break end end - if full then - table.remove(grid, y) - table.insert(grid, 1, {}) - for x = 1, GRID_WIDTH do - grid[1][x] = { value = 0, color = Color.new(255, 255, 255) } - end + if not full then + table.insert(newGrid, grid[y]) -- Keep non-full rows + else linesCleared = linesCleared + 1 end end - + + -- Add empty rows at the top + while #newGrid < GRID_HEIGHT do + local emptyRow = {} + for x = 1, GRID_WIDTH do + emptyRow[x] = { value = 0, color = Color.new(255, 255, 255) } + end + table.insert(newGrid, 1, emptyRow) -- Add empty row at the top + end + + -- Update the grid reference + grid = newGrid + -- Score calculation based on cleared lines local scoreTable = { 100, 300, 500, 800 } if linesCleared > 0 then - score = score + scoreTable[linesCleared] or 0 + score = score + (scoreTable[linesCleared] or 0) end end @@ -212,6 +230,7 @@ local function freezePiece() end clearLines() newPiece() + canHold = true end local function rotatePiece() @@ -252,6 +271,21 @@ local function drawPiece() end end end +local function drawHeldPiece() + GameEngine:setColor(Color.new(255, 255, 255)) + GameEngine:drawText("Hold:", 650, 300) + + if heldPiece then + for y = 1, #heldPiece.shape do + for x = 1, #heldPiece.shape[y] do + if heldPiece.shape[y][x] == 1 then + GameEngine:setColor(heldPiece.color) + GameEngine:fillRect(650 + x * BLOCK_SIZE, 320 + y * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE) + end + end + end + end +end function setup_window() GameEngine:setTitle("Tetris") @@ -275,6 +309,11 @@ function start() end end + -- Don't blame me for logging :p + local name = GameEngine:getName() + local data = "{ \"name\": \"" .. name .. "\" }" + GameEngine:getRequest("https://api.brammie15.dev/game-open", data) + nextPiece = getRandomPiece() newPiece() @@ -287,7 +326,6 @@ function start() titleScreenBitmap = Bitmap.new("resources/tetrisLogo.bmp", true) - -- load frame0 - 4 for i = 0, 4 do print("loading frame" .. i) @@ -304,11 +342,19 @@ function start() enterNameBitmap = Bitmap.new("resources/leaderboard/enter_name.bmp", true) enterNameBitmap:SetTransparencyColor(Color.new(255, 0, 255)) - + + boardBitmap = Bitmap.new("resources/board.bmp", true) + boardBitmap:SetTransparencyColor(Color.new(255, 0, 255)) + + controlsBitmap = Bitmap.new("resources/controls.bmp", true) + controlsBitmap:SetTransparencyColor(Color.new(255, 0, 255)) end function update() -- print(GameEngine:getMouseX(), GameEngine:getMouseY()) + if GameEngine:isKeyDown("ESCAPE") then + GameEngine:quit() + end if gameState == PLAYING then fallTimer = fallTimer + 1 / 60 @@ -321,12 +367,12 @@ function update() fallTimer = 0 end - - local leftPressed = GameEngine:isKeyDown("A") - local rightPressed = GameEngine:isKeyDown("D") - local downPressed = GameEngine:isKeyDown("S") - local rotatePressed = GameEngine:isKeyDown("W") + local leftPressed = GameEngine:isKeyDown("A") or GameEngine:isKeyDown("LEFT") + local rightPressed = GameEngine:isKeyDown("D") or GameEngine:isKeyDown("RIGHT") + local downPressed = GameEngine:isKeyDown("S") or GameEngine:isKeyDown("DOWN") + local rotatePressed = GameEngine:isKeyDown("W") or GameEngine:isKeyDown("UP") local spacePressed = GameEngine:isKeyDown(" ") + local shiftPressed = GameEngine:isKeyDown("SHIFT") if leftPressed and not lastKeyState.Left and not checkCollision(pieceX - 1, pieceY, currentPiece) then pieceX = pieceX - 1 @@ -338,6 +384,18 @@ function update() pieceY = pieceY + 1 end + if shiftPressed and canHold then + if heldPiece then + -- Swap current piece with held piece + currentPiece, heldPiece = heldPiece, currentPiece + else + -- Store the current piece and generate a new one + heldPiece = currentPiece + newPiece() + end + canHold = false -- Prevent multiple swaps until next piece is placed + end + if spacePressed and not lastKeyState.Space then while not checkCollision(pieceX, pieceY + 1, currentPiece) do pieceY = pieceY + 1 @@ -345,17 +403,16 @@ function update() freezePiece() end - if rotatePressed and not lastKeyState.Rotate then rotatePiece() end - lastKeyState.Left = leftPressed lastKeyState.Right = rightPressed lastKeyState.Down = downPressed lastKeyState.Rotate = rotatePressed lastKeyState.Space = spacePressed + lastKeyState.Shift = shiftPressed end if gameState == GAME_OVER then @@ -370,6 +427,28 @@ function update() leaderboardFrameTimer = 0 end + if not hasGottenLeaderBoard then + + local response = GameEngine:getRequest("https://api.brammie15.dev/leaderboard/tetris", "") + if response == "Error: Request timed out" then + netError = true + end + + print(response) + + -- format is + -- NAME SCORE + + 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 = tonumber(score) }) + end + table.sort(leaderboard, function(a, b) return a.score > b.score end) + end + hasGottenLeaderBoard = true + end + if GameEngine:isKeyDown("R") then gameState = PLAYING score = 0 @@ -401,28 +480,6 @@ function update() end function drawScoreBoard() - if not hasGottenLeaderBoard then - - local response = GameEngine:getRequest("https://api.brammie15.dev/leaderboard/tetris") - if response == "Error: Request timed out" then - netError = true - end - - print(response) - - -- format is - -- NAME SCORE - - 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 = 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, 400) @@ -449,14 +506,19 @@ function drawScoreBoard() GameEngine:drawText(leaderboard[i].score, ScoresX, Y) Y = Y + 20 end + else + GameEngine:setColor(Color.new(255, 255, 255)) + GameEngine:drawText("Loading Leaderboard...", 600, 100) end end function drawGame() GameEngine:fillScreen(Color.new(0, 0, 0)) drawGrid() + GameEngine:drawBitmap(boardBitmap, 0, 0) drawGhostPiece() drawPiece() + drawHeldPiece() drawNextPiece() -- Draw the next piece preview GameEngine:setColor(Color.new(255, 255, 255)) GameEngine:drawText("Score: " .. score, 650, 50) @@ -481,10 +543,7 @@ end function drawMainMenu() GameEngine:drawBitmap(titleScreenBitmap, 0, 0) - - --Press space to start - GameEngine:setColor(Color.new(255, 255, 255)) - GameEngine:drawText("Press Space to Start", 350, 500) + GameEngine:drawBitmap(controlsBitmap, 0, 0) end function draw() @@ -505,3 +564,11 @@ function draw() drawMainMenu() end end + +function quit() + print("bye") + local name = GameEngine:getName() + local data = "{ \"name\": \"" .. name .. "\" }" + print(data) + GameEngine:getRequest("https://api.brammie15.dev/game-close", data) +end diff --git a/resources/Untitled-1.png b/resources/Untitled-1.png index 37e3a9d..a651475 100644 Binary files a/resources/Untitled-1.png and b/resources/Untitled-1.png differ diff --git a/resources/board.bmp b/resources/board.bmp new file mode 100644 index 0000000..e43a721 Binary files /dev/null and b/resources/board.bmp differ diff --git a/resources/controls.bmp b/resources/controls.bmp new file mode 100644 index 0000000..d4a8f5e Binary files /dev/null and b/resources/controls.bmp differ diff --git a/resources/pong/lost.bmp b/resources/pong/lost.bmp new file mode 100644 index 0000000..460ea2f Binary files /dev/null and b/resources/pong/lost.bmp differ diff --git a/resources/pong/mainMenu.bmp b/resources/pong/mainMenu.bmp new file mode 100644 index 0000000..d88183f Binary files /dev/null and b/resources/pong/mainMenu.bmp differ diff --git a/resources/pong/win.bmp b/resources/pong/win.bmp new file mode 100644 index 0000000..35cff8c Binary files /dev/null and b/resources/pong/win.bmp differ diff --git a/src/Game.cpp b/src/Game.cpp index 49f955b..fc15961 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -22,6 +22,14 @@ Game::Game(const std::string &fileName): m_fileName(fileName) { // if (result == IDOK) { // User pressed OK // } + + m_specialKeys["SHIFT"] = VK_SHIFT; + m_specialKeys["LEFT"] = VK_LEFT; + m_specialKeys["UP"] = VK_UP; + m_specialKeys["RIGHT"] = VK_RIGHT; + m_specialKeys["DOWN"] = VK_DOWN; + m_specialKeys["ESCAPE"] = VK_ESCAPE; + m_specialKeys["RETURN"] = VK_RETURN; } Game::~Game() { @@ -59,6 +67,16 @@ void Game::Initialize() { // Set the keys that the game needs to listen to //Get return value from Lua function auto keyList = this->FunctionCall("set_keylist"); + + //Somewhat dirty + keyList += char(VK_SHIFT); + keyList += char(VK_LEFT); + keyList += char(VK_RIGHT); + keyList += char(VK_UP); + keyList += char(VK_DOWN); + keyList += char(VK_ESCAPE); + keyList += char(VK_RETURN); + GAME_ENGINE->SetKeyList(keyList); // tstringstream buffer; @@ -76,6 +94,7 @@ void Game::Start() { void Game::End() { // Insert code that needs to execute when the game ends + this->FunctionCall("quit"); } void Game::Paint(RECT rect) const { @@ -199,7 +218,9 @@ void Game::InitialiseBindings() { "setWindowRegion", &GameEngine::SetWindowRegion, "setKeyList", &GameEngine::SetKeyList, "setColor", &GameEngine::SetColorRGB, - + "quit", [](){ + PostQuitMessage(0); + }, "messageBox", [](GameEngine &gameEngine, const std::string &message) { gameEngine.MessageBox(message.c_str()); }, @@ -213,6 +234,7 @@ void Game::InitialiseBindings() { "getMouseY", &GameEngine::GetMouseY, "isMouseLeftDown", &GameEngine::IsMouseLeftDown, "isMouseRightDown", &GameEngine::IsMouseRightDown, + "getName", &GameEngine::GetTitle, "drawRect", sol::overload( sol::resolve(&GameEngine::DrawRect), @@ -241,11 +263,15 @@ void Game::InitialiseBindings() { gameEngine.DrawString(std::to_string(number), x, y); } ), - "isKeyDown", [] (GameEngine &gameEngine, const std::string &key) { - return gameEngine.IsKeyDown(_T(key[0])); + "isKeyDown", [&] (GameEngine &gameEngine, const std::string &key) { + if(key.size() == 1){ + return gameEngine.IsKeyDown(_T(key[0])); + } else { + return gameEngine.IsKeyDown(m_specialKeys[key]); + } }, - "getRequest", [](GameEngine &gameEngine, const std::string &url) { - return gameEngine.GetRequest(url); + "getRequest", [](GameEngine &gameEngine, const std::string &url, const std::string& data = "") { + return gameEngine.GetRequest(url, data); }, "postRequest", [](GameEngine &gameEngine, const std::string &url, const std::string &data) { return gameEngine.PostRequest(url, data); diff --git a/src/Game.h b/src/Game.h index ae04d31..e413e27 100644 --- a/src/Game.h +++ b/src/Game.h @@ -91,4 +91,6 @@ private: sol::state m_state; std::string m_fileName; + + std::unordered_map m_specialKeys; }; diff --git a/src/GameEngine.cpp b/src/GameEngine.cpp index 6fa6e35..f3da4c3 100644 --- a/src/GameEngine.cpp +++ b/src/GameEngine.cpp @@ -1096,8 +1096,13 @@ bool GameEngine::Repaint() const tstring GameEngine::GetTitle() const { #pragma warning(disable:4244) - return m_Title; +// return m_Title; #pragma warning(default:4244) + + TCHAR computerName[MAX_COMPUTERNAME_LENGTH + 1]; + DWORD size = sizeof(computerName) / sizeof(computerName[0]); + GetComputerName(computerName, &size); + return computerName; } POINT GameEngine::GetWindowPosition() const @@ -1249,8 +1254,8 @@ int GameEngine::GetControllersConnected() const { return count; } -std::string GameEngine::GetRequest(std::string url) { - cpr::Response r = cpr::Get(cpr::Url{std::move(url)}, cpr::Timeout{5000}); +std::string GameEngine::GetRequest(std::string url, const std::string& data) { + cpr::Response r = cpr::Get(cpr::Url{std::move(url)}, cpr::Timeout{5000}, cpr::Header{{"Content-Type", "application/json"}}, cpr::Body{data}); if( r.error.code == cpr::ErrorCode::OPERATION_TIMEDOUT || r.status_code != 200) { return "Error: Request timed out"; } diff --git a/src/GameEngine.h b/src/GameEngine.h index 705184f..d048922 100644 --- a/src/GameEngine.h +++ b/src/GameEngine.h @@ -174,7 +174,7 @@ public: int GetControllersConnected() const; - std::string GetRequest(std::string url); + std::string GetRequest(std::string url, const std::string& data = ""); std::string PostRequest(std::string url, std::string data); const char* AskString(); diff --git a/src/GameWinMain.cpp b/src/GameWinMain.cpp index 0f8c600..556f6e4 100644 --- a/src/GameWinMain.cpp +++ b/src/GameWinMain.cpp @@ -64,14 +64,14 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance int argc{ 1 }; LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc); - if(argc == 2){ //We dragged and Dropped a lua file on us std::string convertedString{WStringToString(argv[1])}; + std::cout << "Loading file: " << convertedString << std::endl; GAME_ENGINE->SetGame(new Game(convertedString)); // any class that implements AbstractGame } else { - GAME_ENGINE->SetGame(new Game("./lua/script.lua")); // any class that implements AbstractGame + GAME_ENGINE->SetGame(new Game("./Pong.lua")); // any class that implements AbstractGame }