All Projects → a327ex → Boipushy

a327ex / Boipushy

Input module for LÖVE

Programming Languages

lua
6591 projects

Projects that are alternatives of or similar to Boipushy

Hidguardian
Windows kernel-mode driver for controlling access to various input devices.
Stars: ✭ 138 (+0%)
Mutual labels:  gamepad, input
Grid Sdk
The Grid SDK - Game engine for Lua
Stars: ✭ 612 (+343.48%)
Mutual labels:  game-development, love2d
Windfield
Physics module for LÖVE
Stars: ✭ 254 (+84.06%)
Mutual labels:  game-development, love2d
Goluwa
a game framework written in luajit
Stars: ✭ 173 (+25.36%)
Mutual labels:  game-development, love2d
Gilrs
Game Input Library for Rust - Mirror of https://gitlab.com/gilrs-project/gilrs
Stars: ✭ 81 (-41.3%)
Mutual labels:  gamepad, input
Stalker X
Camera module for LÖVE
Stars: ✭ 212 (+53.62%)
Mutual labels:  game-development, love2d
Unswitch
🕹 A tiny event handler for Switch controllers!
Stars: ✭ 574 (+315.94%)
Mutual labels:  gamepad, input
Blog
gamedev blog
Stars: ✭ 3,076 (+2128.99%)
Mutual labels:  game-development, love2d
Bytepath
A replayable arcade shooter with a focus on build theorycrafting made using Lua and LÖVE.
Stars: ✭ 1,119 (+710.87%)
Mutual labels:  game-development, love2d
Inputsystem
An efficient and versatile input system for Unity.
Stars: ✭ 1,013 (+634.06%)
Mutual labels:  gamepad, input
Awesome Love2d
A curated list of amazingly awesome LÖVE libraries, resources and shiny things.
Stars: ✭ 2,191 (+1487.68%)
Mutual labels:  game-development, love2d
Love
LÖVE is an awesome 2D game framework for Lua.
Stars: ✭ 1,305 (+845.65%)
Mutual labels:  game-development, love2d
Key Mapper
🎮 An easy to use tool to change the mapping of your input device buttons.
Stars: ✭ 184 (+33.33%)
Mutual labels:  gamepad, input
Lovetoys
🍌 a full-featured Entity-Component-System framework for making games with lua
Stars: ✭ 252 (+82.61%)
Mutual labels:  game-development, love2d
Gainput
Cross-platform C++ input library supporting gamepads, keyboard, mouse, touch
Stars: ✭ 636 (+360.87%)
Mutual labels:  gamepad, input
Zabuyaki
Zabuyaki, old-school side-scrolling beat 'em up
Stars: ✭ 91 (-34.06%)
Mutual labels:  game-development, love2d
Tove2d
Animated vector graphics for LÖVE.
Stars: ✭ 113 (-18.12%)
Mutual labels:  game-development, love2d
Reldens
Reldens - You can make it - Open Source MMORPG Platform
Stars: ✭ 130 (-5.8%)
Mutual labels:  game-development
Borealis
Hardware accelerated, controller and TV oriented UI library for PC and Nintendo Switch (libnx).
Stars: ✭ 135 (-2.17%)
Mutual labels:  gamepad
Nasnas
An intuitive and user friendly 2D game framework for C++
Stars: ✭ 131 (-5.07%)
Mutual labels:  game-development

boipushy

An input module for LÖVE. Simplifies input handling by abstracting them away to actions, enabling pressed/released checks outside of LÖVE's callbacks and taking care of gamepad input as well. :)


Usage

Input = require 'Input'

Creating an input object

function love.load()
  input = Input()
end

You can create multiple input objects even though you can get by most of the time with just a single global one. If your game supports multiple players locally then it's probably a good idea to create a different input object for each player, although it's not necessary as long as bindings between players don't collide.


Binding keys to actions

input:bind('1', 'print')

The example above binds the '1' key to the 'print' action. This means that in our code we can check for the 'print' action being pressed with input:pressed('print'), for instance, and that function would return true on the frame that we pressed the '1' key on the keyboard. This layer of indirection between keyboard and action allows our gameplay focus to only speak in terms of actions, which means that it doesn't have to care about which method of input is being used or if the key bindings were changed to something else.

input:bind('s', function() print(2) end)
input:bind('mouse1', 'left_click')

On top of action strings we can also bind anonymous functions. In this case, whenever we press the 's' key on the keyboard 2 would be printed to the console. Additionally, we can bind mouse and gamepad buttons in the same.


Checking if an action is pressed/released/down

function love.update(dt)
  if input:pressed('print') then print('The 1 key was pressed on this frame!') end
  if input:released('print') then print('The 1 key was released on this frame!') end
  if input:down('left_click') then print('The left mouse button is being held down!') end
end

pressed, released and down are the main functions of the library. Both pressed and released only return true on the frame when that event happened, while down returns true on every frame that the key bound to the action is being held down.


Triggering events on intervals if an action is held down

The down function can accept additional arguments to trigger events on an interval basis. For instance:

function love.update(dt)
  if input:down('print', 0.5) then print(love.math.random()) end
end

The example above will print a random number every 0.5 seconds from when the 'print' action key was held down. This is useful in a number of situations, like if you want your player to be able to only perform some action (like shooting projectiles) according to some cooldown.

Additionally, a third argument can be passed which represents a delay for the event triggering to start. For instance:

function love.update(dt)
  if input:down('print', 0.5, 2) then print(love.math.random()) end
end

The example above will print a random number every 0.5 seconds after 2 seconds have passed from when the 'print' action key was held down. This behavior can be seen in action whenever you're typing something and you hold a key down, for instance. If you hold the x key down, first x will be typed once, there will be a small amount of time (like say 0.3s) where nothing happens, and then a lot of x will come following really fast.


Sequences

The sequence function allows you to check for sequences of buttons pressed within an interval of each other. For instance:

function love.update(dt)
  if input:sequence('right', 0.5, 'right') then
    -- dash right
  end
end

In the example above the sequence function will return true when the 'right' action is pressed twice, and the second key press happened within 0.5s of the first. This is useful for simple things like dashing, but also for more complex sequences like combos. This function must be started and finished with an action, and between each action there should be the interval limit.


Unbinding a key

input:unbind('1')
input:unbind('s')
input:unbind('mouse1')

Unbinding keys simply disconnects them from their actions. You can also use input:unbindAll() to unbind all bound keys.


Key/mouse/gamepad Constants

Keyboard constants are unchanged from here, but mouse and gamepad have been changed to the following:

-- Mouse
'mouse1'
'mouse2'
'mouse3'
'mouse4'
'mouse5'
'wheelup'
'wheeldown'

-- Gamepad
'fdown' -- fdown/up/left/right = face buttons: a, b...
'fup'
'fleft'
'fright'
'back'
'guide'
'start'
'leftstick' -- left stick pressed or not (boolean)
'rightstick' -- right stick pressed or not (boolean)
'l1'
'r1'
'l2' -- returns a value from 0 to 1
'r2' -- returns a value from 0 to 1
'dpup' -- dpad buttons
'dpdown'
'dpleft'
'dpright'
'leftx' -- returns a value from -1 to 1, the left stick's horizontal position
'lefty' -- same for vertical
'rightx' -- same for right stick
'righty'

LICENSE

You can do whatever you want with this. See the license at the top of the main file.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].