123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- Tile = class()
- Tile.lit = false -- 🔥️⃠
- -- required: solid (bool)
- -- room being a list of all of the other tiles in a room (as references!)
- function Tile:init(x, y, char, room)
- self.x = x
- self.y = y
- self.char = char
- self.room = room
- end
- function Tile:draw(grid)
- if self.lit then
- grid[self.y][self.x] = self
- end
- end
- function Tile:light(world)
- for k, v in pairs(self.room) do
- world.grid[v.y][v.x].lit = true
- end
- for y = self.y - 1, self.y + 1 do
- for x = self.x - 1, self.x + 1 do
- world.grid[y][x].lit = true
- end
- end
- end
- function Tile:update(world)
- end
- function Tile:collide(world)
- end
- Air = class(Tile)
- Air.solid = false
- Air.color = COLOR.GRAY
- Wall = class(Tile)
- Wall.solid = true
- Stair = class(Tile)
- Stair.solid = false
- Stair.stair = true
- Stair.color = COLOR.WHITE
- function Stair:collide(world)
- world.message = "Press > to enter stairway."
- end
- Chest = class(Tile)
- Chest.solid = false
- Chest.chest = true
- Chest.color = COLOR.CHEST
- function getRandomItem(world)
- local pick = function(t, notThis)
- local x = t[love.math.random(1, #t)]
- if x == notThis then
- return pick(t, notThis)
- else
- return x
- end
- end
- local item = ''
- for i = 1, love.math.random(1, 2) do
- item = item .. pick(ITEM_NAMES.ADJECTIVE) .. ' '
- end
- item = item .. pick(ITEM_NAMES.NOUN)
- if love.math.random(1, 2) == 1 then
- local descr = pick(ITEM_NAMES.DESCRIPTION)
- item = item .. ' of ' .. descr
- if love.math.random(1, 2) == 1 then
- item = item .. ' and ' .. pick(ITEM_NAMES.DESCRIPTION, descr)
- end
- end
- local ltr = string.sub(item, 1, 1)
- world.message = 'You got '
- if love.math.random(1, 4) == 1 then
- world.message = world.message .. 'the'
- -- OH GOSH I'M LAZY
- elseif ltr == 'A' or ltr == 'O' or ltr == 'E' or ltr == 'I' or ltr == 'U' then
- world.message = world.message .. 'an'
- else
- world.message = world.message .. 'a'
- end
- world.message = world.message .. ' ' .. item .. '!'
- world.player.treasure = world.player.treasure + 1
- sounds.item:play()
- end
- function Chest:collide(world)
- world.grid:set(self.x, self.y, Air, '.')
- getRandomItem(world)
- end
|