From 340a3a4b92de5495b47e8e1e102178edfd97514f Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 19 Mar 2017 00:21:02 +0100 Subject: Night commit, added PhysicalBody, newImage to sprite --- not/PhysicalBody.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 not/PhysicalBody.lua (limited to 'not/PhysicalBody.lua') diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua new file mode 100644 index 0000000..6e6a8a6 --- /dev/null +++ b/not/PhysicalBody.lua @@ -0,0 +1,16 @@ +--- `PhysicalBody` +-- Abstract class for drawable body existing in Box2D's physical world. +PhysicalBody = { + body =--[[love.physics.newBody]]nil, +} + +-- `PhysicalBody` is a child of `Sprite`. +require "not.Sprite" +PhysicalBody.__index = PhysicalBody +setmetatable(PhysicalBody, Sprite) + +-- Constructor of `PhysicalBody`. +function PhysicalBody:new (world, x, y, imagePath) + local o = Sprite:new(imagePath) + return o +end \ No newline at end of file -- cgit v1.1 From b262cb3eec1a797832d168f9e6d144468fb48c1d Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 19 Mar 2017 01:35:43 +0100 Subject: Initializers in PhysicalBody, Hero and Sprite --- not/PhysicalBody.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'not/PhysicalBody.lua') diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua index 6e6a8a6..1f91faf 100644 --- a/not/PhysicalBody.lua +++ b/not/PhysicalBody.lua @@ -11,6 +11,12 @@ setmetatable(PhysicalBody, Sprite) -- Constructor of `PhysicalBody`. function PhysicalBody:new (world, x, y, imagePath) - local o = Sprite:new(imagePath) + local o = setmetatable({}, self) + o:init(world, x, y, imagePath) return o +end + +-- Initializator of `PhysicalBody`. +function PhysicalBody:init (world, x, y, imagePath) + Sprite.init(self, imagePath) end \ No newline at end of file -- cgit v1.1 From 4652d69cc88e3d0137cac118344d21853c6a7605 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 19 Mar 2017 02:45:17 +0100 Subject: Small changes, comments --- not/PhysicalBody.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'not/PhysicalBody.lua') diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua index 1f91faf..e726ea3 100644 --- a/not/PhysicalBody.lua +++ b/not/PhysicalBody.lua @@ -19,4 +19,4 @@ end -- Initializator of `PhysicalBody`. function PhysicalBody:init (world, x, y, imagePath) Sprite.init(self, imagePath) -end \ No newline at end of file +end -- cgit v1.1 From b10988b7e8a0c52148b1d3828c3739fb0eeff24e Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 19 Mar 2017 03:09:36 +0100 Subject: No constructors for abstracts --- not/PhysicalBody.lua | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'not/PhysicalBody.lua') diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua index e726ea3..52e9357 100644 --- a/not/PhysicalBody.lua +++ b/not/PhysicalBody.lua @@ -1,5 +1,5 @@ --- `PhysicalBody` --- Abstract class for drawable body existing in Box2D's physical world. +-- Abstract class for drawable entity existing in `not.World`. PhysicalBody = { body =--[[love.physics.newBody]]nil, } @@ -9,14 +9,25 @@ require "not.Sprite" PhysicalBody.__index = PhysicalBody setmetatable(PhysicalBody, Sprite) --- Constructor of `PhysicalBody`. +--[[ Constructor of `PhysicalBody`. function PhysicalBody:new (world, x, y, imagePath) local o = setmetatable({}, self) o:init(world, x, y, imagePath) return o end +]] -- Initializator of `PhysicalBody`. function PhysicalBody:init (world, x, y, imagePath) Sprite.init(self, imagePath) end + +-- Update of `PhysicalBody`. +function PhysicalBody:update (dt) + Sprite.update(self, dt) +end + +-- Draw of `PhysicalBody`. +function PhysicalBody:draw (offset_x, offset_y, scale, debug) + -- TODO: Move debug part here from `not.Hero.draw`. +end -- cgit v1.1 From cca4d9c1bf4033c79e4bd61a257c6ea02557524c Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 19 Mar 2017 04:19:59 +0100 Subject: Moving draw away to abstract classes --- not/PhysicalBody.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'not/PhysicalBody.lua') diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua index 52e9357..bbea3ac 100644 --- a/not/PhysicalBody.lua +++ b/not/PhysicalBody.lua @@ -30,4 +30,5 @@ end -- Draw of `PhysicalBody`. function PhysicalBody:draw (offset_x, offset_y, scale, debug) -- TODO: Move debug part here from `not.Hero.draw`. + Sprite.draw(self, offset_x, offset_y, scale) end -- cgit v1.1 From bda0f791d64178904e655f74efce24a2f3fc2f96 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 3 Apr 2017 17:20:55 +0200 Subject: Position, Fixture, Body init moved from Hero to PhysicalBody --- not/PhysicalBody.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'not/PhysicalBody.lua') diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua index bbea3ac..54d334f 100644 --- a/not/PhysicalBody.lua +++ b/not/PhysicalBody.lua @@ -20,6 +20,31 @@ end -- Initializator of `PhysicalBody`. function PhysicalBody:init (world, x, y, imagePath) Sprite.init(self, imagePath) + self.body = love.physics.newBody(world.world, x, y) +end + +-- Add new fixture to body. +function PhysicalBody:addFixture (shape, density) + local shape = love.physics.newPolygonShape(shape) + local fixture = love.physics.newFixture(self.body, shape, density) + return fixture +end + +-- Position-related methods. +function PhysicalBody:getPosition () + return self.body:getPosition() +end +function PhysicalBody:setPosition (x, y) + self.body:setPosition(x, y) +end + +-- Various setters from Body. +-- type: BodyType ("static", "dynamic", "kinematic") +function PhysicalBody:setBodyType (type) + self.body:setType(type) +end +function PhysicalBody:setBodyFixedRotation (bool) + self.body:setFixedRotation(bool) end -- Update of `PhysicalBody`. -- cgit v1.1 From 9af03e90acde019820021d0bc2fe546d10c25ed4 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 3 Apr 2017 17:34:03 +0200 Subject: Setting group differently, moved debug draw to PhysicalBody from Hero --- not/PhysicalBody.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'not/PhysicalBody.lua') diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua index 54d334f..24e87c8 100644 --- a/not/PhysicalBody.lua +++ b/not/PhysicalBody.lua @@ -54,6 +54,16 @@ end -- Draw of `PhysicalBody`. function PhysicalBody:draw (offset_x, offset_y, scale, debug) - -- TODO: Move debug part here from `not.Hero.draw`. Sprite.draw(self, offset_x, offset_y, scale) + if debug then + for _,fixture in pairs(self.body:getFixtureList()) do + if fixture:getCategory() == 2 then + love.graphics.setColor(137, 255, 0, 120) + else + love.graphics.setColor(137, 0, 255, 40) + end + -- TODO: `world` is not a member of `PhysicalBody` or its instance normally. + love.graphics.polygon("fill", self.world.camera:translatePoints(self.body:getWorldPoints(fixture:getShape():getPoints()))) + end + end end -- cgit v1.1 From 8fa7ec07a1a9b4307ed9b221770c91a242cd68d9 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 3 Apr 2017 18:16:23 +0200 Subject: Platform is now child of PhysicalBody --- not/PhysicalBody.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'not/PhysicalBody.lua') diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua index 24e87c8..7c05262 100644 --- a/not/PhysicalBody.lua +++ b/not/PhysicalBody.lua @@ -57,9 +57,14 @@ function PhysicalBody:draw (offset_x, offset_y, scale, debug) Sprite.draw(self, offset_x, offset_y, scale) if debug then for _,fixture in pairs(self.body:getFixtureList()) do - if fixture:getCategory() == 2 then + local category = fixture:getCategory() + if category == 1 then + love.graphics.setColor(255, 69, 0, 140) + end + if category == 2 then love.graphics.setColor(137, 255, 0, 120) - else + end + if category == 3 then love.graphics.setColor(137, 0, 255, 40) end -- TODO: `world` is not a member of `PhysicalBody` or its instance normally. -- cgit v1.1 From b4389dfb590862b50cc6c9ce59d3fcef9bd046b3 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 3 Apr 2017 20:11:21 +0200 Subject: World comments, other comments, todos --- not/PhysicalBody.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'not/PhysicalBody.lua') diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua index 7c05262..7b774f2 100644 --- a/not/PhysicalBody.lua +++ b/not/PhysicalBody.lua @@ -17,7 +17,7 @@ function PhysicalBody:new (world, x, y, imagePath) end ]] --- Initializator of `PhysicalBody`. +-- Initializer of `PhysicalBody`. function PhysicalBody:init (world, x, y, imagePath) Sprite.init(self, imagePath) self.body = love.physics.newBody(world.world, x, y) -- cgit v1.1 From be64dffe9e3354fda6220a1b25251e1664cd71cc Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 3 Apr 2017 21:50:40 +0200 Subject: Testing if body isn't destroyed in PhysicalBody's update --- not/PhysicalBody.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'not/PhysicalBody.lua') diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua index 7b774f2..a7abcc0 100644 --- a/not/PhysicalBody.lua +++ b/not/PhysicalBody.lua @@ -50,6 +50,7 @@ end -- Update of `PhysicalBody`. function PhysicalBody:update (dt) Sprite.update(self, dt) + if self.body:isDestroyed() then return end end -- Draw of `PhysicalBody`. -- cgit v1.1 From 603fac3ce18ff7df7b8d2f74d5e57cc728c0abc2 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 3 Apr 2017 22:07:32 +0200 Subject: Created physics functions to influence PhysicalBody; changed Hero to use them. Comments. --- not/PhysicalBody.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'not/PhysicalBody.lua') diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua index a7abcc0..a9ac63b 100644 --- a/not/PhysicalBody.lua +++ b/not/PhysicalBody.lua @@ -38,6 +38,14 @@ function PhysicalBody:setPosition (x, y) self.body:setPosition(x, y) end +-- Velocity-related methods. +function PhysicalBody:setLinearVelocity (x, y) + self.body:setLinearVelocity(x, y) +end +function PhysicalBody:getLinearVelocity () + return self.body:getLinearVelocity() +end + -- Various setters from Body. -- type: BodyType ("static", "dynamic", "kinematic") function PhysicalBody:setBodyType (type) @@ -46,6 +54,17 @@ end function PhysicalBody:setBodyFixedRotation (bool) self.body:setFixedRotation(bool) end +function PhysicalBody:setBodyActive (bool) + self.body:setActive(bool) +end + +-- Physical influence methods. +function PhysicalBody:applyLinearImpulse (x, y) + self.body:applyLinearImpulse(x, y) +end +function PhysicalBody:applyForce (x, y) + self.body:applyForce(x, y) +end -- Update of `PhysicalBody`. function PhysicalBody:update (dt) -- cgit v1.1 From 7a560cee7e7f0620656a63e91f05fbe898919246 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 4 Apr 2017 13:11:33 +0200 Subject: Kek, never commit late night. Fail statement back to not.Hero.update --- not/PhysicalBody.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'not/PhysicalBody.lua') diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua index a9ac63b..e9625fa 100644 --- a/not/PhysicalBody.lua +++ b/not/PhysicalBody.lua @@ -69,7 +69,6 @@ end -- Update of `PhysicalBody`. function PhysicalBody:update (dt) Sprite.update(self, dt) - if self.body:isDestroyed() then return end end -- Draw of `PhysicalBody`. -- cgit v1.1