65 lines
No EOL
1.5 KiB
Lua
65 lines
No EOL
1.5 KiB
Lua
function love.load()
|
|
-- Recognize background input
|
|
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")
|
|
|
|
local Button = require "button"
|
|
|
|
local joysticks = love.joystick.getJoysticks()
|
|
joystick = joysticks[1]
|
|
|
|
--movement keys
|
|
mL = Button(8, 27, 24, "dpleft")
|
|
mD = Button(62, 27, 24, "dpdown")
|
|
mR = Button(109, 53, 24, "dpright")
|
|
mU = Button(127, 144, 30, "dpup")
|
|
movement = {mL, mD, mR, mU}
|
|
|
|
--attack keys
|
|
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")
|
|
attack = {bA, bB, bC, bD, bE, bF, bG, bH}
|
|
end
|
|
|
|
function love.update(dt)
|
|
--movement keys
|
|
for _, button in ipairs(movement) do
|
|
button:update(dt)
|
|
end
|
|
|
|
--attack keys
|
|
for _, button in ipairs(attack) do
|
|
button:update(dt)
|
|
end
|
|
end
|
|
|
|
function love.draw()
|
|
|
|
love.graphics.setBackgroundColor(1, 179/255, 102/255)
|
|
|
|
--movement keys
|
|
for _, button in ipairs(movement) do
|
|
button:draw()
|
|
end
|
|
|
|
--attack keys
|
|
for _, button in ipairs(attack) do
|
|
button:draw()
|
|
end
|
|
end |