Merge branch 'simpler-gravity' of game-projects/gamecore into master
This commit is contained in:
commit
81c7dc7cd4
4 changed files with 36 additions and 49 deletions
|
@ -29,10 +29,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
- **world2D:** Make the hitbox an object, owned by the actor
|
||||
|
||||
- **actor:** Rename all function related to YGravity to just \*Gravity
|
||||
|
||||
|
||||
### Fixed
|
||||
|
||||
- **world:** Remove a forgotten camera debug function
|
||||
|
||||
### Removed
|
||||
|
||||
- **actor:** Remove all function related to XGravity
|
||||
|
||||
## 0.5.1 - 2019-06-21
|
||||
|
||||
### Fixed
|
||||
|
|
|
@ -5,7 +5,7 @@ function Player:new(world, x, y, id)
|
|||
Player.super.new(self, world, "player", x, y, 16, 24, true)
|
||||
self:setSprite("player", 8, 12)
|
||||
self:cloneSprite()
|
||||
self:setYGravity(480)
|
||||
self:setGravity(480)
|
||||
|
||||
self.isPunching = false
|
||||
self.direction = 1
|
||||
|
|
|
@ -98,32 +98,6 @@ function Actor2D:changeSpeedToCollisionNormal(nx, ny)
|
|||
self.xsp, self.ysp = xsp, ysp
|
||||
end
|
||||
|
||||
function Actor2D:checkGroundX()
|
||||
local dx, dy = self.x + utils.math.sign(self.xgrav), self.y
|
||||
local newx, newy, cols, colNumber = self:checkCollision(dx, dy)
|
||||
|
||||
for i, col in ipairs(cols) do
|
||||
if (col.type == "touch") or (col.type == "bounce") or (col.type == "slide") then
|
||||
if not (self.ygrav == 0) then
|
||||
if col.normal.x ~= utils.math.sign(self.xgrav) then self.onGround = true end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Actor2D:checkGroundY()
|
||||
local dx, dy = self.x, self.y + utils.math.sign(self.ygrav)
|
||||
local newx, newy, cols, colNumber = self:checkCollision(dx, dy)
|
||||
|
||||
for i, col in ipairs(cols) do
|
||||
if (col.type == "touch") or (col.type == "bounce") or (col.type == "slide") then
|
||||
if not (self.ygrav == 0) then
|
||||
if col.normal.y ~= utils.math.sign(self.ygrav) then self.onGround = true end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Actor2D:move(dx, dy)
|
||||
local cols, colNumber = {}, 0
|
||||
if (self.isDestroyed == false) then
|
||||
|
@ -142,37 +116,44 @@ function Actor2D:checkCollision(dx, dy)
|
|||
end
|
||||
|
||||
function Actor2D:initGravity()
|
||||
local xgrav, ygrav
|
||||
|
||||
if (self.world.gravity.isDefault) then
|
||||
self.xgrav = self.world.gravity.xgrav
|
||||
self.ygrav = self.world.gravity.ygrav
|
||||
self.grav = self.world.gravity.grav
|
||||
else
|
||||
self.xgrav = 0
|
||||
self.ygrav = 0
|
||||
self.grav = 0
|
||||
end
|
||||
|
||||
self.onGround = false
|
||||
end
|
||||
|
||||
function Actor2D:setXGravity(grav)
|
||||
self.xgrav = grav
|
||||
end
|
||||
-- GRAVITY SYSTEM FUNCTIONS
|
||||
-- All functions related to gravity
|
||||
|
||||
function Actor2D:setYGravity(grav)
|
||||
self.ygrav = grav
|
||||
function Actor2D:setGravity(grav)
|
||||
-- It's basically now a function with two roles at once :
|
||||
-- - activate the gravity
|
||||
-- - use the gravity value the dev want
|
||||
|
||||
self.grav = grav or self.world.gravity.grav
|
||||
end
|
||||
|
||||
function Actor2D:applyGravity(dt)
|
||||
self.xsp = self.xsp + self.xgrav * dt
|
||||
self.ysp = self.ysp + self.ygrav * dt
|
||||
self.ysp = self.ysp + self.grav * dt
|
||||
|
||||
if utils.math.sign(self.ysp) == utils.math.sign(self.ygrav) then
|
||||
self:checkGroundY( )
|
||||
if utils.math.sign(self.ysp) == utils.math.sign(self.grav) then
|
||||
self:checkGround( )
|
||||
end
|
||||
end
|
||||
|
||||
if utils.math.sign(self.xsp) == utils.math.sign(self.xgrav) then
|
||||
self:checkGroundX( )
|
||||
function Actor2D:checkGround()
|
||||
local dx, dy = self.x, self.y + utils.math.sign(self.grav)
|
||||
local newx, newy, cols, colNumber = self:checkCollision(dx, dy)
|
||||
|
||||
for i, col in ipairs(cols) do
|
||||
if (col.type == "touch") or (col.type == "bounce") or (col.type == "slide") then
|
||||
if not (self.grav == 0) then
|
||||
if col.normal.y ~= utils.math.sign(self.grav) then self.onGround = true end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -67,13 +67,12 @@ function BaseWorld:initMap(mapfile)
|
|||
self.mapfile = mapfile
|
||||
end
|
||||
|
||||
function BaseWorld:setGravity(xgrav, ygrav, isDefault)
|
||||
local xgrav = xgrav or 0
|
||||
local ygrav = ygrav or 0
|
||||
local isDefault = isDefault or 0
|
||||
function BaseWorld:setGravity(grav, isDefault)
|
||||
local grav = grav or 0
|
||||
local isDefault = isDefault or false
|
||||
|
||||
self.gravity = {}
|
||||
self.gravity.xgrav, self.gravity.ygrav = xgrav, ygrav
|
||||
self.gravity.grav = grav
|
||||
self.gravity.isDefault = isDefault
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue