From 8a51c55cfd5c22ff035f320c9128d6ec49009bf2 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 15 May 2016 22:13:13 +0200 Subject: ZU WARUDO! --- world.lua | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 73 insertions(+), 11 deletions(-) (limited to 'world.lua') diff --git a/world.lua b/world.lua index e4301e4..963ae44 100644 --- a/world.lua +++ b/world.lua @@ -7,10 +7,10 @@ -- nils initialized in constructor World = { world = nil, - nauts = nil, - platforms = nil, - clouds = nil, - camera = nil -- not sure yet? menu will need scaling too + Nauts = nil, + Platforms = nil, + Clouds = nil, + camera = nil } -- Constructor of `World` ZA WARUDO! @@ -25,30 +25,92 @@ function World:new() o.world:setCallbacks(o.beginContact, o.endContact) -- Empty tables for objects local c = {} - o.clouds = c + o.Clouds = c local n = {} - o.nauts = n + o.Nauts = n local p = {} - o.platforms = {} + o.Platforms = {} + -- Create camera + o.camera = Camera:new() return o end -- Add new platform to the world function World:createPlatform(x, y, polygon, sprite) - table.insert(self.platforms, Ground:new(self.world, x, y, polygon, sprite)) + table.insert(self.Platforms, Ground:new(self.world, x, y, polygon, sprite)) end -- Add new naut to the world function World:createNaut(x, y, sprite) - table.insert(self.nauts, Player:new(self.world, x, y, sprite)) + table.insert(self.Nauts, Player:new(self.world, x, y, sprite)) end -- Add new cloud to the world +function World:createCloud(x, y, t) + table.insert(self.Clouds, Cloud:new(x, y, t)) +end + +-- Update ZU WARUDO +function World:update(dt) + -- Physical world + self.world:update(dt) + -- Camera + self.camera:moveFollow() + -- Nauts + for _,naut in pairs(self.Nauts) do + naut:update(dt) + end +end --- Update -- Keypressed +function World:keypressed(key) + for _,naut in pairs(self.Nauts) do + naut:keypressed(key) + end +end + -- Keyreleased +function World:keyreleased(key) + for _,naut in pairs(self.Nauts) do + naut:keyreleased(key) + end +end + -- Draw +function World:draw() + -- Hard-coded background (for now) + love.graphics.setColor(193, 100, 99, 255) + love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight()*0.25) + love.graphics.setColor(179, 82, 80, 255) + love.graphics.rectangle("fill", 0, love.graphics.getHeight()*0.8, love.graphics.getWidth(), love.graphics.getHeight()*0.2) + + -- Camera stuff + local offset_x, offset_y = self.camera:getOffsets() + local scale = self.camera.scale + + -- Draw ground + for _,platform in pairs(self.Platforms) do + platform:draw(offset_x, offset_y, scale, false) + end + + -- Draw player + for _,naut in pairs(self.Nauts) do + naut:draw(offset_x, offset_y, scale, false) + end +end -- beginContact --- endContact \ No newline at end of file +function World.beginContact(a, b, coll) + local x,y = coll:getNormal() + if y == -1 then + print(b:getUserData().name .. " is not in air") + b:getUserData().inAir = false + b:getUserData().jumpdouble = true + end +end + +-- endContact +function World.endContact(a, b, coll) + print(b:getUserData().name .. " is in air") + b:getUserData().inAir = true +end \ No newline at end of file -- cgit v1.1