From 62b67be7882dffebd6de0c8241d253d806a6905c Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 26 May 2017 19:14:27 +0200 Subject: Halfway through with moving to new OOP module --- not/Hero.lua | 92 ++++++++++++++++++++++++++---------------------------------- 1 file changed, 40 insertions(+), 52 deletions(-) (limited to 'not/Hero.lua') diff --git a/not/Hero.lua b/not/Hero.lua index feb61da..1f7cd8b 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -1,60 +1,48 @@ +require "not.PhysicalBody" + --- `Hero` -- Hero (often referred to as: "naut") entity that exists in a game world. -- Collision category: [2] -Hero = { - -- General and physics - name = "empty", - angle = 0, - facing = 1, - max_velocity = 105, - world = --[[not.World]]nil, - group = nil, - -- Combat - combo = 0, - lives = 3, - spawntimer = 2, - isAlive = true, - punchCooldown = 0.25, - punchdir = 0, -- a really bad thing - -- Movement - inAir = true, - salto = false, - isJumping = false, - isWalking = false, - jumpTimer = 0.16, - jumpCounter = 2, - -- Statics - portrait_sprite = nil, - portrait_frame = nil, - portrait_sheet = getNautsIconsList(), - portrait_box = love.graphics.newQuad( 0, 15, 32,32, 80,130), - sfx = require "config.sounds", -} +Hero = PhysicalBody:extends() --- `Hero` is a child of `PhysicalBody`. -require "not.PhysicalBody" -Hero.__index = Hero -setmetatable(Hero, PhysicalBody) +Hero.name = "empty" +Hero.angle = 0 +Hero.facing = 1 +Hero.max_velocity = 105 +Hero.group = nil +-- Combat +Hero.combo = 0 +Hero.lives = 3 +Hero.spawntimer = 2 +Hero.isAlive = true +Hero.punchCooldown = 0.25 +Hero.punchdir = 0 -- a really bad thing +-- Movement +Hero.inAir = true +Hero.salto = false +Hero.isJumping = false +Hero.isWalking = false +Hero.jumpTimer = 0.16 +Hero.jumpCounter = 2 +-- Statics +Hero.portrait_sprite = nil +Hero.portrait_frame = nil +Hero.portrait_sheet = getNautsIconsList() +Hero.portrait_box = love.graphics.newQuad(0, 15, 32,32, 80,130) +Hero.sfx = require "config.sounds" -- Constructor of `Hero`. -function Hero:new (game, world, x, y, name) - local o = setmetatable({}, self) - o:init(name, game, x, y) - -- Load portraits statically. - if self.portrait_sprite == nil then - self.portrait_sprite = love.graphics.newImage("assets/portraits.png") - self.portrait_frame = love.graphics.newImage("assets/menu.png") +function Hero:new (name, x, y, world) + -- TODO: Statics moved temporarily here. Should be moved to e.g. `load()`. + if Hero.portrait_sprite == nil then + Hero.portrait_sprite = love.graphics.newImage("assets/portraits.png") + Hero.portrait_frame = love.graphics.newImage("assets/menu.png") end - return o -end - --- Initializer of `Hero`. -function Hero:init (name, world, x, y) -- Find imagePath based on hero name. - local fileName = name or Hero.name -- INITIAL from metatable + local fileName = name or Hero.name -- INITIAL from prototype local imagePath = string.format("assets/nauts/%s.png", fileName) -- `PhysicalBody` initialization. - PhysicalBody.init(self, world, x, y, imagePath) + Hero.__super.new(self, x, y, world, imagePath) self:setBodyType("dynamic") self:setBodyFixedRotation(true) self.group = -1-#world.Nauts @@ -74,7 +62,7 @@ end -- Update callback of `Hero` function Hero:update (dt) - PhysicalBody.update(self, dt) + Hero.__super.update(self, dt) if self.body:isDestroyed() then return end -- Salto @@ -163,7 +151,7 @@ end -- Draw of `Hero` function Hero:draw (offset_x, offset_y, scale, debug) if not self.isAlive then return end - PhysicalBody.draw(self, offset_x, offset_y, scale, debug) + Hero.__super.draw(self, offset_x, offset_y, scale, debug) end -- Draw HUD of `Hero` @@ -209,7 +197,7 @@ end -- Sensor fixture is deleted after time set in UserData[1]; deleted by `not.Hero.update`. -- TODO: Magic numbers present in `not.Hero.punch`. function Hero:punch (direction) - self.punchCooldown = Hero.punchCooldown -- INITIAL from metatable + self.punchCooldown = Hero.punchCooldown -- INITIAL from prototype -- Choose shape based on punch direction. local shape if direction == "left" then shape = {-2,-6, -20,-6, -20,6, -2,6} end @@ -256,10 +244,10 @@ end -- DIE function Hero:die () self:playSound(1) - self.combo = Hero.combo -- INITIAL from metatable + self.combo = Hero.combo -- INITIAL from prototype self.lives = self.lives - 1 self.isAlive = false - self.spawntimer = Hero.spawntimer -- INITIAL from metatable + self.spawntimer = Hero.spawntimer -- INITIAL from prototype self:setBodyActive(false) self.world:onNautKilled(self) end -- cgit v1.1 From a00ac10a0c3654dccf7c8c92da6d8666f2f7ac48 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 15 Jun 2017 17:19:34 +0200 Subject: Removed magic numbers in punching --- not/Hero.lua | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'not/Hero.lua') diff --git a/not/Hero.lua b/not/Hero.lua index 1f7cd8b..cb205bf 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -31,6 +31,12 @@ Hero.portrait_sheet = getNautsIconsList() Hero.portrait_box = love.graphics.newQuad(0, 15, 32,32, 80,130) Hero.sfx = require "config.sounds" +Hero.PUNCH_FIXTURE_LIFETIME = 0.08 +Hero.PUNCH_LEFT = {-2,-6, -20,-6, -20,6, -2,6} +Hero.PUNCH_RIGHT = {2,-6, 20,-6, 20,6, 2,6} +Hero.PUNCH_UP = {-8,-4, -8,-20, 8,-20, 8,-4} +Hero.PUNCH_DOWN = {-8,4, -8,20, 8,20, 8,4} + -- Constructor of `Hero`. function Hero:new (name, x, y, world) -- TODO: Statics moved temporarily here. Should be moved to e.g. `load()`. @@ -39,7 +45,7 @@ function Hero:new (name, x, y, world) Hero.portrait_frame = love.graphics.newImage("assets/menu.png") end -- Find imagePath based on hero name. - local fileName = name or Hero.name -- INITIAL from prototype + local fileName = name or Hero.name -- INITIAL local imagePath = string.format("assets/nauts/%s.png", fileName) -- `PhysicalBody` initialization. Hero.__super.new(self, x, y, world, imagePath) @@ -195,22 +201,21 @@ end -- Creates temporary fixture for hero's body that acts as sensor. -- direction: ("left", "right", "up", "down") -- Sensor fixture is deleted after time set in UserData[1]; deleted by `not.Hero.update`. --- TODO: Magic numbers present in `not.Hero.punch`. function Hero:punch (direction) - self.punchCooldown = Hero.punchCooldown -- INITIAL from prototype + self.punchCooldown = Hero.punchCooldown -- Choose shape based on punch direction. local shape - if direction == "left" then shape = {-2,-6, -20,-6, -20,6, -2,6} end - if direction == "right" then shape = {2,-6, 20,-6, 20,6, 2,6} end - if direction == "up" then shape = {-8,-4, -8,-20, 8,-20, 8,-4} end - if direction == "down" then shape = {-8,4, -8,20, 8,20, 8,4} end + if direction == "left" then shape = Hero.PUNCH_LEFT end + if direction == "right" then shape = Hero.PUNCH_RIGHT end + if direction == "up" then shape = Hero.PUNCH_UP end + if direction == "down" then shape = Hero.PUNCH_DOWN end -- Create and set sensor fixture. local fixture = self:addFixture(shape, 0) fixture:setSensor(true) fixture:setCategory(3) fixture:setMask(1,3) fixture:setGroupIndex(self.group) - fixture:setUserData({0.08, direction}) + fixture:setUserData({Hero.PUNCH_FIXTURE_LIFETIME, direction}) self:playSound(4) end @@ -270,3 +275,5 @@ function Hero:playSound (sfx, force) source:play() end end + +return Hero -- cgit v1.1 From 0c70843b512c0e1633f77f5b0355cf5c2f80efe5 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 16 Jul 2017 22:10:07 +0200 Subject: Initial trial effect, it's too fun --- not/Hero.lua | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'not/Hero.lua') diff --git a/not/Hero.lua b/not/Hero.lua index cb205bf..0406e51 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -1,9 +1,7 @@ -require "not.PhysicalBody" - --- `Hero` -- Hero (often referred to as: "naut") entity that exists in a game world. -- Collision category: [2] -Hero = PhysicalBody:extends() +Hero = require "not.PhysicalBody":extends() Hero.name = "empty" Hero.angle = 0 @@ -114,6 +112,12 @@ function Hero:update (dt) self:respawn() end + -- Trail spawner + if self.combo > 100 then + local dx, dy = love.math.random(-4, 4), love.math.random(-4, 4) + self:createEffect("trail", dx, dy) + end + -- # PUNCH -- Cooldown self.punchCooldown = self.punchCooldown - dt @@ -188,14 +192,18 @@ function Hero:goToNextFrame () end -- Spawn `Effect` relative to `Hero` -function Hero:createEffect (name) - if name == "trail" or name == "hit" then - -- 16px effect: -7 -7 - self.world:createEffect(name, self.body:getX()-8, self.body:getY()-8) - elseif name ~= nil then - -- 24px effect: -12 -15 - self.world:createEffect(name, self.body:getX()-12, self.body:getY()-15) +function Hero:createEffect (name, dx, dy) + local x, y = self.body:getX()-8, self.body:getY()-8 -- 16px effect: -7 -7 + if not (name == "trail") and not (name == "hit") then + x, y = x-4, y-7 -- 24px effect: -12 -15 + end + if dx then + x = x + dx + end + if dy then + y = y + dy end + self.world:createEffect(name, x, y) end -- Creates temporary fixture for hero's body that acts as sensor. -- cgit v1.1 From 539faff13d2ca690d94102abf6eef85572e9a287 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 16 Jul 2017 23:09:09 +0200 Subject: Additional condition for trail to appear Wider range for random position --- not/Hero.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'not/Hero.lua') diff --git a/not/Hero.lua b/not/Hero.lua index 0406e51..cb4d249 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -113,8 +113,8 @@ function Hero:update (dt) end -- Trail spawner - if self.combo > 100 then - local dx, dy = love.math.random(-4, 4), love.math.random(-4, 4) + if self.combo > 100 and self.punchCooldown > 0 then + local dx, dy = love.math.random(-5, 5), love.math.random(-5, 5) self:createEffect("trail", dx, dy) end -- cgit v1.1 From 25c3cdf7ee06a6415e7bb26418ffb64dda3a2151 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 16 Jul 2017 23:23:49 +0200 Subject: Exploding update and new methods of Hero --- not/Hero.lua | 78 +++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 43 insertions(+), 35 deletions(-) (limited to 'not/Hero.lua') diff --git a/not/Hero.lua b/not/Hero.lua index cb4d249..b097767 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -37,26 +37,13 @@ Hero.PUNCH_DOWN = {-8,4, -8,20, 8,20, 8,4} -- Constructor of `Hero`. function Hero:new (name, x, y, world) - -- TODO: Statics moved temporarily here. Should be moved to e.g. `load()`. - if Hero.portrait_sprite == nil then - Hero.portrait_sprite = love.graphics.newImage("assets/portraits.png") - Hero.portrait_frame = love.graphics.newImage("assets/menu.png") - end - -- Find imagePath based on hero name. - local fileName = name or Hero.name -- INITIAL - local imagePath = string.format("assets/nauts/%s.png", fileName) - -- `PhysicalBody` initialization. + local imagePath = string.format("assets/nauts/%s.png", name) + Hero.load() Hero.__super.new(self, x, y, world, imagePath) self:setBodyType("dynamic") self:setBodyFixedRotation(true) self.group = -1-#world.Nauts - -- Main fixture initialization. - local fixture = self:addFixture({-5,-8, 5,-8, 5,8, -5,8}, 8) - fixture:setUserData(self) - fixture:setCategory(2) - fixture:setMask(2) - fixture:setGroupIndex(self.group) - -- Actual `Hero` initialization. + self:newFixture() self.world = world self.punchCooldown = 0 self.name = name @@ -64,11 +51,30 @@ function Hero:new (name, x, y, world) self:createEffect("respawn") end +-- TODO: This is temporarily called by constructor. +function Hero.load () + if Hero.portrait_sprite == nil then + Hero.portrait_sprite = love.graphics.newImage("assets/portraits.png") + Hero.portrait_frame = love.graphics.newImage("assets/menu.png") + end +end + +--- Creates hero's fixture and adds it to physical body. +function Hero:newFixture () + local fixture = self:addFixture({-5,-8, 5,-8, 5,8, -5,8}, 8) + fixture:setUserData(self) + fixture:setCategory(2) + fixture:setMask(2) + fixture:setGroupIndex(self.group) +end + -- Update callback of `Hero` function Hero:update (dt) Hero.__super.update(self, dt) - if self.body:isDestroyed() then return end - + if self.body:isDestroyed() then + return + end + self:dampVelocity(dt) -- Salto if self.salto and (self.current == self.animations.walk or self.current == self.animations.default) then self.angle = (self.angle + 17 * dt * self.facing) % 360 @@ -76,23 +82,6 @@ function Hero:update (dt) self.angle = 0 end - -- Custom linear damping. - if not self.isWalking then - local face = nil - local x, y = self:getLinearVelocity() - if x < -12 then - face = 1 - elseif x > 12 then - face = -1 - else - face = 0 - end - self:applyForce(40*face,0) - if not self.inAir then - self:applyForce(80*face,0) - end - end - -- Could you please die? -- TODO: World/Map function for testing if Point is inside playable area. local m = self.world.map @@ -147,6 +136,25 @@ function Hero:update (dt) end end +--- Damps linear velocity every frame by applying minor force to body. +function Hero:dampVelocity (dt) + if not self.isWalking then + local face + local x, y = self:getLinearVelocity() + if x < -12 then + face = 1 + elseif x > 12 then + face = -1 + else + face = 0 + end + self:applyForce(40*face,0) + if not self.inAir then + self:applyForce(80*face,0) + end + end +end + -- TODO: comment them and place them somewhere properly function Hero:getAngle () return self.angle -- cgit v1.1 From 113d648178755dd0fb9f4ea0e7726f173ecc5223 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 16 Jul 2017 23:45:35 +0200 Subject: Cleaning-up Hero and Player, this far w/o big changes --- not/Hero.lua | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'not/Hero.lua') diff --git a/not/Hero.lua b/not/Hero.lua index b097767..d1621df 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -3,17 +3,7 @@ -- Collision category: [2] Hero = require "not.PhysicalBody":extends() -Hero.name = "empty" -Hero.angle = 0 -Hero.facing = 1 -Hero.max_velocity = 105 -Hero.group = nil -- Combat -Hero.combo = 0 -Hero.lives = 3 -Hero.spawntimer = 2 -Hero.isAlive = true -Hero.punchCooldown = 0.25 Hero.punchdir = 0 -- a really bad thing -- Movement Hero.inAir = true @@ -29,6 +19,9 @@ Hero.portrait_sheet = getNautsIconsList() Hero.portrait_box = love.graphics.newQuad(0, 15, 32,32, 80,130) Hero.sfx = require "config.sounds" +Hero.MAX_VELOCITY = 105 +Hero.RESPAWN_TIME = 2 +Hero.PUNCH_COOLDOWN = 0.25 Hero.PUNCH_FIXTURE_LIFETIME = 0.08 Hero.PUNCH_LEFT = {-2,-6, -20,-6, -20,6, -2,6} Hero.PUNCH_RIGHT = {2,-6, 20,-6, 20,6, 2,6} @@ -40,14 +33,23 @@ function Hero:new (name, x, y, world) local imagePath = string.format("assets/nauts/%s.png", name) Hero.load() Hero.__super.new(self, x, y, world, imagePath) + -- Physics + self.group = -1-#world.Nauts self:setBodyType("dynamic") self:setBodyFixedRotation(true) - self.group = -1-#world.Nauts self:newFixture() + -- General self.world = world - self.punchCooldown = 0 self.name = name + self.lives = 3 + self.angle = 0 + self.facing = 1 + self.combo = 0 + self.punchCooldown = 0 + self.spawntimer = 2 + self.isAlive = true self:setAnimationsList(require("config.animations.hero")) + -- Post-creation self:createEffect("respawn") end @@ -218,7 +220,7 @@ end -- direction: ("left", "right", "up", "down") -- Sensor fixture is deleted after time set in UserData[1]; deleted by `not.Hero.update`. function Hero:punch (direction) - self.punchCooldown = Hero.punchCooldown + self.punchCooldown = Hero.PUNCH_COOLDOWN -- Choose shape based on punch direction. local shape if direction == "left" then shape = Hero.PUNCH_LEFT end @@ -265,10 +267,10 @@ end -- DIE function Hero:die () self:playSound(1) - self.combo = Hero.combo -- INITIAL from prototype + self.combo = 0 self.lives = self.lives - 1 self.isAlive = false - self.spawntimer = Hero.spawntimer -- INITIAL from prototype + self.spawntimer = Hero.RESPAWN_TIME self:setBodyActive(false) self.world:onNautKilled(self) end -- cgit v1.1 From c668460a615bc5f6a3e3f921f570269b1598bfc9 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 17 Jul 2017 10:36:25 +0200 Subject: More properties moved to constructor in Hero --- not/Hero.lua | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'not/Hero.lua') diff --git a/not/Hero.lua b/not/Hero.lua index d1621df..6eb3978 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -6,19 +6,15 @@ Hero = require "not.PhysicalBody":extends() -- Combat Hero.punchdir = 0 -- a really bad thing -- Movement -Hero.inAir = true -Hero.salto = false -Hero.isJumping = false -Hero.isWalking = false Hero.jumpTimer = 0.16 Hero.jumpCounter = 2 -- Statics -Hero.portrait_sprite = nil -Hero.portrait_frame = nil Hero.portrait_sheet = getNautsIconsList() Hero.portrait_box = love.graphics.newQuad(0, 15, 32,32, 80,130) Hero.sfx = require "config.sounds" +Hero.IMAGE_PORTRAITS = nil +Hero.IMAGE_FRAME = nil Hero.MAX_VELOCITY = 105 Hero.RESPAWN_TIME = 2 Hero.PUNCH_COOLDOWN = 0.25 @@ -48,6 +44,10 @@ function Hero:new (name, x, y, world) self.punchCooldown = 0 self.spawntimer = 2 self.isAlive = true + self.inAir = true + self.isJumping = false + self.isWalking = false + self.salto = false self:setAnimationsList(require("config.animations.hero")) -- Post-creation self:createEffect("respawn") @@ -55,9 +55,9 @@ end -- TODO: This is temporarily called by constructor. function Hero.load () - if Hero.portrait_sprite == nil then - Hero.portrait_sprite = love.graphics.newImage("assets/portraits.png") - Hero.portrait_frame = love.graphics.newImage("assets/menu.png") + if Hero.IMAGE_PORTRAITS == nil then + Hero.IMAGE_PORTRAITS = love.graphics.newImage("assets/portraits.png") + Hero.IMAGE_FRAME = love.graphics.newImage("assets/menu.png") end end @@ -180,8 +180,8 @@ function Hero:drawHUD (x,y,scale,elevation) -- hud displays only if player is alive 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) + love.graphics.draw(self.IMAGE_FRAME, self.portrait_box, (x)*scale, (y)*scale, 0, scale, scale) + love.graphics.draw(self.IMAGE_PORTRAITS, self.portrait_sheet[self.name], (x+2)*scale, (y+3)*scale, 0, scale, scale) local dy = 30 * elevation love.graphics.setFont(Font) love.graphics.print((self.combo).."%",(x+2)*scale,(y-3+dy)*scale,0,scale,scale) -- cgit v1.1 From 57d6d2def0674c135a659740265ec75cdebae6fa Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 17 Jul 2017 10:39:09 +0200 Subject: Changed order of properties in Hero's constructor --- not/Hero.lua | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'not/Hero.lua') diff --git a/not/Hero.lua b/not/Hero.lua index 6eb3978..d92d003 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -37,17 +37,18 @@ function Hero:new (name, x, y, world) -- General self.world = world self.name = name - self.lives = 3 self.angle = 0 self.facing = 1 + -- Status self.combo = 0 - self.punchCooldown = 0 - self.spawntimer = 2 - self.isAlive = true + self.lives = 3 self.inAir = true - self.isJumping = false - self.isWalking = false self.salto = false + self.isAlive = true + self.isWalking = false + self.isJumping = false + self.spawntimer = 2 + self.punchCooldown = 0 self:setAnimationsList(require("config.animations.hero")) -- Post-creation self:createEffect("respawn") -- cgit v1.1 From fc43bcb81b5dbfc8ef8dd164193014aa0cf43c9f Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 17 Jul 2017 12:53:00 +0200 Subject: Trail now works mostly as intended --- not/Hero.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'not/Hero.lua') diff --git a/not/Hero.lua b/not/Hero.lua index d92d003..014eeb2 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -44,6 +44,7 @@ function Hero:new (name, x, y, world) self.lives = 3 self.inAir = true self.salto = false + self.smoke = false self.isAlive = true self.isWalking = false self.isJumping = false @@ -105,7 +106,8 @@ function Hero:update (dt) end -- Trail spawner - if self.combo > 100 and self.punchCooldown > 0 then + -- TODO: lower the frequency of spawning - currently it is each frame. + if self.smoke and self.inAir then local dx, dy = love.math.random(-5, 5), love.math.random(-5, 5) self:createEffect("trail", dx, dy) end @@ -263,6 +265,9 @@ function Hero:damage (direction) self.combo = math.min(999, self.combo + 10) self.punchCooldown = 0.08 + self.combo*0.0006 self:playSound(2) + if self.combo > 80 then + self.smoke = true + end end -- DIE -- cgit v1.1 From 7ad366dcec68c703499e3f6f72b345d1adeac1da Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 17 Jul 2017 14:15:36 +0200 Subject: Moved landing method to Hero from World --- not/Hero.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'not/Hero.lua') diff --git a/not/Hero.lua b/not/Hero.lua index 014eeb2..ff07c36 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -219,6 +219,15 @@ function Hero:createEffect (name, dx, dy) self.world:createEffect(name, x, y) end +-- Called by World when Hero starts contact with Platform (lands). +function Hero:land () + self.inAir = false + self.jumpCounter = 2 + self.salto = false + self.smoke = false + self:createEffect("land") +end + -- Creates temporary fixture for hero's body that acts as sensor. -- direction: ("left", "right", "up", "down") -- Sensor fixture is deleted after time set in UserData[1]; deleted by `not.Hero.update`. -- cgit v1.1 From b6aad58259b1e71913280d30e2c9dbf4ecf264c3 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 18 Jul 2017 06:39:05 +0200 Subject: Removed obsolete punchdir and reworked physical animations on punches --- not/Hero.lua | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'not/Hero.lua') diff --git a/not/Hero.lua b/not/Hero.lua index ff07c36..d9b0636 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -3,8 +3,6 @@ -- Collision category: [2] Hero = require "not.PhysicalBody":extends() --- Combat -Hero.punchdir = 0 -- a really bad thing -- Movement Hero.jumpTimer = 0.16 Hero.jumpCounter = 2 @@ -127,17 +125,14 @@ function Hero:update (dt) end -- Stop vertical - local c,a = self.current, self.animations - if (c == a.attack_up or c == a.attack_down or c == a.attack) and self.frame < c.frames then - if self.punchdir == 0 then - self:setLinearVelocity(0,0) - else - self:setLinearVelocity(38*self.facing,0) + local currentAnimation = self:getAnimation() + if self.frame < currentAnimation.frames then + if currentAnimation == self.animations.attack_up or currentAnimation == self.animations.attack_down then + self:setLinearVelocity(0, 0) + end + if currentAnimation == self.animations.attack then + self:setLinearVelocity(38*self.facing, 0) end - end - - if self.punchCooldown <= 0 and self.punchdir == 1 then - self.punchdir = 0 end end -- cgit v1.1 From 0774fe93cb125e2b3d37904b2c32f9e490d432f7 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 18 Jul 2017 06:44:16 +0200 Subject: Renamed few more poperties in Hero which are used the same way as statics --- not/Hero.lua | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'not/Hero.lua') diff --git a/not/Hero.lua b/not/Hero.lua index d9b0636..729826d 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -3,14 +3,13 @@ -- Collision category: [2] Hero = require "not.PhysicalBody":extends() --- Movement +-- Few are left... Hero.jumpTimer = 0.16 Hero.jumpCounter = 2 --- Statics -Hero.portrait_sheet = getNautsIconsList() -Hero.portrait_box = love.graphics.newQuad(0, 15, 32,32, 80,130) Hero.sfx = require "config.sounds" +Hero.QUAD_PORTRAITS = getNautsIconsList() +Hero.QUAD_FRAME = love.graphics.newQuad(0, 15, 32,32, 80,130) Hero.IMAGE_PORTRAITS = nil Hero.IMAGE_FRAME = nil Hero.MAX_VELOCITY = 105 @@ -178,8 +177,8 @@ function Hero:drawHUD (x,y,scale,elevation) -- hud displays only if player is alive if self.isAlive then love.graphics.setColor(255,255,255,255) - love.graphics.draw(self.IMAGE_FRAME, self.portrait_box, (x)*scale, (y)*scale, 0, scale, scale) - love.graphics.draw(self.IMAGE_PORTRAITS, self.portrait_sheet[self.name], (x+2)*scale, (y+3)*scale, 0, scale, scale) + love.graphics.draw(self.IMAGE_FRAME, self.QUAD_FRAME, (x)*scale, (y)*scale, 0, scale, scale) + love.graphics.draw(self.IMAGE_PORTRAITS, self.QUAD_PORTRAITS[self.name], (x+2)*scale, (y+3)*scale, 0, scale, scale) local dy = 30 * elevation love.graphics.setFont(Font) love.graphics.print((self.combo).."%",(x+2)*scale,(y-3+dy)*scale,0,scale,scale) -- cgit v1.1 From c55bf67aa348c7f16e5fccf2f2153bc90910934c Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 18 Jul 2017 06:54:35 +0200 Subject: Respawning now resets salto and smoke flags in Hero's behaviour --- not/Hero.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'not/Hero.lua') diff --git a/not/Hero.lua b/not/Hero.lua index 729826d..1c15588 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -287,6 +287,8 @@ end -- And then respawn. Like Jon Snow. function Hero:respawn () self.isAlive = true + self.salto = false + self.smoke = false self:setLinearVelocity(0,0) self:setPosition(self.world:getSpawnPosition()) -- TODO: I'm not convinced about getting new position like this. self:setBodyActive(true) -- cgit v1.1 From 9b75ea38f0194dfffc89c0144c1ab0efb8b4f392 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 18 Jul 2017 16:54:14 +0200 Subject: Resized 16px effects frames to 24px --- not/Hero.lua | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'not/Hero.lua') diff --git a/not/Hero.lua b/not/Hero.lua index 1c15588..13ab3dd 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -200,10 +200,7 @@ end -- Spawn `Effect` relative to `Hero` function Hero:createEffect (name, dx, dy) - local x, y = self.body:getX()-8, self.body:getY()-8 -- 16px effect: -7 -7 - if not (name == "trail") and not (name == "hit") then - x, y = x-4, y-7 -- 24px effect: -12 -15 - end + local x, y = self.body:getX()-12, self.body:getY()-15 if dx then x = x + dx end -- cgit v1.1 From 657eb912abc89a71d16ea60516458ad6c72f6a4e Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 19 Jul 2017 14:50:25 +0200 Subject: Initial clash No additional effect, rusty mechanics for now --- not/Hero.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'not/Hero.lua') diff --git a/not/Hero.lua b/not/Hero.lua index 13ab3dd..5c3d9f4 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -234,7 +234,7 @@ function Hero:punch (direction) local fixture = self:addFixture(shape, 0) fixture:setSensor(true) fixture:setCategory(3) - fixture:setMask(1,3) + fixture:setMask(1) fixture:setGroupIndex(self.group) fixture:setUserData({Hero.PUNCH_FIXTURE_LIFETIME, direction}) self:playSound(4) -- cgit v1.1 From cc352d320bf87f2d9e4ca77497fb452958bab231 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 20 Jul 2017 16:18:30 +0200 Subject: Added initial name tags above Heroes --- not/Hero.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'not/Hero.lua') diff --git a/not/Hero.lua b/not/Hero.lua index 5c3d9f4..e8fa206 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -169,6 +169,9 @@ end function Hero:draw (offset_x, offset_y, scale, debug) if not self.isAlive then return end Hero.__super.draw(self, offset_x, offset_y, scale, debug) + love.graphics.setFont(Font) + local x,y = self:getPosition() + love.graphics.printf(string.format("Player %d", math.abs(self.group)), (math.floor(x)+offset_x)*scale, (math.floor(y)+offset_y-26)*scale,100,'center',0,scale,scale,50,0) end -- Draw HUD of `Hero` -- cgit v1.1 From 02aba07e03465205b45c41df7aec6894d4e89909 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 20 Jul 2017 19:51:30 +0200 Subject: Moved name-tag drawing to separate function; moved up overall in drawing functions --- not/Hero.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'not/Hero.lua') diff --git a/not/Hero.lua b/not/Hero.lua index e8fa206..039aeb8 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -169,8 +169,11 @@ end function Hero:draw (offset_x, offset_y, scale, debug) if not self.isAlive then return end Hero.__super.draw(self, offset_x, offset_y, scale, debug) - love.graphics.setFont(Font) +end + +function Hero:drawTag (offset_x, offset_y, scale) local x,y = self:getPosition() + love.graphics.setFont(Font) love.graphics.printf(string.format("Player %d", math.abs(self.group)), (math.floor(x)+offset_x)*scale, (math.floor(y)+offset_y-26)*scale,100,'center',0,scale,scale,50,0) end -- cgit v1.1