Guest User

Untitled

a guest
Feb 19th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. SCREEN_WIDTH = 320
  2. SCREEN_HEIGHT = 480
  3. LIMIT_FPS = 30
  4.  
  5. local player = {}
  6. player.x = SCREEN_WIDTH / 2
  7. player.y = SCREEN_HEIGHT / 2
  8.  
  9. -- Disable the status bar
  10. display.setStatusBar(display.HiddenStatusBar)
  11.  
  12. -- Add a background image
  13. local background = display.newImage ("background.png")
  14.  
  15. -- Draw a @ at the x,y coords assigned to the player and flag it as not-red
  16. local playerObject = display.newText("@", player.x, player.y, "Courier Final Draft", 24)
  17. playerObject:setTextColor(255, 255, 255)
  18. playerIsRed = false
  19.  
  20. -- Create a tap event for the @ player object
  21. playerObject:addEventListener( "tap", playerObject)
  22.  
  23. -- When the @ object is tapped, toggle the color of the character
  24. function playerObject:tap( event )
  25. if playerIsRed then
  26. playerObject:setTextColor(255, 255, 255)
  27. playerIsRed = false
  28. else
  29. playerObject:setTextColor(255, 0, 0)
  30. playerIsRed = true
  31. end
  32. end
  33.  
  34. -- Assign the event coords to the player coords, using the touch event listener.
  35. function playerMovement (event)
  36. playerObject.x = event.x
  37. playerObject.y = event.y
  38.  
  39. if playerObject.x > SCREEN_WIDTH then
  40. playerObject.x = SCREEN_WIDTH
  41. end
  42.  
  43. if playerObject.x < 0 then
  44. playerObject.x = 0
  45. end
  46.  
  47. if playerObject.y > SCREEN_HEIGHT then
  48. playerObject.y = SCREEN_HEIGHT
  49. end
  50.  
  51. if playerObject.y < 0 then
  52. playerObject.y = 0
  53. end
  54. end
  55. Runtime:addEventListener("touch", playerMovement)
Add Comment
Please, Sign In to add comment