summaryrefslogtreecommitdiffhomepage
path: root/world.lua
diff options
context:
space:
mode:
Diffstat (limited to 'world.lua')
-rw-r--r--world.lua23
1 files changed, 22 insertions, 1 deletions
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