From 65709f0ae087e2ec8a2ac855d1e90cfc8456ae1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erkki=20Sepp=C3=A4l=C3=A4?= Date: Mon, 20 Oct 2014 22:55:32 +0300 Subject: [PATCH] plane: added ability to land on ground --- entities/ground.lua | 2 ++ entities/plane.lua | 18 +++++++++++++++--- level_state.lua | 2 -- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/entities/ground.lua b/entities/ground.lua index c1c8dbf..dadf633 100644 --- a/entities/ground.lua +++ b/entities/ground.lua @@ -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; } diff --git a/entities/plane.lua b/entities/plane.lua index 8204156..2c93a87 100644 --- a/entities/plane.lua +++ b/entities/plane.lua @@ -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) diff --git a/level_state.lua b/level_state.lua index cf5d45d..4b9e847 100644 --- a/level_state.lua +++ b/level_state.lua @@ -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