Skip to content

Commit 39aac80

Browse files
committed
Added winscreen (this was kinda painful)
1 parent 8eda3ff commit 39aac80

File tree

6 files changed

+90
-16
lines changed

6 files changed

+90
-16
lines changed

images/WinScreen.png

15 KB
Loading

main.lua

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ local editor = require("editor")
77
local utils = require("modules.utils")
88
local fonts = require("modules.font")
99
local pause = require('modules.pause')
10+
local win = require('modules.win')
1011

1112
local inMenu = true
1213
local levelPage = 1
@@ -124,6 +125,7 @@ function love.load()
124125
if sprite.IsLoaded == false then sprite:Init() end
125126
if fonts.IsLoaded == false then fonts:Load() end
126127
if pause.IsLoaded == false then pause:Load() end
128+
if win.IsLoaded == false then win:Load() end
127129
if editor.InEditor == true then editor:Load() return end
128130

129131
world:setCallbacks(beginContact, endContact)
@@ -146,6 +148,7 @@ function love.draw()
146148
level:draw()
147149
player:draw()
148150
pause:Draw()
151+
win:Draw()
149152
end
150153
end
151154

@@ -165,14 +168,16 @@ end
165168
function love.keypressed(key)
166169
if key == "j" and editor.InEditor == false then
167170
player:WaterToggle()
168-
elseif key == "escape" and (inMenu == false or editor.InEditor == true) then
171+
elseif key == "escape" and (inMenu == false or editor.InEditor == true) and win.WinVisible == false then
169172
pause.Paused = not pause.Paused
170173
end
171174
end
172175

173176
function love.mousepressed(x, y, button)
177+
if win.WinVisible == true then win:MouseClick(x, y) return end
174178
if pause.Paused == true then pause:MouseClick(x, y) return end
175179
if editor.InEditor == true then editor:MousePressed(x, y, button) return end
180+
176181
if inMenu == true then
177182
for _,btn in pairs(menuButtons) do
178183
if utils:CheckCollision(x, y, 1, 1, btn.Transform[1], btn.Transform[2], btn.Transform[3], btn.Transform[4]) then
@@ -192,6 +197,8 @@ function beginContact(a, b)
192197
player:YieldRespawn()
193198
elseif b:getUserData() == "Sponge" and player.IsWater == true then
194199
player:YieldRespawn()
200+
elseif b:getUserData() == "Flag" then
201+
win.WinVisible = true
195202
end
196203
end
197204
end

modules/level.lua

+30-11
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ end
1010
function level:loadLevel(data)
1111
print(data)
1212
if data.Start then self.map.Start = data.Start end
13+
if data.End then self.map.End = data.End end
1314
for _,platform in pairs(data.Platforms) do
1415
local body = love.physics.newBody(world, platform.X + (platform.W / 2), platform.Y + (platform.H / 2), "static")
1516
local shape = love.physics.newRectangleShape(platform.W, platform.H)
@@ -75,6 +76,16 @@ function level:loadLevel(data)
7576
player.body:setX(self.map.Start.X)
7677
player.body:setY(self.map.Start.Y)
7778
end
79+
80+
if self.map.End then
81+
local body = love.physics.newBody(world, self.map.End.X + (60 / 2), self.map.End.Y + (60 / 2), "static")
82+
local shape = love.physics.newRectangleShape(60, 60)
83+
local fixutre = love.physics.newFixture(body, shape)
84+
fixutre:setUserData("Flag")
85+
fixutre:setSensor(true)
86+
87+
self.map.End.Fixture = fixutre
88+
end
7889
end
7990

8091
function level:Unload()
@@ -84,19 +95,27 @@ end
8495

8596
function level:draw()
8697
if self.map ~= {} then
87-
for _,platform in pairs(self.map) do
88-
if platform.type == "Platform" then
89-
love.graphics.setColor(platform.color.R, platform.color.B, platform.color.G)
90-
love.graphics.rectangle("fill", platform.transform[1] - player.CameraData.CameraX, platform.transform[2] - player.CameraData.CameraY, platform.transform[3], platform.transform[4])
91-
love.graphics.setColor(1, 1, 1)
92-
elseif platform.type == "Spike" then
93-
love.graphics.draw(sprite.Spike, platform.transform[1] - player.CameraData.CameraX, platform.transform[2] - player.CameraData.CameraY)
94-
elseif platform.type == "Sponge" then
95-
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)
96-
elseif platform.type == "Gate" then
97-
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)
98+
for _,platform in pairs(self.map) do
99+
if type(platform) == "table" then
100+
if platform.type then
101+
if platform.type == "Platform" then
102+
love.graphics.setColor(platform.color.R, platform.color.B, platform.color.G)
103+
love.graphics.rectangle("fill", platform.transform[1] - player.CameraData.CameraX, platform.transform[2] - player.CameraData.CameraY, platform.transform[3], platform.transform[4])
104+
love.graphics.setColor(1, 1, 1)
105+
elseif platform.type == "Spike" then
106+
love.graphics.draw(sprite.Spike, platform.transform[1] - player.CameraData.CameraX, platform.transform[2] - player.CameraData.CameraY)
107+
elseif platform.type == "Sponge" then
108+
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)
109+
elseif platform.type == "Gate" then
110+
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)
111+
end
112+
end
98113
end
99114
end
115+
116+
if self.map.End then
117+
love.graphics.draw(sprite.EndFlag, self.map.End.X - player.CameraData.CameraX, self.map.End.Y - player.CameraData.CameraY)
118+
end
100119
end
101120
end
102121

modules/player.lua

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local player = {}
33
local sprite = require("modules.sprite")
44
local pause = require("modules.pause")
55
local level = require("modules.level")
6+
local win = require("modules.win")
67
local movementDirections = {a = {-1,0}, d = {1,0}, space = {0,-1}}
78
local respawning = false
89
player.MovementData = {
@@ -59,10 +60,8 @@ function player:update(dt)
5960
self.MovementData.OnGround = true
6061
end
6162

62-
63-
6463
for key, data in pairs(movementDirections) do
65-
if love.keyboard.isDown(key) and pause.Paused == false then
64+
if love.keyboard.isDown(key) and (pause.Paused == false and win.WinVisible == false) then
6665
local impulseX = 0
6766
local impulseY = 0
6867

modules/sprite.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ local sprite = {
1414
["SaveButton"] = "images/SaveButton.png",
1515
["MainMenu"] = "images/MainMenu.png",
1616
["PauseMenu"] = "images/PauseMenu.png",
17-
["DeleteButton"] = "images/DeleteButton.png"
17+
["DeleteButton"] = "images/DeleteButton.png",
18+
["WinScreen"] = "images/WinScreen.png"
1819
}
1920
sprite.IsLoaded = false
2021

modules/win.lua

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
local sprite = require("modules.sprite")
2+
local utils = require("modules.utils")
3+
local win = {}
4+
win.WinVisible = false
5+
win.IsLoaded = false
6+
7+
function win:Load()
8+
main = require("main")
9+
level = require("modules.level")
10+
player = require("modules.player")
11+
self.IsLoaded = true
12+
end
13+
14+
local buttons = {
15+
["Exit"] = {
16+
["Transform"] = {200, 217, 397, 125},
17+
["Callback"] = function()
18+
main:Exit()
19+
level:Unload()
20+
win.WinVisible = false
21+
end
22+
},
23+
["Restart"] = {
24+
["Transform"] = {200, 355, 397, 125},
25+
["Callback"] = function()
26+
player.body:setX(level.map.Start.X or 0)
27+
player.body:setY(level.map.Start.Y or 0)
28+
win.WinVisible = false
29+
end
30+
}
31+
}
32+
33+
function win:Draw()
34+
if self.WinVisible == true then
35+
love.graphics.draw(sprite.WinScreen)
36+
end
37+
end
38+
39+
function win:MouseClick(x, y)
40+
for _,btn in pairs(buttons) do
41+
if utils:CheckCollision(x, y, 1, 1, btn["Transform"][1], btn["Transform"][2], btn["Transform"][3], btn["Transform"][4]) then
42+
btn.Callback()
43+
end
44+
end
45+
end
46+
47+
48+
return win

0 commit comments

Comments
 (0)