Skip to content

Commit

Permalink
Added winscreen (this was kinda painful)
Browse files Browse the repository at this point in the history
  • Loading branch information
29cmb committed Jul 29, 2024
1 parent 8eda3ff commit 39aac80
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 16 deletions.
Binary file added images/WinScreen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local editor = require("editor")
local utils = require("modules.utils")
local fonts = require("modules.font")
local pause = require('modules.pause')
local win = require('modules.win')

local inMenu = true
local levelPage = 1
Expand Down Expand Up @@ -124,6 +125,7 @@ function love.load()
if sprite.IsLoaded == false then sprite:Init() end
if fonts.IsLoaded == false then fonts:Load() end
if pause.IsLoaded == false then pause:Load() end
if win.IsLoaded == false then win:Load() end
if editor.InEditor == true then editor:Load() return end

world:setCallbacks(beginContact, endContact)
Expand All @@ -146,6 +148,7 @@ function love.draw()
level:draw()
player:draw()
pause:Draw()
win:Draw()
end
end

Expand All @@ -165,14 +168,16 @@ end
function love.keypressed(key)
if key == "j" and editor.InEditor == false then
player:WaterToggle()
elseif key == "escape" and (inMenu == false or editor.InEditor == true) then
elseif key == "escape" and (inMenu == false or editor.InEditor == true) and win.WinVisible == false then
pause.Paused = not pause.Paused
end
end

function love.mousepressed(x, y, button)
if win.WinVisible == true then win:MouseClick(x, y) return end
if pause.Paused == true then pause:MouseClick(x, y) return end
if editor.InEditor == true then editor:MousePressed(x, y, button) return end

if inMenu == true then
for _,btn in pairs(menuButtons) do
if utils:CheckCollision(x, y, 1, 1, btn.Transform[1], btn.Transform[2], btn.Transform[3], btn.Transform[4]) then
Expand All @@ -192,6 +197,8 @@ function beginContact(a, b)
player:YieldRespawn()
elseif b:getUserData() == "Sponge" and player.IsWater == true then
player:YieldRespawn()
elseif b:getUserData() == "Flag" then
win.WinVisible = true
end
end
end
Expand Down
41 changes: 30 additions & 11 deletions modules/level.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ end
function level:loadLevel(data)
print(data)
if data.Start then self.map.Start = data.Start end
if data.End then self.map.End = data.End end
for _,platform in pairs(data.Platforms) do
local body = love.physics.newBody(world, platform.X + (platform.W / 2), platform.Y + (platform.H / 2), "static")
local shape = love.physics.newRectangleShape(platform.W, platform.H)
Expand Down Expand Up @@ -75,6 +76,16 @@ function level:loadLevel(data)
player.body:setX(self.map.Start.X)
player.body:setY(self.map.Start.Y)
end

if self.map.End then
local body = love.physics.newBody(world, self.map.End.X + (60 / 2), self.map.End.Y + (60 / 2), "static")
local shape = love.physics.newRectangleShape(60, 60)
local fixutre = love.physics.newFixture(body, shape)
fixutre:setUserData("Flag")
fixutre:setSensor(true)

self.map.End.Fixture = fixutre
end
end

function level:Unload()
Expand All @@ -84,19 +95,27 @@ end

function level:draw()
if self.map ~= {} then
for _,platform in pairs(self.map) do
if platform.type == "Platform" then
love.graphics.setColor(platform.color.R, platform.color.B, platform.color.G)
love.graphics.rectangle("fill", platform.transform[1] - player.CameraData.CameraX, platform.transform[2] - player.CameraData.CameraY, platform.transform[3], platform.transform[4])
love.graphics.setColor(1, 1, 1)
elseif platform.type == "Spike" then
love.graphics.draw(sprite.Spike, platform.transform[1] - player.CameraData.CameraX, platform.transform[2] - player.CameraData.CameraY)
elseif platform.type == "Sponge" then
love.graphics.draw(sprite.Sponge, platform.transform[1] - player.CameraData.CameraX, platform.transform[2] - player.CameraData.CameraY, 0, platform.transform[3] / 536, platform.transform[4] / 350)
elseif platform.type == "Gate" then
love.graphics.draw(sprite.Water, platform.transform[1] - player.CameraData.CameraX, platform.transform[2] - player.CameraData.CameraY, 0, platform.transform[3] / 643, platform.transform[4] / 360)
for _,platform in pairs(self.map) do
if type(platform) == "table" then
if platform.type then
if platform.type == "Platform" then
love.graphics.setColor(platform.color.R, platform.color.B, platform.color.G)
love.graphics.rectangle("fill", platform.transform[1] - player.CameraData.CameraX, platform.transform[2] - player.CameraData.CameraY, platform.transform[3], platform.transform[4])
love.graphics.setColor(1, 1, 1)
elseif platform.type == "Spike" then
love.graphics.draw(sprite.Spike, platform.transform[1] - player.CameraData.CameraX, platform.transform[2] - player.CameraData.CameraY)
elseif platform.type == "Sponge" then
love.graphics.draw(sprite.Sponge, platform.transform[1] - player.CameraData.CameraX, platform.transform[2] - player.CameraData.CameraY, 0, platform.transform[3] / 536, platform.transform[4] / 350)
elseif platform.type == "Gate" then
love.graphics.draw(sprite.Water, platform.transform[1] - player.CameraData.CameraX, platform.transform[2] - player.CameraData.CameraY, 0, platform.transform[3] / 643, platform.transform[4] / 360)
end
end
end
end

if self.map.End then
love.graphics.draw(sprite.EndFlag, self.map.End.X - player.CameraData.CameraX, self.map.End.Y - player.CameraData.CameraY)
end
end
end

Expand Down
5 changes: 2 additions & 3 deletions modules/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local player = {}
local sprite = require("modules.sprite")
local pause = require("modules.pause")
local level = require("modules.level")
local win = require("modules.win")
local movementDirections = {a = {-1,0}, d = {1,0}, space = {0,-1}}
local respawning = false
player.MovementData = {
Expand Down Expand Up @@ -59,10 +60,8 @@ function player:update(dt)
self.MovementData.OnGround = true
end



for key, data in pairs(movementDirections) do
if love.keyboard.isDown(key) and pause.Paused == false then
if love.keyboard.isDown(key) and (pause.Paused == false and win.WinVisible == false) then
local impulseX = 0
local impulseY = 0

Expand Down
3 changes: 2 additions & 1 deletion modules/sprite.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ local sprite = {
["SaveButton"] = "images/SaveButton.png",
["MainMenu"] = "images/MainMenu.png",
["PauseMenu"] = "images/PauseMenu.png",
["DeleteButton"] = "images/DeleteButton.png"
["DeleteButton"] = "images/DeleteButton.png",
["WinScreen"] = "images/WinScreen.png"
}
sprite.IsLoaded = false

Expand Down
48 changes: 48 additions & 0 deletions modules/win.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
local sprite = require("modules.sprite")
local utils = require("modules.utils")
local win = {}
win.WinVisible = false
win.IsLoaded = false

function win:Load()
main = require("main")
level = require("modules.level")
player = require("modules.player")
self.IsLoaded = true
end

local buttons = {
["Exit"] = {
["Transform"] = {200, 217, 397, 125},
["Callback"] = function()
main:Exit()
level:Unload()
win.WinVisible = false
end
},
["Restart"] = {
["Transform"] = {200, 355, 397, 125},
["Callback"] = function()
player.body:setX(level.map.Start.X or 0)
player.body:setY(level.map.Start.Y or 0)
win.WinVisible = false
end
}
}

function win:Draw()
if self.WinVisible == true then
love.graphics.draw(sprite.WinScreen)
end
end

function win:MouseClick(x, y)
for _,btn in pairs(buttons) do
if utils:CheckCollision(x, y, 1, 1, btn["Transform"][1], btn["Transform"][2], btn["Transform"][3], btn["Transform"][4]) then
btn.Callback()
end
end
end


return win

0 comments on commit 39aac80

Please sign in to comment.