From 2b207c4282219bae06eff9589824dc851f014be3 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 29 Jun 2016 03:28:35 +0200 Subject: Flying Rayss! --- world.lua | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'world.lua') diff --git a/world.lua b/world.lua index 8da0d6b..86a8ab1 100644 --- a/world.lua +++ b/world.lua @@ -8,6 +8,7 @@ require "player" require "cloud" require "effect" require "decoration" +require "ray" -- Metatable of `World` -- nils initialized in constructor @@ -19,6 +20,7 @@ World = { Clouds = nil, Decorations = nil, Effects = nil, + Rays = nil, camera = nil, -- cloud generator clouds_delay = 5, @@ -53,6 +55,8 @@ function World:new(map, ...) o.Effects = e local d = {} o.Decorations = d + local r = {} + o.Rays = r -- Random init math.randomseed(os.time()) -- Map @@ -166,6 +170,11 @@ function World:createEffect(name, x, y) table.insert(self.Effects, Effect:new(name, x, y)) end +-- Add a ray +function World:createRay(naut) + table.insert(self.Rays, Ray:new(naut, self)) +end + -- get Nauts functions -- more than -1 lives function World:getNautsPlayable() @@ -192,6 +201,7 @@ end -- Event: when player is killed function World:onNautKilled(naut) self.camera:startShake() + self:createRay(naut) local nauts = self:getNautsPlayable() if self.lastNaut then local m = Menu:new() @@ -236,6 +246,12 @@ function World:update(dt) table.remove(self.Effects, _) end end + -- Rays + for _,ray in pairs(self.Rays) do + if ray:update(dt) then + table.remove(self.Rays, _) + end + end -- Bounce `winner` self.win_move = self.win_move + dt if self.win_move > 2 then @@ -283,6 +299,11 @@ function World:draw() platform:draw(offset_x, offset_y, scale, debug) end + -- Draw rays + for _,ray in pairs(self.Rays) do + ray:draw(offset_x, offset_y, scale) + end + -- draw center if debug then local c = self.camera @@ -351,4 +372,4 @@ function World.endContact(a, b, coll) print(b:getUserData().name .. " is in air") b:getUserData().inAir = true end -end \ No newline at end of file +end -- cgit v1.1