diff options
-rw-r--r-- | player.lua | 7 | ||||
-rw-r--r-- | ray.lua | 43 | ||||
-rw-r--r-- | world.lua | 23 |
3 files changed, 71 insertions, 2 deletions
@@ -293,6 +293,11 @@ function Player:draw (offset_x, offset_y, scale, debug) end end +-- getPosition +function Player:getPosition() + return self.body:getPosition() +end + -- Draw HUD of `Player` -- elevation: 1 bottom, 0 top function Player:drawHUD (x,y,scale,elevation) @@ -386,4 +391,4 @@ end function Player:playSound(sfx) local source = love.audio.newSource(self.sfx[sfx]) source:play() -end
\ No newline at end of file +end @@ -0,0 +1,43 @@ +-- `Ray` +-- That awesome effect that blinks when player dies! + +-- WHOLE CODE HAS FLAG OF "need a cleanup" + +Ray = { + naut = nil, + world = nil, + delay = 0.3 +} +function Ray:new(naut, world) + -- Meta + local o = {} + setmetatable(o, self) + self.__index = self + -- Init + o.naut = naut + o.world = world + return o +end +function Ray:update(dt) + self.delay = self.delay - dt + if self.delay < 0 then + return true -- delete + end + return false +end +function Ray:draw(offset_x, offset_y, scale) + love.graphics.setLineStyle("rough") + love.graphics.setLineWidth(self.delay*160*scale) + local x, y = self.naut:getPosition() + local m = self.world.map + local dy = m.height + if y > m.center_y then + dy = -dy + end + local dx = m.width + if x > m.center_x then + dx = -dx + end + love.graphics.line((m.center_x+offset_x+dx)*scale,(m.center_y+offset_y+dy)*scale,(x+offset_x)*scale,(y+dy*0.7+offset_y)*scale) + love.graphics.setLineWidth(1) +end @@ -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 |