plane: added incomplete support for flipping

This commit is contained in:
Erkki Seppälä 2014-10-23 09:56:59 +03:00
parent b7b6e10535
commit b1002378c5
3 changed files with 36 additions and 4 deletions

View file

@ -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
}

View file

@ -21,6 +21,9 @@ Player = Class{
end,
decelerate = function(down)
self.plane:decelerate(down)
end,
flip = function(down)
self.plane:flip(down)
end
}

View file

@ -16,7 +16,8 @@ KEYMAP = {
flip = 'i',
shoot = 'o',
accelerate = 'j',
decelerate = 'm'
decelerate = 'm',
flip = ','
},
[2] = {
@ -25,7 +26,8 @@ KEYMAP = {
flip = 'q',
shoot = 'w',
accelerate = 'x',
decelerate = 'z'
decelerate = 'z',
flip = 'a'
}
}