summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2016-06-03 00:55:56 +0200
committerAki <nthirtyone@gmail.com>2016-06-03 00:55:56 +0200
commit1027ec0d527d29c5ae47919ae12bcab176b46182 (patch)
tree57c76cb5c3fbcba05ed72bdcdd07fe18ed2b93ad
parent728c8aa62add0310119017615c7e973e35daf146 (diff)
downloadroflnauts-1027ec0d527d29c5ae47919ae12bcab176b46182.zip
roflnauts-1027ec0d527d29c5ae47919ae12bcab176b46182.tar.gz
roflnauts-1027ec0d527d29c5ae47919ae12bcab176b46182.tar.bz2
Map decorations added
-rw-r--r--decoration.lua30
-rw-r--r--maps/default.lua3
-rw-r--r--world.lua20
3 files changed, 50 insertions, 3 deletions
diff --git a/decoration.lua b/decoration.lua
new file mode 100644
index 0000000..226b7f9
--- /dev/null
+++ b/decoration.lua
@@ -0,0 +1,30 @@
+Decoration = {
+ world = nil,
+ sprite = nil,
+ x = 0,
+ y = 0
+}
+function Decoration:new(x, y, sprite)
+ local o = {}
+ setmetatable(o, self)
+ self.__index = self
+ o.sprite = love.graphics.newImage(sprite)
+ o:setPosition(x,y)
+ return o
+end
+function Decoration:setPosition(x, y)
+ self.x, self.y = x, y
+end
+function Decoration:getPosition()
+ return self.x, self.y
+end
+function Decoration:draw(offset_x, offset_y, scale)
+ -- defaults
+ local offset_x = offset_x or 0
+ local offset_y = offset_y or 0
+ local scale = scale or 1
+ -- draw
+ love.graphics.setColor(255,255,255,255)
+ local x, y = self:getPosition()
+ love.graphics.draw(self.sprite, (x+offset_x)*scale, (y+offset_y)*scale, 0, scale, scale)
+end \ No newline at end of file
diff --git a/maps/default.lua b/maps/default.lua
index a2d5275..d21f33f 100644
--- a/maps/default.lua
+++ b/maps/default.lua
@@ -38,5 +38,6 @@ return {
shape = {0,1, 34,1, 34,16, 0,16},
sprite = "assets/platform_top.png"
}
- }
+ },
+ decorations = {}
} \ No newline at end of file
diff --git a/world.lua b/world.lua
index c11855d..d1f1a3e 100644
--- a/world.lua
+++ b/world.lua
@@ -7,6 +7,7 @@ require "ground"
require "player"
require "cloud"
require "effect"
+require "decoration"
-- Metatable of `World`
-- nils initialized in constructor
@@ -16,8 +17,8 @@ World = {
Nauts = nil,
Platforms = nil,
Clouds = nil,
- EffectsBottom = nil,
- EffectsTop = nil,
+ Decorations = nil,
+ Effects = nil,
camera = nil,
-- cloud generator
clouds_delay = 6,
@@ -45,6 +46,8 @@ function World:new(map, ...)
o.Clouds = c
local e = {}
o.Effects = e
+ local d = {}
+ o.Decorations = d
-- Random init
math.randomseed(os.time())
-- Map
@@ -71,6 +74,9 @@ function World:loadMap(name)
for _,platform in pairs(self.map.platforms) do
self:createPlatform(platform.x, platform.y, platform.shape, platform.sprite)
end
+ for _,decoration in pairs(self.map.decorations) do
+ self:createDecoration(decoration.x, decoration.y, decoration.sprite)
+ end
end
-- Spawn all the nauts for the round
@@ -107,6 +113,11 @@ function World:createNaut(x, y, name)
return naut
end
+-- Add new decoration to the world
+function World:createDecoration(x, y, sprite)
+ table.insert(self.Decorations, Decoration:new(x, y, sprite))
+end
+
-- Add new cloud to the world
function World:createCloud(x, y, t, v)
table.insert(self.Clouds, Cloud:new(x, y, t, v))
@@ -190,6 +201,11 @@ function World:draw()
cloud:draw(offset_x, offset_y, scale)
end
+ -- Draw decorations
+ for _,decoration in pairs(self.Decorations) do
+ decoration:draw(offset_x, offset_y, scale)
+ end
+
-- Draw effects
for _,effect in pairs(self.Effects) do
effect:draw(offset_x,offset_y, scale)