|
10 | 10 | function level:loadLevel(data)
|
11 | 11 | print(data)
|
12 | 12 | if data.Start then self.map.Start = data.Start end
|
| 13 | + if data.End then self.map.End = data.End end |
13 | 14 | for _,platform in pairs(data.Platforms) do
|
14 | 15 | local body = love.physics.newBody(world, platform.X + (platform.W / 2), platform.Y + (platform.H / 2), "static")
|
15 | 16 | local shape = love.physics.newRectangleShape(platform.W, platform.H)
|
@@ -75,6 +76,16 @@ function level:loadLevel(data)
|
75 | 76 | player.body:setX(self.map.Start.X)
|
76 | 77 | player.body:setY(self.map.Start.Y)
|
77 | 78 | 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 |
78 | 89 | end
|
79 | 90 |
|
80 | 91 | function level:Unload()
|
|
84 | 95 |
|
85 | 96 | function level:draw()
|
86 | 97 | 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 |
98 | 113 | end
|
99 | 114 | 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 |
100 | 119 | end
|
101 | 120 | end
|
102 | 121 |
|
|
0 commit comments