plane: crash when flipping on ground
This commit is contained in:
parent
9611db61c8
commit
cdc6979062
3 changed files with 40 additions and 15 deletions
|
@ -67,6 +67,11 @@ PhysicsEntity = Class{
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
-- Reimplement
|
||||||
|
noLongerHitBy = function(self, by)
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
-- Apply linear impulse with given direction and power
|
-- Apply linear impulse with given direction and power
|
||||||
punch = function(self, angle, power)
|
punch = function(self, angle, power)
|
||||||
local forces = rad_dist_to_xy(angle, power)
|
local forces = rad_dist_to_xy(angle, power)
|
||||||
|
|
|
@ -117,6 +117,8 @@ Plane = Class{
|
||||||
kbdShooting = false,
|
kbdShooting = false,
|
||||||
joyShooting = false,
|
joyShooting = false,
|
||||||
|
|
||||||
|
contactingGround = false,
|
||||||
|
|
||||||
init = function(self, x, y, xDir, yDir, r, g, b, level)
|
init = function(self, x, y, xDir, yDir, r, g, b, level)
|
||||||
local density = 50
|
local density = 50
|
||||||
PhysicsEntity.init(self, x, y, level, "dynamic", 0.2)
|
PhysicsEntity.init(self, x, y, level, "dynamic", 0.2)
|
||||||
|
@ -237,11 +239,19 @@ Plane = Class{
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
noLongerHitBy = function(self, by)
|
||||||
|
if by:isinstance(Ground) then
|
||||||
|
self.contactingGround = false
|
||||||
|
end
|
||||||
|
end;
|
||||||
|
|
||||||
wasHitBy = function(self, by)
|
wasHitBy = function(self, by)
|
||||||
if by:isinstance(Ground) then
|
if by:isinstance(Ground) then
|
||||||
local angle = normalizeAngle(self.body:getAngle())
|
local angle = normalizeAngle(self.body:getAngle())
|
||||||
if (self.goingRight and (angle > math.pi * 2 - math.pi / 4 or angle < math.pi / 4)) or
|
self.contactingGround = true
|
||||||
(not self.goingRight and (angle > math.pi - math.pi / 4 and angle < math.pi + math.pi / 4)) then
|
if self.flipping == nil and
|
||||||
|
((self.goingRight and (angle > math.pi * 2 - math.pi / 4 or angle < math.pi / 4)) or
|
||||||
|
(not self.goingRight and (angle > math.pi - math.pi / 4 and angle < math.pi + math.pi / 4))) then
|
||||||
-- don't die this time.
|
-- don't die this time.
|
||||||
else
|
else
|
||||||
self:receiveDamage(1000)
|
self:receiveDamage(1000)
|
||||||
|
@ -443,20 +453,24 @@ Plane = Class{
|
||||||
self.motorSound:setPitch(motorEffort * self.motorPower / ENGINE_MAX + 0.5)
|
self.motorSound:setPitch(motorEffort * self.motorPower / ENGINE_MAX + 0.5)
|
||||||
|
|
||||||
if self.flipping ~= nil then
|
if self.flipping ~= nil then
|
||||||
self.flipping = self.flipping + flipping_speed * dt * fwd_vel
|
if self.contactingGround then
|
||||||
local finished = self.flipping <= -1.0 or self.flipping >= 1.0
|
self:die()
|
||||||
if finished then
|
|
||||||
self.flipping = 1.0
|
|
||||||
end
|
|
||||||
if self.goingRight then
|
|
||||||
self.orientationAngle = 180 * self.flipping
|
|
||||||
else
|
else
|
||||||
self.orientationAngle = 180 + 180 * self.flipping
|
self.flipping = self.flipping + flipping_speed * dt * fwd_vel
|
||||||
end
|
local finished = self.flipping <= -1.0 or self.flipping >= 1.0
|
||||||
self.orientationAngle = self.orientationAngle % 360
|
if finished then
|
||||||
if finished then
|
self.flipping = 1.0
|
||||||
self.goingRight = not self.goingRight
|
end
|
||||||
self.flipping = nil
|
if self.goingRight then
|
||||||
|
self.orientationAngle = 180 * self.flipping
|
||||||
|
else
|
||||||
|
self.orientationAngle = 180 + 180 * self.flipping
|
||||||
|
end
|
||||||
|
self.orientationAngle = self.orientationAngle % 360
|
||||||
|
if finished then
|
||||||
|
self.goingRight = not self.goingRight
|
||||||
|
self.flipping = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
|
|
|
@ -252,7 +252,13 @@ function begin_contact(a, b, coll)
|
||||||
end
|
end
|
||||||
|
|
||||||
function end_contact(a, b, coll)
|
function end_contact(a, b, coll)
|
||||||
|
local aObj = a:getUserData()
|
||||||
|
local bObj = b:getUserData()
|
||||||
|
|
||||||
|
if aObj ~= nil and bObj ~= nil then
|
||||||
|
aObj:noLongerHitBy(bObj)
|
||||||
|
bObj:noLongerHitBy(aObj)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function pre_solve(a, b, coll)
|
function pre_solve(a, b, coll)
|
||||||
|
|
Loading…
Reference in a new issue