plane: added ability to land on ground

This commit is contained in:
Erkki Seppälä 2014-10-20 22:55:32 +03:00
parent 38d80b9dc1
commit 65709f0ae0
3 changed files with 17 additions and 5 deletions

View file

@ -10,5 +10,7 @@ Ground = Class{
(love.window.getWidth() - 1600) / 2, love.window.getHeight(),
level, "static",
0, 1600, 20, 0, groundImg)
self.fixture:setRestitution(0)
self.fixture:setFriction(0.5)
end;
}

View file

@ -3,6 +3,7 @@ require 'entities/physicsentity'
require 'settings'
require 'entities/debug'
require 'entities/animation'
require 'entities/ground'
Matrix = require 'matrix'
VectorLight = require 'hump/vector-light'
require 'utils'
@ -112,7 +113,7 @@ Plane = Class{
-- self.body:setMassData(self.xsize / 2, 0, 430, 158194)
self.body:setMassData(7, 5, 800, 558194.140625)
self.body:setAngularDamping(0.1)
self.fixture:setFriction(0)
self.fixture:setFriction(0.5)
self.angle = 0
--x 16 y 17.200000762939 mass 3520 inertia 1942476.875
@ -181,8 +182,19 @@ Plane = Class{
end;
wasHitBy = function(self, by)
local i = love.math.random(#CLANG_SFX)
CLANG_SFX[i]:play()
if by:isinstance(Ground) then
local angle = self.body:getAngle()
if (not goingRight and (angle > -math.pi / 4 and angle < math.pi / 4)) or
(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)
self:getOwner():addScore(SUICIDE_SCORE)
end
elseif not by:isinstance(Ground) then
local i = love.math.random(#CLANG_SFX)
CLANG_SFX[i]:play()
end
end;
update = function(self, dt)

View file

@ -210,8 +210,6 @@ function begin_contact(a, b, coll)
elseif plane then
if other:getOwner() == nil then
-- Collision with ground or other plane
plane:receiveDamage(1000)
plane:getOwner():addScore(SUICIDE_SCORE)
elseif other:getOwner().id ~= plane.id then
for key, gun in pairs(GUNS) do
if other:isinstance(gun['projectile']) and plane.health > 0 then