Joystick button bindings are now used

This commit is contained in:
Erkki Seppälä 2014-10-24 09:23:44 +03:00
parent 0162c2f353
commit cda67f61ba
2 changed files with 19 additions and 19 deletions

View file

@ -306,7 +306,7 @@ Plane = Class{
if self.accelerating then
self.motorPower = math.min(max_motorPower, self.motorPower + dt * accel_speed)
end
if self.decelerating or self.brake then
if self.decelerating then
self.motorPower = math.max(0.0, self.motorPower - dt * decel_speed)
end
self.motorPower = math.max(0.0, math.min(max_motorPower, self.motorPower + dt * self.throttleY * accel_speed))
@ -499,25 +499,11 @@ Plane = Class{
self.turningCcw = isTurning
end;
analog = function(self, controlY, throttleX, throttleY, fire, brake)
analog = function(self, controlY, throttleX, throttleY)
if self.health > 0 then
self.controlY = controlY
self.throttleX = throttleX
self.throttleY = -throttleY
self.fire = fire
self.brake = brake
if fire then
if not self.kbdShooting and not self.joyShooting then
self.machinegun:startShooting()
end
self.joyShooting = true
else
self.joyShooting = false
if not self.kbdShooting and not self.joyShooting then
self.machinegun:stopShooting()
end
end
end
end;

View file

@ -20,6 +20,8 @@ local players = {
[2] = Player(2, 'Nicd')
}
local lastJoystickButtons = { nil, nil }
local scoreboards = {}
local level_music = nil
@ -113,10 +115,22 @@ function level_state:update(dt)
for i = 1, j:getButtonCount(), 1 do
buttons[i] = j:isDown(i)
end
if lastJoystickButtons[player] ~= nil then
for i = 1, #buttons, 1 do
if buttons[i] ~= lastJoystickButtons[player][i] then
local key = string.format("button%d", i)
if buttons[i] then
players[player]:press(key)
else
players[player]:release(key)
end
end
end
end
lastJoystickButtons[player] = buttons
local x1, y1, x2, y2 = j:getAxes()
if #buttons >= 8 and y2 ~= nil then
-- button mapping suitable for XBox original controller
players[player]:joystick(y2 - x2, x1, y1, buttons[8], buttons[7])
if y2 ~= nil then
players[player]:joystick(y2 - x2, x1, y1)
end
end
end