gdritter repos animaltransiro / a114db3
Some indoor tiles + basic other area loading Getty Ritter 6 years ago
13 changed file(s) with 78 addition(s) and 12 deletion(s). Collapse all Expand all
5050 end
5151 end
5252
53 function Board:enterSquare(x, y, state)
54 if 0 <= x and x < consts.boardWidth then
55 local e = self.entity[y * consts.boardWidth + x]
56 if e then e:enterTile(state) end
57 end
58 end
59
5360 function Board:lookup(x, y)
5461 if 0 <= x and x < consts.boardWidth then
5562 return self.base[y * consts.boardWidth + x]
44 local Entity = {}
55 Entity.__index = Entity
66
7 function Entity:new(board, x, y, name)
7 function Entity:new(state, x, y, name)
88 local file = io.open('entities/' .. name .. '.lua')
99 local char_data = loadstring('return' .. file:read('*all'))()
1010
1414 end
1515
1616 local t = {
17 board = board,
17 state = state,
1818 x = x,
1919 y = y,
2020 dx = 0,
3333 local alignX = ((self.x + dx) % consts.tileSize) == 0
3434 local alignY = ((self.y + dy) % consts.tileSize) == 0
3535
36 local a = self.board:passable(bx, by)
37 local b = self.board:passable(bx + 1, by)
38 local c = self.board:passable(bx, by + 1)
39 local d = self.board:passable(bx + 1, by + 1)
36 local a = self.state.board:passable(bx, by)
37 local b = self.state.board:passable(bx + 1, by)
38 local c = self.state.board:passable(bx, by + 1)
39 local d = self.state.board:passable(bx + 1, by + 1)
4040
4141 if alignX and alignY then
4242 return a
5454 local bx = math.floor(self.x / consts.tileSize)
5555 local by = math.floor(self.y / consts.tileSize)
5656
57 return board:lookupEntity(bx + self.direction[1], by + self.direction[2])
57 return board:lookupEntity(bx + self.direction[1],
58 by + self.direction[2])
5859 end
5960
6061 function Entity:move(board)
6162 local movement = true
6263
63 debug = string.format(' {x=%d, y=%d, gx=%d, gy=%d}\n', self.x, self.y, self:gameCoords())
64 local gX, gY = self:gameCoords()
65 debug = string.format(' {x=%d, y=%d, gx=%d, gy=%d}\n',
66 self.x, self.y, gX, gY)
6467
6568 if self.dx == 0 and self.dy == 0 then
6669 return
118121 end
119122 end
120123 end
124
125 local nX, nY = self:gameCoords()
126 if nX ~= gX or nY ~= gY then
127 self.state.board:enterSquare(nX, nY, self.state)
128 end
121129 end
122130
123131 function Entity:draw()
1 {
2 {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"},
3 {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"},
4 {"black"}, {"black"}, {"black"}, {"bwtile", "curtain"}, {"bwtile", "curtain"}, {"bwtile", "curtain"}, {"bwtile", "curtain"}, {"bwtile", "curtain"}, {"bwtile", "curtain"}, {"bwtile", "curtain"}, {"bwtile", "curtain"}, {"bwtile", "curtain"}, {"bwtile", "curtain"}, {"black"}, {"black"}, {"black"},
5 {"black"}, {"black"}, {"black"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"black"}, {"black"}, {"black"},
6 {"black"}, {"black"}, {"black"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"black"}, {"black"}, {"black"},
7 {"black"}, {"black"}, {"black"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"black"}, {"black"}, {"black"},
8 {"black"}, {"black"}, {"black"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"black"}, {"black"}, {"black"},
9 {"black"}, {"black"}, {"black"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"black"}, {"black"}, {"black"},
10 {"black"}, {"black"}, {"black"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"bwtile"}, {"black"}, {"black"}, {"black"},
11 {"black"}, {"black"}, {"black"}, {"bwtile", "front_black"}, {"bwtile", "front_black"}, {"bwtile", "front_black"}, {"bwtile", "front_black"}, {"bwtile", "front_door", enterTile=function(self, state) state:loadMap('sample.map');state.char.x = 312 state.char.y = 96 end}, {"bwtile", "front_black"}, {"bwtile", "front_black"}, {"bwtile", "front_black"}, {"bwtile", "front_black"}, {"bwtile", "front_black"}, {"black"}, {"black"}, {"black"},
12 {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"},
13 {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"}, {"black"},
14 }
55 local event = require 'event'
66 local menu = require 'menu'
77 local draw = require 'draw'
8 local state = {}
8 local state = {
9 loadMap = function(self, name)
10 self.board = board.loadBoard(name)
11 end
12 }
913
1014 local sprites = {}
1115
2024
2125 state.board = board.loadBoard('sample.map')
2226 state.char = entity.Entity:new(
23 state.board, 3 * 24, 3 * 24, 'character')
27 state, 3 * 24, 3 * 24, 'character')
2428
2529 state.canvas = love.graphics.newCanvas(
2630 consts.boardWidth * consts.tileSize,
22 {"grass"}, {"grass"}, {"grass"}, {"stonepath"}, {"grass"}, {"water"}, {"water"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"},
33 {"grass"}, {"grass"}, {"water"}, {"stonepath"}, {"water"}, {"water"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass", "pine_upper"}, {"grass", "house_nw"}, {"grass", "house_nc"}, {"grass", "house_ne"}, {"grass"},
44 {"grass"}, {"water"}, {"water", "pine_upper"}, {"stonepath"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass", "pine_lower"}, {"grass", "house_cw"}, {"grass", "house_cc"}, {"grass", "house_ce"}, {"grass", "pine_upper"},
5 {"grass"}, {"water"}, {"grass", "pine_lower"}, {"stonepath"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass", "sign", signText="This house doesn't do anything yet."}, {"grass", "house_sw"}, {"stonepath", "house_sc", action=function(self, state) state.message = "I'm sleeping! Go away!" end}, {"grass", "house_se"}, {"grass", "pine_lower"},
5 {"grass"}, {"water"}, {"grass", "pine_lower"}, {"stonepath"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass", "sign", signText="Probably best not to go in the house."}, {"grass", "house_sw"}, {"stonepath", "house_sc", enterTile=function(self, state) state:loadMap('interior.map') state.char.x = 168 state.char.y = 192 end}, {"grass", "house_se"}, {"grass", "pine_lower"},
66 {"grass"}, {"water"}, {"grass"}, {"stonepath"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"stonepath"}, {"grass"}, {"grass"},
77 {"grass"}, {"water"}, {"grass"}, {"stonepath"}, {"grass"}, {"grass"}, {"grass", "sign"}, {"stonepath"}, {"stonepath"}, {"stonepath"}, {"stonepath"}, {"stonepath"}, {"stonepath"}, {"stonepath"}, {"grass"}, {"grass"},
88 {"water"}, {"water"}, {"grass"}, {"stonepath"}, {"stonepath"}, {"stonepath"}, {"stonepath"}, {"stonepath"}, {"grass"}, {"grass", "sign", signText="This is an example of entity-specific\ninformation contained in the map file."}, {"grass"}, {"grass"}, {"grass", "tree_upper"}, {"grass"}, {"grass"}, {"grass"},
4848 return setmetatable(t, Tile)
4949 end
5050
51 function Tile:action()
51 function Tile:action(self, state)
52 end
53
54 function Tile:enterTile(self, state)
5255 end
5356
5457 function tileAnimation(self, x, y, t)
1 {
2 name = 'black',
3 pass = false,
4 spriteX = 31,
5 spriteY = 31,
6 }
1 {
2 name = 'bwtile',
3 pass = true,
4 spriteX = 4,
5 spriteY = 4,
6 }
1 {
2 name = 'curtain',
3 pass = false,
4 spriteX = 3,
5 spriteY = 4,
6 }
1 {
2 name = 'front black',
3 pass = false,
4 spriteX = 29,
5 spriteY = 31,
6 }
1 {
2 name = 'front door',
3 pass = true,
4 spriteX = 30,
5 spriteY = 31,
6 }
Binary diff not shown
Binary diff not shown