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.

50 rindas
1.5 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. for x = 1, world.width do
  10. world[x] = {}
  11. for y = 1, world.height do
  12. world[x][y] = "nothing"
  13. end
  14. end
  15. end
  16. -- load the tile files
  17. function world.loadTiles()
  18. world.grass = love.graphics.newImage("img/tiles/grass.png")
  19. world.dirt = love.graphics.newImage("img/tiles/dirt.png")
  20. world.water = love.graphics.newImage("img/tiles/water.png")
  21. world.nothing = love.graphics.newImage("img/tiles/nothing.png")
  22. world.select = love.graphics.newImage("img/tiles/select.png")
  23. end
  24. -- render the world
  25. function world.render(offset)
  26. for x = 1, world.width do
  27. for y = 1, world.height do
  28. local tile = world[x][y]
  29. local loc = util.cartToIso({x = x, y = y})
  30. if tile == "grass" then
  31. image = world.grass
  32. elseif tile == "dirt" then
  33. image = world.dirt
  34. elseif tile == "water" then
  35. image = world.water
  36. else
  37. image = world.nothing
  38. end
  39. love.graphics.draw(image, loc.x * 16 + offset.x, loc.y * 16 + offset.y)
  40. end
  41. end
  42. end
  43. return world