From 4ebbfa3887ee82febd5ea732b94ca1d8d05d249d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erkki=20Sepp=C3=A4l=C3=A4?= Date: Tue, 21 Oct 2014 21:02:03 +0300 Subject: [PATCH] plane: fixed landing for both players --- entities/plane.lua | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/entities/plane.lua b/entities/plane.lua index 2b7b3bc..2577281 100644 --- a/entities/plane.lua +++ b/entities/plane.lua @@ -10,6 +10,19 @@ VectorLight = require 'hump/vector-light' require 'utils' require 'machinegun' +-- normalizes angle to be between [0 .. 2 pi[ +local normalizeAngle = function(angle) + if angle < 0 then + angle = -angle + angle = angle - 2 * math.pi * math.floor(angle / (2 * math.pi)) + angle = math.pi * 2 - angle + else + angle = angle - 2 * math.pi * math.floor(angle / (2 * math.pi)) + end + return angle +end + + local CLANG_SFX = { love.audio.newSource("resources/audio/clangs/cast iron clangs - Marker #1.wav"), love.audio.newSource("resources/audio/clangs/cast iron clangs - Marker #2.wav"), @@ -199,9 +212,9 @@ Plane = Class{ wasHitBy = function(self, by) 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 + 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 -- don't die this time. else self:receiveDamage(1000)