Advertisement
Guest User

Untitled

a guest
Apr 30th, 2025
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. local cam
  2. function love.load()
  3. anim8 = require 'libs/anim8'
  4. wf = require 'libs/windfield'
  5. world = wf.newWorld(0, 0)
  6. sti = require 'libs/sti'
  7. map = sti('map/test map.lua')
  8. gamera = require 'libs/gamera'
  9. local mapWidth = map.width * map.tilewidth
  10. local mapHeight = map.height * map.tileheight
  11. cam = gamera.new(0, 0, mapWidth, mapHeight)
  12. player = {}
  13. player.speed = 3
  14. player.x = 400
  15. player.y = 300
  16. player.sprite = love.graphics.newImage('sprites/$Lonely.png')
  17. player.Grid = anim8.newGrid(32, 32, player.sprite:getWidth(), player.sprite:getHeight())
  18. player.animations = {}
  19. player.animations.right = anim8.newAnimation(player.Grid('1-3', 3), 0.2)
  20. player.animations.up = anim8.newAnimation(player.Grid('1-3', 4), 0.2)
  21. player.animations.left = anim8.newAnimation(player.Grid('1-3', 2), 0.2)
  22. player.animations.down = anim8.newAnimation(player.Grid('1-3', 1), 0.2)
  23. player.anim = player.animations.right
  24. love.graphics.setDefaultFilter("nearest", "nearest")
  25. player.collider = world:newBSGRectangleCollider(player.x, player.y, 40, 80, 14)
  26. player.collider:setFixedRotation(true)
  27.  
  28. end
  29.  
  30. function love.update(dt)
  31. local isMoving = false
  32. if love.keyboard.isDown("w") then
  33. player.y = player.y - player.speed
  34. player.anim = player.animations.up
  35. isMoving = true
  36. end
  37.  
  38. if love.keyboard.isDown("d") then
  39. player.x = player.x + player.speed
  40. isMoving = true
  41. player.anim = player.animations.right
  42. end
  43. if love.keyboard.isDown("a") then
  44. player.x = player.x - player.speed
  45. isMoving = true
  46. player.anim = player.animations.left
  47. end
  48. if love.keyboard.isDown("s") then
  49. player.y = player.y + player.speed
  50. player.anim = player.animations.down
  51. isMoving = true
  52. end
  53.  
  54. player.anim:update(dt)
  55. if isMoving == false then
  56. player.anim:gotoFrame(2)
  57. end
  58. cam:setPosition(player.x, player.y)
  59. world:update(dt)
  60. player.x = player.collider:getX()
  61. player.y = player.collider:getY()
  62. end
  63.  
  64. function love.draw()
  65. cam:draw(function(l, t, w, h)
  66. map:drawLayer(map.layers["ground"])
  67. map:drawLayer(map.layers["bushes"])
  68. map:drawLayer(map.layers["trees"])
  69. map:drawLayer(map.layers["buildings"])
  70. player.anim:draw(player.sprite, player.x, player.y, nil, 2)
  71. world:draw(dt)
  72. end)
  73.  
  74. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement