From b1002378c59e5941340f92ce8bde5bfd55160952 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erkki=20Sepp=C3=A4l=C3=A4?= Date: Thu, 23 Oct 2014 09:56:59 +0300 Subject: [PATCH] plane: added incomplete support for flipping --- entities/plane.lua | 27 +++++++++++++++++++++++++++ player.lua | 3 +++ settings.lua | 10 ++++++---- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/entities/plane.lua b/entities/plane.lua index 575b4c0..c3b3017 100644 --- a/entities/plane.lua +++ b/entities/plane.lua @@ -84,6 +84,7 @@ local max_motorPower = ENGINE_MAX local head_area = 1.0 local plane_area = 10.0 local motor_speed_ratio = 80.0 +local flipping_speed = 1.0 / 0.5 local out_of_bounds_coeff_multiplier = 10.0 @@ -438,6 +439,26 @@ Plane = Class{ local motorEffort = (self.motorPower / (math.max(fwd_vel, 100) + 1) - 1) / 2 + 1 self.motorSound:setPitch(motorEffort * self.motorPower / ENGINE_MAX + 0.5) + + if self.flipping ~= nil then + self.flipping = self.flipping + flipping_speed * dt + local finished = self.flipping >= 1.0 + if finished then + self.flipping = 1.0 + end + if self.goingRight then + self.orientationAngle = 180 * self.flipping + else + self.orientationAngle = 180 + 180 * self.flipping + if self.orientationAngle >= 360 then + self.orientationAngle = 0 + end + end + if finished then + self.goingRight = not self.goingRight + self.flipping = nil + end + end end; draw = function(self) @@ -485,5 +506,11 @@ Plane = Class{ end end end; + + flip = function(self, down) + if self.flipping == nil then + self.flipping = 0 + end + end } diff --git a/player.lua b/player.lua index b399101..172493a 100644 --- a/player.lua +++ b/player.lua @@ -21,6 +21,9 @@ Player = Class{ end, decelerate = function(down) self.plane:decelerate(down) + end, + flip = function(down) + self.plane:flip(down) end } diff --git a/settings.lua b/settings.lua index 40a48a1..94d82ce 100644 --- a/settings.lua +++ b/settings.lua @@ -15,8 +15,9 @@ KEYMAP = { cw = 'l', flip = 'i', shoot = 'o', - accelerate = 'j', - decelerate = 'm' + accelerate = 'j', + decelerate = 'm', + flip = ',' }, [2] = { @@ -24,8 +25,9 @@ KEYMAP = { cw = 's', flip = 'q', shoot = 'w', - accelerate = 'x', - decelerate = 'z' + accelerate = 'x', + decelerate = 'z', + flip = 'a' } }