tile.lua 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. Tile = class()
  2. Tile.lit = false -- 🔥️⃠
  3. -- required: solid (bool)
  4. -- room being a list of all of the other tiles in a room (as references!)
  5. function Tile:init(x, y, char, room)
  6. self.x = x
  7. self.y = y
  8. self.char = char
  9. self.room = room
  10. end
  11. function Tile:draw(grid)
  12. if self.lit then
  13. grid[self.y][self.x] = self
  14. end
  15. end
  16. function Tile:light(world)
  17. for k, v in pairs(self.room) do
  18. world.grid[v.y][v.x].lit = true
  19. end
  20. for y = self.y - 1, self.y + 1 do
  21. for x = self.x - 1, self.x + 1 do
  22. world.grid[y][x].lit = true
  23. end
  24. end
  25. end
  26. function Tile:update(world)
  27. end
  28. function Tile:collide(world)
  29. end
  30. Air = class(Tile)
  31. Air.solid = false
  32. Air.color = COLOR.GRAY
  33. Wall = class(Tile)
  34. Wall.solid = true
  35. Stair = class(Tile)
  36. Stair.solid = false
  37. Stair.stair = true
  38. Stair.color = COLOR.WHITE
  39. function Stair:collide(world)
  40. world.message = "Press > to enter stairway."
  41. end
  42. Chest = class(Tile)
  43. Chest.solid = false
  44. Chest.chest = true
  45. Chest.color = COLOR.CHEST
  46. function getRandomItem(world)
  47. local pick = function(t, notThis)
  48. local x = t[love.math.random(1, #t)]
  49. if x == notThis then
  50. return pick(t, notThis)
  51. else
  52. return x
  53. end
  54. end
  55. local item = ''
  56. for i = 1, love.math.random(1, 2) do
  57. item = item .. pick(ITEM_NAMES.ADJECTIVE) .. ' '
  58. end
  59. item = item .. pick(ITEM_NAMES.NOUN)
  60. if love.math.random(1, 2) == 1 then
  61. local descr = pick(ITEM_NAMES.DESCRIPTION)
  62. item = item .. ' of ' .. descr
  63. if love.math.random(1, 2) == 1 then
  64. item = item .. ' and ' .. pick(ITEM_NAMES.DESCRIPTION, descr)
  65. end
  66. end
  67. local ltr = string.sub(item, 1, 1)
  68. world.message = 'You got '
  69. if love.math.random(1, 4) == 1 then
  70. world.message = world.message .. 'the'
  71. -- OH GOSH I'M LAZY
  72. elseif ltr == 'A' or ltr == 'O' or ltr == 'E' or ltr == 'I' or ltr == 'U' then
  73. world.message = world.message .. 'an'
  74. else
  75. world.message = world.message .. 'a'
  76. end
  77. world.message = world.message .. ' ' .. item .. '!'
  78. world.player.treasure = world.player.treasure + 1
  79. sounds.item:play()
  80. end
  81. function Chest:collide(world)
  82. world.grid:set(self.x, self.y, Air, '.')
  83. getRandomItem(world)
  84. end