an unnamed video game
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

67 rindas
2.1 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 depth and width
  6. function world.new(width, depth, height)
  7. world.width = width
  8. world.depth = depth
  9. world.height = height
  10. world.hover = nil
  11. world.select = love.graphics.newImage("img/tiles/select.png")
  12. for x = 1, world.width do
  13. world[x] = {}
  14. for y = 1, world.depth do
  15. world[x][y] = {}
  16. for z = 1, world.height do
  17. world[x][y][z] = "nothing"
  18. end
  19. end
  20. end
  21. end
  22. -- generates a world, should be called after world.new()
  23. function world.generate()
  24. end
  25. -- load the tile files
  26. function world.loadTiles()
  27. world.tiles = {}
  28. world.tiles.grass = love.graphics.newImage("img/tiles/grass.png")
  29. world.tiles.dirt = love.graphics.newImage("img/tiles/dirt.png")
  30. world.tiles.water = love.graphics.newImage("img/tiles/water.png")
  31. world.tiles.nothing = love.graphics.newImage("img/tiles/nothing.png")
  32. end
  33. -- render the world
  34. function world.render(offset)
  35. for x = 1, world.width do
  36. for y = 1, world.depth do
  37. for z = 1, world.height do
  38. local tile = world[x][y][z]
  39. local loc = util.cartToIso({x = x, y = y})
  40. if tile == "grass" then
  41. image = world.tiles.grass
  42. elseif tile == "dirt" then
  43. image = world.tiles.dirt
  44. elseif tile == "water" then
  45. image = world.tiles.water
  46. else
  47. image = world.tiles.nothing
  48. end
  49. love.graphics.draw(image, loc.x * 16 + offset.x, loc.y * 16 + offset.y - z * 16)
  50. end
  51. end
  52. end
  53. if not world.hover == nil then
  54. love.graphics.draw(world.select, world.hover.x, world.hover.y)
  55. end
  56. end
  57. return world