Last active
April 24, 2018 01:39
-
-
Save Mr-Coxall/f12b2e8bc6a0c20b741003f912c0d446 to your computer and use it in GitHub Desktop.
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
----------------------------------------------------------------------------------------- | |
-- | |
-- main.lua | |
-- | |
----------------------------------------------------------------------------------------- | |
-- Gravity | |
local physics = require( "physics" ) | |
physics.start() | |
physics.setGravity( 0, 25 ) -- ( x, y ) | |
physics.setDrawMode( "hybrid" ) -- Shows collision engine outlines only | |
local theGround = display.newImage( "./assets/sprites/land.png" ) | |
theGround.x = display.contentCenterX | |
theGround.y = display.contentHeight | |
theGround.id = "the ground" | |
physics.addBody( theGround, "static", { | |
friction = 0.5, | |
bounce = 0.3 | |
} ) | |
local theCharacter = display.newImage( "./assets/sprites/Idle.png" ) | |
theCharacter.x = display.contentCenterX | |
theCharacter.y = display.contentCenterY | |
theCharacter.id = "the character" | |
physics.addBody( theCharacter, "dynamic", { | |
density = 3.0, | |
friction = 0.5, | |
bounce = 0.3 | |
} ) | |
local dPad = display.newImage( "./assets/sprites/d-pad.png" ) | |
dPad.x = 150 | |
dPad.y = display.contentHeight - 80 | |
dPad.alpha = 0.50 | |
dPad.id = "d-pad" | |
local upArrow = display.newImage( "./assets/sprites/upArrow.png" ) | |
upArrow.x = 150 | |
upArrow.y = display.contentHeight - 190 | |
upArrow.id = "up arrow" | |
local downArrow = display.newImage( "./assets/sprites/downArrow.png" ) | |
downArrow.x = 150 | |
downArrow.y = display.contentHeight + 28 | |
downArrow.id = "down arrow" | |
local leftArrow = display.newImage( "./assets/sprites/leftArrow.png" ) | |
leftArrow.x = 40 | |
leftArrow.y = display.contentHeight - 80 | |
leftArrow.id = "left arrow" | |
local rightArrow = display.newImage( "./assets/sprites/rightArrow.png" ) | |
rightArrow.x = 260 | |
rightArrow.y = display.contentHeight - 80 | |
rightArrow.id = "right arrow" | |
function upArrow:touch( event ) | |
if ( event.phase == "ended" ) then | |
-- move the character up | |
transition.moveBy( theCharacter, { | |
x = 0, -- move 0 in the x direction | |
y = -50, -- move up 50 pixels | |
time = 100 -- move in a 1/10 of a second | |
} ) | |
end | |
return true | |
end | |
function downArrow:touch( event ) | |
if ( event.phase == "ended" ) then | |
-- move the character up | |
transition.moveBy( theCharacter, { | |
x = 0, -- move 0 in the x direction | |
y = 50, -- move up 50 pixels | |
time = 100 -- move in a 1/10 of a second | |
} ) | |
end | |
return true | |
end | |
function leftArrow:touch( event ) | |
if ( event.phase == "ended" ) then | |
-- move the character up | |
transition.moveBy( theCharacter, { | |
x = -50, -- move 0 in the x direction | |
y = 0, -- move up 50 pixels | |
time = 100 -- move in a 1/10 of a second | |
} ) | |
end | |
return true | |
end | |
function rightArrow:touch( event ) | |
if ( event.phase == "ended" ) then | |
-- move the character up | |
transition.moveBy( theCharacter, { | |
x = 50, -- move 0 in the x direction | |
y = 0, -- move up 50 pixels | |
time = 100 -- move in a 1/10 of a second | |
} ) | |
end | |
return true | |
end | |
upArrow:addEventListener( "touch", upArrow ) | |
downArrow:addEventListener( "touch", downArrow ) | |
leftArrow:addEventListener( "touch", leftArrow ) | |
rightArrow:addEventListener( "touch", rightArrow ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment