Exam ig
This commit is contained in:
@@ -79,6 +79,9 @@ add_custom_command(TARGET CopyLuaScripts POST_BUILD
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/lua
|
${CMAKE_CURRENT_SOURCE_DIR}/lua
|
||||||
$<TARGET_FILE_DIR:${PROJECT_NAME}>/)
|
$<TARGET_FILE_DIR:${PROJECT_NAME}>/)
|
||||||
|
|
||||||
|
# add dependencies
|
||||||
|
add_dependencies(${PROJECT_NAME} CopyLuaScripts)
|
||||||
|
|
||||||
add_custom_target(CopyResources ALL
|
add_custom_target(CopyResources ALL
|
||||||
COMMENT "Copying resources to output directory"
|
COMMENT "Copying resources to output directory"
|
||||||
)
|
)
|
||||||
@@ -88,4 +91,6 @@ add_custom_command(TARGET CopyResources POST_BUILD
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/resources
|
${CMAKE_CURRENT_SOURCE_DIR}/resources
|
||||||
$<TARGET_FILE_DIR:${PROJECT_NAME}>/resources)
|
$<TARGET_FILE_DIR:${PROJECT_NAME}>/resources)
|
||||||
|
|
||||||
|
add_dependencies(${PROJECT_NAME} CopyResources)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -195,6 +195,8 @@ end
|
|||||||
function updateLost()
|
function updateLost()
|
||||||
if GameEngine:isKeyDown("R") then
|
if GameEngine:isKeyDown("R") then
|
||||||
currentGameState = PLAYING
|
currentGameState = PLAYING
|
||||||
|
score = 0
|
||||||
|
ai_score = 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -204,12 +206,14 @@ end
|
|||||||
function drawWin()
|
function drawWin()
|
||||||
GameEngine:fillScreen(Color.new(0, 0,0))
|
GameEngine:fillScreen(Color.new(0, 0,0))
|
||||||
GameEngine:setColor(Color.new(255,255,255))
|
GameEngine:setColor(Color.new(255,255,255))
|
||||||
GameEngine:drawBitmap(lostBitmap, 0, 0)
|
GameEngine:drawBitmap(winBitmap, 0, 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
function updateWin()
|
function updateWin()
|
||||||
if GameEngine:isKeyDown("R") then
|
if GameEngine:isKeyDown("R") then
|
||||||
currentGameState = PLAYING
|
currentGameState = PLAYING
|
||||||
|
score = 0
|
||||||
|
ai_score = 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -226,7 +230,7 @@ end
|
|||||||
|
|
||||||
--- the set_keylist function
|
--- the set_keylist function
|
||||||
--- @return string
|
--- @return string
|
||||||
function set_keylist()
|
function set_keylist()
|
||||||
return "WASD "
|
return "WASD "
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -299,6 +303,5 @@ function quit()
|
|||||||
print("bye")
|
print("bye")
|
||||||
local name = GameEngine:getName()
|
local name = GameEngine:getName()
|
||||||
local data = "{ \"name\": \"" .. name .. "\" }"
|
local data = "{ \"name\": \"" .. name .. "\" }"
|
||||||
print(data)
|
|
||||||
GameEngine:getRequest("https://api.brammie15.dev/game-close", data)
|
GameEngine:getRequest("https://api.brammie15.dev/game-close", data)
|
||||||
end
|
end
|
||||||
@@ -27,6 +27,24 @@ local tetrominoes = {
|
|||||||
{ shape = {{1, 1, 1}, {1, 0, 0}}, color = Color.new(255, 165, 0) }, -- L
|
{ 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
|
{ shape = {{1, 1, 1}, {0, 0, 1}}, color = Color.new(0, 0, 255) } -- J
|
||||||
}
|
}
|
||||||
|
local wallKicks = {
|
||||||
|
-- These values come from the official Super Rotation System (SRS)
|
||||||
|
-- https://harddrop.com/wiki/SRS
|
||||||
|
|
||||||
|
I = {
|
||||||
|
[0] = { {0, 0}, {-2, 0}, {1, 0}, {-2, -1}, {1, 2} },
|
||||||
|
[1] = { {0, 0}, {2, 0}, {-1, 0}, {2, 1}, {-1, -2} },
|
||||||
|
[2] = { {0, 0}, {-1, 0}, {2, 0}, {-1, 2}, {2, -1} },
|
||||||
|
[3] = { {0, 0}, {1, 0}, {-2, 0}, {1, -2}, {-2, 1} }
|
||||||
|
},
|
||||||
|
Default = {
|
||||||
|
[0] = { {0, 0}, {-1, 0}, {-1, 1}, {0, -2}, {-1, -2} },
|
||||||
|
[1] = { {0, 0}, {1, 0}, {1, -1}, {0, 2}, {1, 2} },
|
||||||
|
[2] = { {0, 0}, {1, 0}, {1, 1}, {0, -2}, {1, -2} },
|
||||||
|
[3] = { {0, 0}, {-1, 0}, {-1, -1}, {0, 2}, {-1, 2} }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
--- endregion
|
--- endregion
|
||||||
|
|
||||||
-- Game State
|
-- Game State
|
||||||
@@ -51,6 +69,8 @@ local SUBMITTING_NAME = 3
|
|||||||
|
|
||||||
local gameState = MAIN_MENU
|
local gameState = MAIN_MENU
|
||||||
|
|
||||||
|
local combo = 0
|
||||||
|
local backToBackTetris = false
|
||||||
|
|
||||||
|
|
||||||
local nameTextBox
|
local nameTextBox
|
||||||
@@ -63,6 +83,10 @@ local leaderboardFrameTimer = 0
|
|||||||
local leaderboardFrameIndex = 1
|
local leaderboardFrameIndex = 1
|
||||||
local leaderboardFreamSpeed = 0.05
|
local leaderboardFreamSpeed = 0.05
|
||||||
|
|
||||||
|
local FALL_SPEED = 0.5
|
||||||
|
local linesClearedTotal = 0
|
||||||
|
local level = 1
|
||||||
|
|
||||||
--- region Bitmaps
|
--- region Bitmaps
|
||||||
|
|
||||||
local titleScreenBitmap
|
local titleScreenBitmap
|
||||||
@@ -72,6 +96,8 @@ local pressRBitmap
|
|||||||
local enterNameBitmap
|
local enterNameBitmap
|
||||||
local boardBitmap
|
local boardBitmap
|
||||||
local controlsBitmap
|
local controlsBitmap
|
||||||
|
|
||||||
|
|
||||||
--- endregion
|
--- endregion
|
||||||
|
|
||||||
local yesButton = button.new(350, 400, 100, 50, "Yes", Color.new(0, 255, 0), function()
|
local yesButton = button.new(350, 400, 100, 50, "Yes", Color.new(0, 255, 0), function()
|
||||||
@@ -103,6 +129,16 @@ local function shuffleBag()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function getPieceType()
|
||||||
|
if #currentPiece.shape == 4 then
|
||||||
|
return "I"
|
||||||
|
elseif #currentPiece.shape == 2 then
|
||||||
|
return "O"
|
||||||
|
else
|
||||||
|
return "Default"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function getNextPiece()
|
local function getNextPiece()
|
||||||
if #pieceBag == 0 then
|
if #pieceBag == 0 then
|
||||||
shuffleBag()
|
shuffleBag()
|
||||||
@@ -185,7 +221,6 @@ local function clearLines()
|
|||||||
local linesCleared = 0
|
local linesCleared = 0
|
||||||
local newGrid = {}
|
local newGrid = {}
|
||||||
|
|
||||||
-- Build a new grid without full lines
|
|
||||||
for y = 1, GRID_HEIGHT do
|
for y = 1, GRID_HEIGHT do
|
||||||
local full = true
|
local full = true
|
||||||
for x = 1, GRID_WIDTH do
|
for x = 1, GRID_WIDTH do
|
||||||
@@ -195,36 +230,40 @@ local function clearLines()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not full then
|
if not full then
|
||||||
table.insert(newGrid, grid[y]) -- Keep non-full rows
|
table.insert(newGrid, grid[y])
|
||||||
else
|
else
|
||||||
linesCleared = linesCleared + 1
|
linesCleared = linesCleared + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Add empty rows at the top
|
|
||||||
while #newGrid < GRID_HEIGHT do
|
while #newGrid < GRID_HEIGHT do
|
||||||
local emptyRow = {}
|
local emptyRow = {}
|
||||||
for x = 1, GRID_WIDTH do
|
for x = 1, GRID_WIDTH do
|
||||||
emptyRow[x] = { value = 0, color = Color.new(255, 255, 255) }
|
emptyRow[x] = { value = 0, color = Color.new(255, 255, 255) }
|
||||||
end
|
end
|
||||||
table.insert(newGrid, 1, emptyRow) -- Add empty row at the top
|
table.insert(newGrid, 1, emptyRow)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Update the grid reference
|
|
||||||
grid = newGrid
|
grid = newGrid
|
||||||
|
|
||||||
-- Score calculation based on cleared lines
|
-- Update total lines cleared and level
|
||||||
local scoreTable = { 100, 300, 500, 800 }
|
|
||||||
if linesCleared > 0 then
|
if linesCleared > 0 then
|
||||||
score = score + (scoreTable[linesCleared] or 0)
|
linesClearedTotal = linesClearedTotal + linesCleared
|
||||||
|
level = math.floor(linesClearedTotal / 10) + 1 -- Level up every 10 lines
|
||||||
|
FALL_SPEED = math.max(0.1, 0.5 - (level * 0.05)) -- Speed up, but never below 0.1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function freezePiece()
|
local function freezePiece()
|
||||||
for y = 1, #currentPiece.shape do
|
for y = 1, #currentPiece.shape do
|
||||||
for x = 1, #currentPiece.shape[y] do
|
for x = 1, #currentPiece.shape[y] do
|
||||||
if currentPiece.shape[y][x] == 1 then
|
if currentPiece.shape[y][x] == 1 then
|
||||||
grid[pieceY + y][pieceX + x] = { value = 1, color = currentPiece.color }
|
local gridY = pieceY + y
|
||||||
|
local gridX = pieceX + x
|
||||||
|
|
||||||
|
-- Ensure it's within bounds before assigning
|
||||||
|
if gridY >= 1 and gridY <= GRID_HEIGHT and gridX >= 1 and gridX <= GRID_WIDTH then
|
||||||
|
grid[gridY][gridX] = { value = 1, color = currentPiece.color }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -241,8 +280,24 @@ local function rotatePiece()
|
|||||||
newShape[x][#currentPiece.shape - y + 1] = currentPiece.shape[y][x]
|
newShape[x][#currentPiece.shape - y + 1] = currentPiece.shape[y][x]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not checkCollision(pieceX, pieceY, { shape = newShape }) then
|
|
||||||
|
local pieceType = getPieceType()
|
||||||
|
if pieceType == "O" then
|
||||||
currentPiece.shape = newShape
|
currentPiece.shape = newShape
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local rotationIndex = (currentPiece.rotation or 0) % 4
|
||||||
|
local kickTable = wallKicks[pieceType][rotationIndex]
|
||||||
|
|
||||||
|
for _, offset in ipairs(kickTable) do
|
||||||
|
local newX, newY = pieceX + offset[1], pieceY + offset[2]
|
||||||
|
if not checkCollision(newX, newY, { shape = newShape }) then
|
||||||
|
currentPiece.shape = newShape
|
||||||
|
pieceX, pieceY = newX, newY
|
||||||
|
currentPiece.rotation = (rotationIndex + 1) % 4
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -328,7 +383,6 @@ function start()
|
|||||||
|
|
||||||
-- load frame0 - 4
|
-- load frame0 - 4
|
||||||
for i = 0, 4 do
|
for i = 0, 4 do
|
||||||
print("loading frame" .. i)
|
|
||||||
local bmp = Bitmap.new("resources/leaderboard/frame" .. i .. ".bmp", true)
|
local bmp = Bitmap.new("resources/leaderboard/frame" .. i .. ".bmp", true)
|
||||||
bmp:SetTransparencyColor(Color.new(255, 0, 255))
|
bmp:SetTransparencyColor(Color.new(255, 0, 255))
|
||||||
table.insert(leaderboardFrames, bmp)
|
table.insert(leaderboardFrames, bmp)
|
||||||
@@ -384,22 +438,23 @@ function update()
|
|||||||
pieceY = pieceY + 1
|
pieceY = pieceY + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
if shiftPressed and canHold then
|
if shiftPressed and not lastKeyState.Shift and canHold then
|
||||||
if heldPiece then
|
if heldPiece then
|
||||||
-- Swap current piece with held piece
|
-- Swap current piece with held piece
|
||||||
currentPiece, heldPiece = heldPiece, currentPiece
|
currentPiece, heldPiece = heldPiece, currentPiece
|
||||||
else
|
else
|
||||||
-- Store the current piece and generate a new one
|
|
||||||
heldPiece = currentPiece
|
heldPiece = currentPiece
|
||||||
newPiece()
|
currentPiece = getNextPiece()
|
||||||
end
|
end
|
||||||
canHold = false -- Prevent multiple swaps until next piece is placed
|
-- Reset position for the new piece
|
||||||
|
pieceX, pieceY = 4, 0
|
||||||
|
canHold = false -- Prevent repeated swaps until the piece is placed
|
||||||
end
|
end
|
||||||
|
|
||||||
if spacePressed and not lastKeyState.Space then
|
if spacePressed and not lastKeyState.Space then
|
||||||
while not checkCollision(pieceX, pieceY + 1, currentPiece) do
|
local dropDistance = getGhostPieceY() - pieceY
|
||||||
pieceY = pieceY + 1
|
score = score + (dropDistance * 2) -- 2 points per row
|
||||||
end
|
pieceY = getGhostPieceY()
|
||||||
freezePiece()
|
freezePiece()
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -452,6 +507,7 @@ function update()
|
|||||||
if GameEngine:isKeyDown("R") then
|
if GameEngine:isKeyDown("R") then
|
||||||
gameState = PLAYING
|
gameState = PLAYING
|
||||||
score = 0
|
score = 0
|
||||||
|
level = 1
|
||||||
netError = false
|
netError = false
|
||||||
hasGottenLeaderBoard = false
|
hasGottenLeaderBoard = false
|
||||||
leaderboard = {}
|
leaderboard = {}
|
||||||
@@ -522,6 +578,8 @@ function drawGame()
|
|||||||
drawNextPiece() -- Draw the next piece preview
|
drawNextPiece() -- Draw the next piece preview
|
||||||
GameEngine:setColor(Color.new(255, 255, 255))
|
GameEngine:setColor(Color.new(255, 255, 255))
|
||||||
GameEngine:drawText("Score: " .. score, 650, 50)
|
GameEngine:drawText("Score: " .. score, 650, 50)
|
||||||
|
|
||||||
|
GameEngine:drawText("Level: " .. level, 650, 75)
|
||||||
end
|
end
|
||||||
|
|
||||||
function drawGameOver()
|
function drawGameOver()
|
||||||
@@ -569,6 +627,5 @@ function quit()
|
|||||||
print("bye")
|
print("bye")
|
||||||
local name = GameEngine:getName()
|
local name = GameEngine:getName()
|
||||||
local data = "{ \"name\": \"" .. name .. "\" }"
|
local data = "{ \"name\": \"" .. name .. "\" }"
|
||||||
print(data)
|
|
||||||
GameEngine:getRequest("https://api.brammie15.dev/game-close", data)
|
GameEngine:getRequest("https://api.brammie15.dev/game-close", data)
|
||||||
end
|
end
|
||||||
@@ -71,7 +71,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance
|
|||||||
GAME_ENGINE->SetGame(new Game(convertedString)); // any class that implements AbstractGame
|
GAME_ENGINE->SetGame(new Game(convertedString)); // any class that implements AbstractGame
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
GAME_ENGINE->SetGame(new Game("./Pong.lua")); // any class that implements AbstractGame
|
GAME_ENGINE->SetGame(new Game("./Game_ShittyTetris.lua")); // any class that implements AbstractGame
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user