Skip to content

Instantly share code, notes, and snippets.

@caleywoods
Created February 13, 2019 15:20
Show Gist options
  • Save caleywoods/ff8cf90da5a3e92db3c8ae095990e6a7 to your computer and use it in GitHub Desktop.
Save caleywoods/ff8cf90da5a3e92db3c8ae095990e6a7 to your computer and use it in GitHub Desktop.
local background = display.newImageRect( "background.png", 360, 570 )
local trashcan = display.newImageRect( "trashcan.png", 100, 100 )
local shafi = display.newImageRect( "ShafiChamp.png", 60, 60 )
local physics = require( "physics" )
local timer = require( "timer" )
local spinning = false
local timerID = nil
background.x = display.contentCenterX
background.y = display.contentCenterY
trashcan.x = display.contentCenterX
trashcan.y = display.contentHeight - 5
shafi.x = display.contentCenterX
shafi.y = display.contentCenterY
physics.start()
physics.addBody( trashcan, "static", { radius=5 } )
physics.addBody( shafi, "dynamic", { radius=60, bounce=0.5 } )
local function spinThisMan()
if not spinning then
spinning = true
timerID = timer.performWithDelay( 50, spinThisMan, -1 )
else
shafi:rotate( 5 )
end
end
local function pushShafi()
if not spinning then
spinThisMan()
end
shafi:applyLinearImpulse( 0, -1.5, shafi.x, shafi.y )
end
local function wasted()
background = display.newImageRect( "ded.jpg", 350, display.pixelHeight )
background.x = display.contentCenterX
background.y = display.contentCenterY
shafi:removeSelf()
trashcan:removeSelf()
end
local function onCollision()
if timerID ~= nil then
timer.cancel( timerID )
end
wasted()
end
shafi:addEventListener( "collision", onCollision )
shafi:addEventListener( "tap", pushShafi )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment