an unnamed video game
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.1 KiB

  1. -- bring in the util module
  2. local util = require("util")
  3. local entities = {}
  4. -- initialize the entities table
  5. function entities.init()
  6. entities.staticEntities = {}
  7. entities.dynamicEntities = {}
  8. end
  9. -- load all sprites to memory
  10. function entities.loadSprites()
  11. entities.sprites = {}
  12. entities.sprites.town = love.graphics.newImage("img/building.png")
  13. end
  14. -- create a new static entity that will always align with the map grid
  15. function entities.newStatic(x, y, z, type)
  16. local static = {}
  17. static.x = x
  18. static.y = y
  19. static.z = z
  20. static.type = type
  21. table.insert(entities.staticEntities, static)
  22. end
  23. -- render all entities
  24. function entities.render(offset)
  25. -- render static entities
  26. for _, entity in ipairs(entities.staticEntities) do
  27. local type = entity.type
  28. local loc = util.cartToIso({x = entity.x, y = entity.y})
  29. if type == "town" then
  30. image = entities.sprites.town
  31. end
  32. if image ~= nil then
  33. love.graphics.draw(image, loc.x * 16 + offset.x, loc.y * 16 + offset.y - entity.z * 16)
  34. end
  35. end
  36. end
  37. return entities