an unnamed video game
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

72 rader
1.4 KiB

  1. -- world module
  2. local world = require("world")
  3. -- love's load function
  4. function love.load()
  5. -- set the overall map offset
  6. offset = {
  7. x = 0,
  8. y = 0
  9. }
  10. -- generate the world and load the files
  11. world.new(10, 10)
  12. world.loadTiles()
  13. -- store the mouse position
  14. mouse = {
  15. x = love.mouse.getX(),
  16. y = love.mouse.getY()
  17. }
  18. end
  19. -- love's update function
  20. function love.update(dt)
  21. -- get the current mouse location
  22. local mouseNow = {
  23. x = love.mouse.getX(),
  24. y = love.mouse.getY()
  25. }
  26. -- if mouse is pressed move the offset
  27. if love.mouse.isDown(1) then
  28. local mouseDelta = {
  29. x = mouse.x - mouseNow.x,
  30. y = mouse.y - mouseNow.y,
  31. }
  32. offset.x = offset.x - mouseDelta.x
  33. offset.y = offset.y - mouseDelta.y
  34. end
  35. mouse = mouseNow
  36. end
  37. -- love's key press funciton
  38. function love.keypressed(key, scanCode, isRepeat)
  39. -- arrow keys for moving offset
  40. if key == "left" then
  41. offset.x = offset.x - 16
  42. end
  43. if key == "right" then
  44. offset.x = offset.x + 16
  45. end
  46. if key == "up" then
  47. offset.y = offset.y - 16
  48. end
  49. if key == "down" then
  50. offset.y = offset.y + 16
  51. end
  52. end
  53. -- love's draw function
  54. function love.draw()
  55. -- clear the window
  56. love.graphics.clear()
  57. -- draw the map
  58. world.render(offset)
  59. end