diff --git a/button.lua b/button.lua index ed22ed3..9c7319a 100644 --- a/button.lua +++ b/button.lua @@ -10,10 +10,19 @@ function Button:new(x, y, r, b) end function Button:update(dt) - if love.keyboard.isDown(self.b) then - self.press = true - else + + if self.b == "triggerleft" or self.b == "triggerright" then + if fightstick:getGamepadAxis(self.b) == 1 then + self.press = true + else self.press = false + end + else + if fightstick:isGamepadDown(self.b) then + self.press = true + else + self.press = false + end end end @@ -24,8 +33,7 @@ function Button:draw() else mode = "line" end - love.graphics.circle(mode, self.x + self.r, self.y + self.r, self.r) -end +end return Button \ No newline at end of file diff --git a/invis.lua b/invis.lua new file mode 100644 index 0000000..e69de29 diff --git a/main.lua b/main.lua index 3643250..5c65441 100644 --- a/main.lua +++ b/main.lua @@ -1,23 +1,29 @@ function love.load() + + require("sdl") + require("invis") + local Button = require "button" + joysticks = love.joystick.getJoysticks() + fightstick = joysticks[1] --movement keys movement = {} - mL = Button(8, 27, 24, "a") - mD = Button(62, 27, 24, "s") - mR = Button(109, 53, 24, "d") - mU = Button(127, 144, 30, "space") + mL = Button(8, 27, 24, "dpleft") + mD = Button(62, 27, 24, "dpdown") + mR = Button(109, 53, 24, "dpright") + mU = Button(127, 144, 30, "dpup") --attack keys attack = {} - bA = Button(159, 29, 24, "u") - bB = Button(208, 8, 24, "i") - bC = Button(262, 9, 24, "o") - bD = Button(317, 16, 24, "p") - bE = Button(155, 85, 24, "j") - bF = Button(206, 64, 24, "k") - bG = Button(262, 64, 24, "l") - bH = Button(315,72, 24, ";") + bA = Button(159, 29, 24, "x") + bB = Button(208, 8, 24, "y") + bC = Button(262, 9, 24, "rightshoulder") + bD = Button(317, 16, 24, "leftshoulder") + bE = Button(155, 85, 24, "a") + bF = Button(206, 64, 24, "b") + bG = Button(262, 64, 24, "triggerright") + bH = Button(315,72, 24, "triggerleft") end function love.update(dt) @@ -40,6 +46,10 @@ end 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) --movement keys diff --git a/sdl.lua b/sdl.lua new file mode 100644 index 0000000..570beba --- /dev/null +++ b/sdl.lua @@ -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") \ No newline at end of file