From 4e3b4358bb3f8280a4739bf6a110823b029acae2 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 13 Sep 2017 04:53:00 +0200 Subject: CloudGenerators now can be configured to use layer with ratio --- config/maps/default.lua | 15 ++++++++++++++- not/CloudGenerator.lua | 4 +++- not/World.lua | 9 ++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/config/maps/default.lua b/config/maps/default.lua index 6acc577..43fb696 100644 --- a/config/maps/default.lua +++ b/config/maps/default.lua @@ -16,7 +16,20 @@ return { clouds = "assets/clouds.png", animations = "clouds-default", - count = 8 + count = 4, + ratio = 0.9 + }, + { + clouds = "assets/clouds.png", + animations = "clouds-default", + count = 3, + ratio = 0.8 + }, + { + clouds = "assets/clouds.png", + animations = "clouds-default", + count = 3, + ratio = 0.7 }, { ratio = 0, diff --git a/not/CloudGenerator.lua b/not/CloudGenerator.lua index 36ec70f..75fd180 100644 --- a/not/CloudGenerator.lua +++ b/not/CloudGenerator.lua @@ -9,8 +9,9 @@ function CloudGenerator:new (atlas, animations, count, world) self.atlas = atlas self.quads = animations self.count = count - self.interval = 6 + self.interval = 8 self.timer = 0 + self.layer = false end -- TODO: This was a bad idea. Move Cloud creation back to World, pass created Cloud here for configuration. @@ -21,6 +22,7 @@ function CloudGenerator:createCloud (x, y, style) cloud:setVelocity(13, 0) cloud:setBoundary(340, 320) cloud.generator = self + cloud.layer = self.layer return cloud end diff --git a/not/World.lua b/not/World.lua index f576fca..5492c76 100644 --- a/not/World.lua +++ b/not/World.lua @@ -75,6 +75,7 @@ function World:initLayers () end --- Builds map using one of tables frin config files located in `config/maps/` directory. +-- TODO: Clean World@buildMap. Possibly explode into more methods. function World:buildMap () for _,op in pairs(self.map.create) do if op.platform then @@ -97,11 +98,15 @@ function World:buildMap () bg.layer = self:addLayer(width, height, op.ratio) end if op.clouds then + local width, height = love.graphics.getDimensions() local animations = op.animations if type(animations) == "string" then animations = require("config.animations." .. animations) end local cg = CloudGenerator(op.clouds, animations, op.count, self) + if op.ratio then + cg.layer = self:addLayer(width, height, op.ratio) + end self:insertEntity(cg) cg:run(op.count, true) end @@ -177,7 +182,9 @@ end function World:insertCloud (cloud) table.insert(self.entities, cloud) - cloud.layer = self.layers.clouds + if not cloud.layer then + cloud.layer = self.layers.clouds + end return cloud end -- cgit v1.1