This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function onInputDeviceStatusChanged( event ) | |
-- Handle the input device change | |
if ( event.connectionStateChanged ) then | |
print( event.device.displayName .. ": " .. event.device.connectionState, event.device.descriptor, event.device.type, event.device.canVibrate ) | |
end | |
end | |
Runtime:addEventListener( "inputDeviceStatus", onInputDeviceStatusChanged ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Fetch all input devices currently connected to the system | |
local inputDevices = system.getInputDevices() | |
-- Traverse all input devices | |
for deviceIndex = 1, #inputDevices do | |
-- Fetch the input device's axes | |
print( deviceIndex, "andoridDeviceid", inputDevices[deviceIndex].androidDeviceId ) | |
print( deviceIndex, "canVibrate", inputDevices[deviceIndex].canVibrate ) | |
print( deviceIndex, "connectionState", inputDevices[deviceIndex].connectionState ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function onAxisEvent( event ) | |
-- Display some info on the screen about this axis event | |
local message = "Axis '" .. event.axis.descriptor .. "' was moved " .. tostring( event.normalizedValue ) | |
myAxisDisplayText.text = message | |
-- Map event data to simple variables | |
local abs = math.abs | |
local controller = event.device.descriptor | |
local thisAxis = event.axis.number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Since controllers don't generate constant values, but simply events when | |
-- the values change, we need to set a movement amount when the event happens, | |
-- and also have the game loop continuously apply it | |
-- We can also calculate our rotation angle here | |
local function moveRedPlayer() | |
-- Set the .isMovingX and .isMovingY values in our event handler | |
-- If this number isn't 0 (stopped moving), move the player |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Calculate the angle to rotate the square. Using simple right angle math, we can | |
-- determine the base and height of a right triangle where one point is 0,0 | |
-- (stick center) and the values returned from the two axis numbers returned | |
-- from the stick | |
-- This will give us a 0-90 value, so we have to map it to the quadrant | |
-- based on if the values for the two axis are positive or negative | |
-- Negative Y, positive X is top-right area | |
-- Positive X, Positive Y is bottom-right area | |
-- Negative X, positive Y is bottom-left area |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local redPlayer = display.newRect( display.contentCenterX-15, display.contentCenterY-15, 30, 30 ) | |
redPlayer:setFillColor( 1, 0, 0 ) | |
redPlayer.x = display.contentCenterX | |
redPlayer.y = display.contentCenterY | |
redPlayer.isMovingX = 0 | |
redPlayer.isMovingY = 0 | |
redPlayer.isRotatingX = 0 | |
redPlayer.isRotatingY = 0 | |
redPlayer.thisAngle = 0 | |
redPlayer.lastAngle = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Map the names to identify an axis with a device's physical inputs | |
local axisMap = {} | |
axisMap["OUYA Game Controller"] = {} | |
axisMap["OUYA Game Controller"][1] = "left_x" | |
axisMap["OUYA Game Controller"][2] = "left_y" | |
axisMap["OUYA Game Controller"][3] = "left_trigger" | |
axisMap["OUYA Game Controller"][4] = "right_x" | |
axisMap["OUYA Game Controller"][5] = "right_y" | |
axisMap["OUYA Game Controller"][6] = "right_trigger" | |
axisMap["DualShock Controller"] = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iphone = | |
{ | |
plist = | |
{ | |
CFBundleIconFile = "Icon.png", | |
CFBundleIconFiles = | |
{ | |
"Icon.png", | |
"Icon@2x.png", | |
"Icon-60.png", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- rectangle based | |
local function hasCollided(obj1, obj2) | |
if obj1 == nil then | |
return false | |
end | |
if obj2 == nil then | |
return false | |
end | |
local left = obj1.contentBounds.xMin <= obj2.contentBounds.xMin and obj1.contentBounds.xMax >= obj2.contentBounds.xMin |