controller support and unfocused window added
This commit is contained in:
parent
768eed8787
commit
94ba18772b
4 changed files with 46 additions and 17 deletions
18
button.lua
18
button.lua
|
@ -10,10 +10,19 @@ function Button:new(x, y, r, b)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Button:update(dt)
|
function Button:update(dt)
|
||||||
if love.keyboard.isDown(self.b) then
|
|
||||||
self.press = true
|
if self.b == "triggerleft" or self.b == "triggerright" then
|
||||||
else
|
if fightstick:getGamepadAxis(self.b) == 1 then
|
||||||
|
self.press = true
|
||||||
|
else
|
||||||
self.press = false
|
self.press = false
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if fightstick:isGamepadDown(self.b) then
|
||||||
|
self.press = true
|
||||||
|
else
|
||||||
|
self.press = false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -24,8 +33,7 @@ function Button:draw()
|
||||||
else
|
else
|
||||||
mode = "line"
|
mode = "line"
|
||||||
end
|
end
|
||||||
|
|
||||||
love.graphics.circle(mode, self.x + self.r, self.y + self.r, self.r)
|
love.graphics.circle(mode, self.x + self.r, self.y + self.r, self.r)
|
||||||
end
|
end
|
||||||
|
|
||||||
return Button
|
return Button
|
0
invis.lua
Normal file
0
invis.lua
Normal file
34
main.lua
34
main.lua
|
@ -1,23 +1,29 @@
|
||||||
function love.load()
|
function love.load()
|
||||||
|
|
||||||
|
require("sdl")
|
||||||
|
require("invis")
|
||||||
|
|
||||||
local Button = require "button"
|
local Button = require "button"
|
||||||
|
joysticks = love.joystick.getJoysticks()
|
||||||
|
fightstick = joysticks[1]
|
||||||
|
|
||||||
--movement keys
|
--movement keys
|
||||||
movement = {}
|
movement = {}
|
||||||
mL = Button(8, 27, 24, "a")
|
mL = Button(8, 27, 24, "dpleft")
|
||||||
mD = Button(62, 27, 24, "s")
|
mD = Button(62, 27, 24, "dpdown")
|
||||||
mR = Button(109, 53, 24, "d")
|
mR = Button(109, 53, 24, "dpright")
|
||||||
mU = Button(127, 144, 30, "space")
|
mU = Button(127, 144, 30, "dpup")
|
||||||
|
|
||||||
--attack keys
|
--attack keys
|
||||||
attack = {}
|
attack = {}
|
||||||
bA = Button(159, 29, 24, "u")
|
bA = Button(159, 29, 24, "x")
|
||||||
bB = Button(208, 8, 24, "i")
|
bB = Button(208, 8, 24, "y")
|
||||||
bC = Button(262, 9, 24, "o")
|
bC = Button(262, 9, 24, "rightshoulder")
|
||||||
bD = Button(317, 16, 24, "p")
|
bD = Button(317, 16, 24, "leftshoulder")
|
||||||
bE = Button(155, 85, 24, "j")
|
bE = Button(155, 85, 24, "a")
|
||||||
bF = Button(206, 64, 24, "k")
|
bF = Button(206, 64, 24, "b")
|
||||||
bG = Button(262, 64, 24, "l")
|
bG = Button(262, 64, 24, "triggerright")
|
||||||
bH = Button(315,72, 24, ";")
|
bH = Button(315,72, 24, "triggerleft")
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.update(dt)
|
function love.update(dt)
|
||||||
|
@ -40,6 +46,10 @@ end
|
||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
|
|
||||||
|
for i, joystick in ipairs(joysticks) do
|
||||||
|
love.graphics.print(joystick:getName(), 10, i * 20)
|
||||||
|
end
|
||||||
|
|
||||||
love.graphics.setBackgroundColor(1, 179/255, 102/255)
|
love.graphics.setBackgroundColor(1, 179/255, 102/255)
|
||||||
|
|
||||||
--movement keys
|
--movement keys
|
||||||
|
|
11
sdl.lua
Normal file
11
sdl.lua
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
local ffi = require("ffi")
|
||||||
|
ffi.cdef[[
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
SDL_FALSE = 0,
|
||||||
|
SDL_TRUE = 1
|
||||||
|
} SDL_bool;
|
||||||
|
SDL_bool SDL_SetHint(const char *name, const char *value);
|
||||||
|
]]
|
||||||
|
local sdl = ffi.os == "Windows" and ffi.load("SDL2") or ffi.C
|
||||||
|
sdl.SDL_SetHint("SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS", "1")
|
Loading…
Add table
Add a link
Reference in a new issue