an unnamed video game
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

56 lignes
1.7 KiB

  1. -- bring in the util module
  2. local util = require("util")
  3. -- world stuffs
  4. local world = {}
  5. -- create a new world with given height and width
  6. function world.new(width, height)
  7. world.width = width
  8. world.height = height
  9. world.hover = nil
  10. world.select = love.graphics.newImage("img/tiles/select.png")
  11. for x = 1, world.width do
  12. world[x] = {}
  13. for y = 1, world.height do
  14. world[x][y] = "nothing"
  15. end
  16. end
  17. end
  18. -- load the tile files
  19. function world.loadTiles()
  20. world.tiles = {}
  21. world.tiles.grass = love.graphics.newImage("img/tiles/grass.png")
  22. world.tiles.dirt = love.graphics.newImage("img/tiles/dirt.png")
  23. world.tiles.water = love.graphics.newImage("img/tiles/water.png")
  24. world.tiles.nothing = love.graphics.newImage("img/tiles/nothing.png")
  25. end
  26. -- render the world
  27. function world.render(offset)
  28. for x = 1, world.width do
  29. for y = 1, world.height do
  30. local tile = world[x][y]
  31. local loc = util.cartToIso({x = x, y = y})
  32. if tile == "grass" then
  33. image = world.tiles.grass
  34. elseif tile == "dirt" then
  35. image = world.tiles.dirt
  36. elseif tile == "water" then
  37. image = world.tiles.water
  38. else
  39. image = world.tiles.nothing
  40. end
  41. love.graphics.draw(image, loc.x * 16 + offset.x, loc.y * 16 + offset.y)
  42. end
  43. end
  44. if not world.hover == nil then
  45. love.graphics.draw(world.select, world.hover.x, world.hover.y)
  46. end
  47. end
  48. return world