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;
|
||||
|
||||
|
||||
-- Reimplement
|
||||
noLongerHitBy = function(self, by)
|
||||
end;
|
||||
|
||||
|
||||
-- Apply linear impulse with given direction and power
|
||||
punch = function(self, angle, power)
|
||||
local forces = rad_dist_to_xy(angle, power)
|
||||
|
|
|
@ -117,6 +117,8 @@ Plane = Class{
|
|||
kbdShooting = false,
|
||||
joyShooting = false,
|
||||
|
||||
contactingGround = false,
|
||||
|
||||
init = function(self, x, y, xDir, yDir, r, g, b, level)
|
||||
local density = 50
|
||||
PhysicsEntity.init(self, x, y, level, "dynamic", 0.2)
|
||||
|
@ -237,11 +239,19 @@ Plane = Class{
|
|||
end
|
||||
end;
|
||||
|
||||
noLongerHitBy = function(self, by)
|
||||
if by:isinstance(Ground) then
|
||||
self.contactingGround = false
|
||||
end
|
||||
end;
|
||||
|
||||
wasHitBy = function(self, by)
|
||||
if by:isinstance(Ground) then
|
||||
local angle = normalizeAngle(self.body:getAngle())
|
||||
if (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
|
||||
self.contactingGround = true
|
||||
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.
|
||||
else
|
||||
self:receiveDamage(1000)
|
||||
|
@ -443,6 +453,9 @@ Plane = Class{
|
|||
self.motorSound:setPitch(motorEffort * self.motorPower / ENGINE_MAX + 0.5)
|
||||
|
||||
if self.flipping ~= nil then
|
||||
if self.contactingGround then
|
||||
self:die()
|
||||
else
|
||||
self.flipping = self.flipping + flipping_speed * dt * fwd_vel
|
||||
local finished = self.flipping <= -1.0 or self.flipping >= 1.0
|
||||
if finished then
|
||||
|
@ -459,6 +472,7 @@ Plane = Class{
|
|||
self.flipping = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end;
|
||||
|
||||
draw = function(self)
|
||||
|
|
|
@ -252,7 +252,13 @@ function begin_contact(a, b, coll)
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
function pre_solve(a, b, coll)
|
||||
|
|
Loading…
Reference in a new issue