Joystick button bindings are now used
This commit is contained in:
parent
0162c2f353
commit
cda67f61ba
2 changed files with 19 additions and 19 deletions
|
@ -306,7 +306,7 @@ Plane = Class{
|
||||||
if self.accelerating then
|
if self.accelerating then
|
||||||
self.motorPower = math.min(max_motorPower, self.motorPower + dt * accel_speed)
|
self.motorPower = math.min(max_motorPower, self.motorPower + dt * accel_speed)
|
||||||
end
|
end
|
||||||
if self.decelerating or self.brake then
|
if self.decelerating then
|
||||||
self.motorPower = math.max(0.0, self.motorPower - dt * decel_speed)
|
self.motorPower = math.max(0.0, self.motorPower - dt * decel_speed)
|
||||||
end
|
end
|
||||||
self.motorPower = math.max(0.0, math.min(max_motorPower, self.motorPower + dt * self.throttleY * accel_speed))
|
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
|
self.turningCcw = isTurning
|
||||||
end;
|
end;
|
||||||
|
|
||||||
analog = function(self, controlY, throttleX, throttleY, fire, brake)
|
analog = function(self, controlY, throttleX, throttleY)
|
||||||
if self.health > 0 then
|
if self.health > 0 then
|
||||||
self.controlY = controlY
|
self.controlY = controlY
|
||||||
self.throttleX = throttleX
|
self.throttleX = throttleX
|
||||||
self.throttleY = -throttleY
|
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
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,8 @@ local players = {
|
||||||
[2] = Player(2, 'Nicd')
|
[2] = Player(2, 'Nicd')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local lastJoystickButtons = { nil, nil }
|
||||||
|
|
||||||
local scoreboards = {}
|
local scoreboards = {}
|
||||||
|
|
||||||
local level_music = nil
|
local level_music = nil
|
||||||
|
@ -113,10 +115,22 @@ function level_state:update(dt)
|
||||||
for i = 1, j:getButtonCount(), 1 do
|
for i = 1, j:getButtonCount(), 1 do
|
||||||
buttons[i] = j:isDown(i)
|
buttons[i] = j:isDown(i)
|
||||||
end
|
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()
|
local x1, y1, x2, y2 = j:getAxes()
|
||||||
if #buttons >= 8 and y2 ~= nil then
|
if y2 ~= nil then
|
||||||
-- button mapping suitable for XBox original controller
|
players[player]:joystick(y2 - x2, x1, y1)
|
||||||
players[player]:joystick(y2 - x2, x1, y1, buttons[8], buttons[7])
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue