summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2017-04-06 16:09:50 +0200
committerAki <nthirtyone@gmail.com>2017-04-06 16:09:50 +0200
commit2508af1856d4b30678e11fa610c0449bf2135ed0 (patch)
tree0fd9ca7322263ba3478990e86b1380d0409e4bf1
parent5ed018c810a5433851fefc2c45792de1da7e7ca8 (diff)
downloadroflnauts-2508af1856d4b30678e11fa610c0449bf2135ed0.zip
roflnauts-2508af1856d4b30678e11fa610c0449bf2135ed0.tar.gz
roflnauts-2508af1856d4b30678e11fa610c0449bf2135ed0.tar.bz2
Hero.alive -> Hero.isAlive; World.init method
-rw-r--r--not/Hero.lua16
-rw-r--r--not/World.lua81
2 files changed, 44 insertions, 53 deletions
diff --git a/not/Hero.lua b/not/Hero.lua
index 6d0a202..7c2555a 100644
--- a/not/Hero.lua
+++ b/not/Hero.lua
@@ -13,7 +13,7 @@ Hero = {
combo = 0,
lives = 3,
spawntimer = 2,
- alive = true,
+ isAlive = true,
punchCooldown = 0.25,
punchdir = 0, -- a really bad thing
-- Movement
@@ -90,7 +90,7 @@ function Hero:update (dt)
local x, y = self:getPosition()
if (x < m.center_x - m.width*1.5 or x > m.center_x + m.width*1.5 or
y < m.center_y - m.height*1.5 or y > m.center_y + m.height*1.5) and
- self.alive
+ self.isAlive
then
self:die()
end
@@ -99,7 +99,7 @@ function Hero:update (dt)
if self.spawntimer > 0 then
self.spawntimer = self.spawntimer - dt
end
- if self.spawntimer <= 0 and not self.alive and self.lives >= 0 then
+ if self.spawntimer <= 0 and not self.isAlive and self.lives >= 0 then
self:respawn()
end
@@ -145,7 +145,7 @@ end
-- Draw of `Hero`
function Hero:draw (offset_x, offset_y, scale, debug)
- if not self.alive then return end
+ if not self.isAlive then return end
PhysicalBody.draw(self, offset_x, offset_y, scale, debug)
end
@@ -153,7 +153,7 @@ end
-- elevation: 1 bottom, 0 top
function Hero:drawHUD (x,y,scale,elevation)
-- hud displays only if player is alive
- if self.alive then
+ if self.isAlive then
love.graphics.setColor(255,255,255,255)
love.graphics.draw(self.portrait_frame, self.portrait_box, (x)*scale, (y)*scale, 0, scale, scale)
love.graphics.draw(self.portrait_sprite, self.portrait_sheet[self.name], (x+2)*scale, (y+3)*scale, 0, scale, scale)
@@ -241,7 +241,7 @@ function Hero:die ()
self:playSound(1)
self.combo = Hero.combo -- INITIAL from metatable
self.lives = self.lives - 1
- self.alive = false
+ self.isAlive = false
self.spawntimer = Hero.spawntimer -- INITIAL from metatable
self:setBodyActive(false)
self.world:onNautKilled(self)
@@ -249,7 +249,7 @@ end
-- And then respawn. Like Jon Snow.
function Hero:respawn ()
- self.alive = true
+ self.isAlive = true
self:setLinearVelocity(0,0)
self:setPosition(self.world:getSpawnPosition()) -- TODO: I'm not convinced about getting new position like this.
self:setBodyActive(true)
@@ -260,7 +260,7 @@ end
-- Sounds
-- TODO: Possibly export to nonexistent SoundEmitter class. Can be used by World (Stage), too.
function Hero:playSound (sfx, force)
- if self.alive or force then
+ if self.isAlive or force then
local source = love.audio.newSource(self.sfx[sfx])
source:play()
end
diff --git a/not/World.lua b/not/World.lua
index 8aa9d28..6e57ac1 100644
--- a/not/World.lua
+++ b/not/World.lua
@@ -1,18 +1,6 @@
--- `World`
+--- `World`
-- Used to manage physical world and everything inside it: clouds, platforms, nauts, background etc.
-- TODO: Possibly move common parts of `World` and `Menu` to abstract class `Scene`.
-
--- WHOLE CODE HAS FLAG OF "need a cleanup"
-
-require "not.Platform"
-require "not.Player"
-require "not.Cloud"
-require "not.Effect"
-require "not.Decoration"
-require "not.Ray"
-
--- Metatable of `World`
--- nils initialized in constructor
World = {
-- inside
world = nil,
@@ -23,6 +11,7 @@ World = {
Effects = nil,
Rays = nil,
camera = nil,
+ isActive = true,
-- cloud generator
clouds_delay = 5,
-- Map
@@ -36,48 +25,54 @@ World = {
music = nil
}
+World.__index = World
+
+require "not.Platform"
+require "not.Player"
+require "not.Cloud"
+require "not.Effect"
+require "not.Decoration"
+require "not.Ray"
+
-- Constructor of `World` ZA WARUDO!
-- TODO: push stuff to initialization method.
function World:new (map, nauts)
- -- Meta
- local o = {}
- setmetatable(o, self)
- self.__index = self
- -- Physical world initialization
+ local o = setmetatable({}, self)
+ o:init(map, nauts)
+ return o
+end
+
+-- Init za warudo
+function World:init (map, nauts)
+ -- Box2D physical world.
love.physics.setMeter(64)
- o.world = love.physics.newWorld(0, 9.81*64, true)
- o.world:setCallbacks(o.beginContact, o.endContact)
- -- Empty tables for objects
- -- TODO: DEAR DEER, do you see it?
+ self.world = love.physics.newWorld(0, 9.81*64, true)
+ self.world:setCallbacks(self.beginContact, self.endContact)
+ -- Tables for entities. TODO: DEAR DEER, do you see it?
local n = {}
- o.Nauts = n
+ self.Nauts = n
local p = {}
- o.Platforms = {}
+ self.Platforms = {}
local c = {}
- o.Clouds = c
+ self.Clouds = c
local e = {}
- o.Effects = e
+ self.Effects = e
local d = {}
- o.Decorations = d
+ self.Decorations = d
local r = {}
- o.Rays = r
+ self.Rays = r
-- Random init; TODO: use LOVE2D's random.
math.randomseed(os.time())
- -- Map
+ -- Map and misc.
local map = map or "default"
- o:loadMap(map)
- -- Nauts
- o:spawnNauts(nauts)
- -- Create camera
- o.camera = Camera:new(o)
- -- Play music
- o.music = Music:new(o.map.theme)
- return o
+ self:loadMap(map)
+ self:spawnNauts(nauts)
+ self.camera = Camera:new(self)
+ self.music = Music:new(self.map.theme)
end
-- The end of the world
function World:delete ()
- self.world:destroy()
for _,platform in pairs(self.Platforms) do
platform:delete()
end
@@ -85,7 +80,7 @@ function World:delete ()
naut:delete()
end
self.music:delete()
- self = nil
+ self.world:destroy()
end
-- Load map from file
@@ -202,7 +197,7 @@ end
function World:getNautsAlive ()
local nauts = {}
for _,naut in self.Nauts do
- if naut.alive then
+ if naut.isAlive then
table.insert(nauts, naut)
end
end
@@ -239,9 +234,8 @@ end
-- LÖVE2D callbacks
-- Update ZU WARUDO
function World:update (dt)
- -- Physical world
+
self.world:update(dt)
- -- Camera
self.camera:update(dt)
-- Engine world: Nauts, Grounds (kek) and Decorations - all Animateds (top kek)
for _,naut in pairs(self.Nauts) do
@@ -385,9 +379,7 @@ function World.beginContact (a, b, coll)
if a:getCategory() == 1 then
local x,y = coll:getNormal()
if y < -0.6 then
- -- TODO: remove debug messages
-- TODO: move landing to `not.Hero`
- print(b:getUserData().name .. " is not in air")
-- Move them to Hero
b:getUserData().inAir = false
b:getUserData().jumpCounter = 2
@@ -409,7 +401,6 @@ end
-- endContact
function World.endContact (a, b, coll)
if a:getCategory() == 1 then
- print(b:getUserData().name .. " is in air")
-- Move them to Hero
b:getUserData().inAir = true
end