diff options
author | Aki <nthirtyone@gmail.com> | 2016-05-22 16:29:12 +0200 |
---|---|---|
committer | Aki <nthirtyone@gmail.com> | 2016-05-22 16:29:12 +0200 |
commit | bbee57ad4fbb9a12c5e3947fcee68657d0fa52c5 (patch) | |
tree | f6435fb85afb221688cb802bc90664d10a9a48b9 | |
parent | b9fd32317e2af74ab6c9fb410666c26793d4f7a6 (diff) | |
download | roflnauts-bbee57ad4fbb9a12c5e3947fcee68657d0fa52c5.zip roflnauts-bbee57ad4fbb9a12c5e3947fcee68657d0fa52c5.tar.gz roflnauts-bbee57ad4fbb9a12c5e3947fcee68657d0fa52c5.tar.bz2 |
Map loads from file
-rw-r--r-- | main.lua | 18 | ||||
-rw-r--r-- | maps/default.lua | 38 | ||||
-rw-r--r-- | player.lua | 7 | ||||
-rw-r--r-- | world.lua | 47 |
4 files changed, 88 insertions, 22 deletions
@@ -10,8 +10,8 @@ require "effect" -- Temporary debug debug = false -third = true -fourth = false +third = "clunk" +fourth = nil --"yuri" -- Load function love.load () @@ -25,13 +25,7 @@ function love.load () love.graphics.setFont(Font) -- ZU WARUDO! - w = World:new() - w:createPlatform(290/2, 180/2, {-91,1, 90,1, 90,10, 5,76, -5,76, -91,10}, "assets/platform_big.png") - w:createPlatform(290/2+140, 180/2+50, {-26,1, 26,1, 26,30, -26,30}, "assets/platform_small.png") - w:createPlatform(290/2-140, 180/2+50, {-26,1, 26,1, 26,30, -26,30}, "assets/platform_small.png") - w:createPlatform(290/2, 180/2-50, {-17,1, 17,1, 17,16, -17,16}, "assets/platform_top.png") - w:createNaut(290/2-15, 180/2 - 80, "leon") - w:createNaut(290/2+15, 180/2 - 80, "lonestar") + w = World:new("default", "leon", "lonestar", third, fourth) -- Temporary settings for second player w.Nauts[2].key_left = "a" @@ -42,8 +36,7 @@ function love.load () w.Nauts[2].key_hit = "f" -- Temporary settings for third player - if third then - w:createNaut(290/2+05, 180/2 - 80, "clunk") + if third ~= nil then w.Nauts[3].key_left = "kp4" w.Nauts[3].key_right = "kp6" w.Nauts[3].key_up = "kp8" @@ -53,8 +46,7 @@ function love.load () end -- Temporary settings for fourth player - if fourth then - w:createNaut(290/2-05, 180/2 - 80, "yuri") + if fourth ~= nil then w.Nauts[4].key_left = "b" w.Nauts[4].key_right = "m" w.Nauts[4].key_up = "h" diff --git a/maps/default.lua b/maps/default.lua new file mode 100644 index 0000000..8d9740b --- /dev/null +++ b/maps/default.lua @@ -0,0 +1,38 @@ +-- Default map from original roflnauts +return { + color_top = {193, 100, 99, 255}, + color_mid = {189, 95, 93, 255}, + color_bot = {179, 82, 80, 255}, + respawns = { + {x = 130, y = 10}, + {x = 140, y = 10}, + {x = 150, y = 10}, + {x = 160, y = 10} + }, + platforms = { + { + x = 145, + y = 90, + shape = {-91,1, 90,1, 90,10, 5,76, -5,76, -91,10}, + sprite = "assets/platform_big.png" + }, + { + x = 285, + y = 140, + shape = {-26,1, 26,1, 26,30, -26,30}, + sprite = "assets/platform_small.png" + }, + { + x = 5, + y = 140, + shape = {-26,1, 26,1, 26,30, -26,30}, + sprite = "assets/platform_small.png" + }, + { + x = 145, + y = 40, + shape = {-17,1, 17,1, 17,16, -17,16}, + sprite = "assets/platform_top.png" + } + } +} @@ -149,8 +149,9 @@ function Player:update (dt) -- # DEATH -- We all die in the end. - if (self.body:getX() < -600 or self.body:getX() > 780 or - self.body:getY() < -500 or self.body:getY() > 500) and + local m = self.world.map + if (self.body:getX() < m.center_x - m.width*1.5 or self.body:getX() > m.center_x + m.width*1.5 or + self.body:getY() < m.center_y - m.height*1.5 or self.body:getY() > m.center_y + m.height*1.5) and self.alive then self:die() @@ -349,7 +350,7 @@ end function Player:respawn () self.alive = true self.body:setLinearVelocity(0,0) - self.body:setPosition(290/2, 180/2-80) + self.body:setPosition(self.world:getSpawnPosition()) self.body:setActive(true) self:createEffect("respawn") self:changeAnimation("idle") @@ -16,11 +16,13 @@ World = { camera = nil, -- cloud generator clouds_delay = 6, - clouds_initial = nil + clouds_initial = nil, + -- Map + map = nil } -- Constructor of `World` ZA WARUDO! -function World:new() +function World:new(map, ...) -- Meta local o = {} setmetatable(o, self) @@ -47,9 +49,40 @@ function World:new() for i=1,5 do o:randomizeCloud(false) end + -- Map + local map = map or "default" + o:loadMap(map) + -- Nauts + o:spawnNauts(...) return o end +-- Load map from file +function World:loadMap(name) + local name = name or "default" + name = "maps/" .. name + local map = require(name) + self.map = map + for _,platform in pairs(self.map.platforms) do + self:createPlatform(platform.x, platform.y, platform.shape, platform.sprite) + end +end + +-- Spawn all the nauts for the round +function World:spawnNauts(...) + local nauts = {...} + for _,naut in pairs(nauts) do + local x,y = self:getSpawnPosition() + self:createNaut(x, y, naut) + end +end + +-- Get respawn location +function World:getSpawnPosition() + local n = math.random(1, #self.map.respawns) + return self.map.respawns[n].x, self.map.respawns[n].y +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)) @@ -140,10 +173,12 @@ 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) + love.graphics.setColor(self.map.color_bot) + love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight()) + love.graphics.setColor(self.map.color_mid) + love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight()*0.8) + love.graphics.setColor(self.map.color_top) + love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight()*0.25) -- Camera stuff local offset_x, offset_y = self.camera:getOffsets() |