Some indoor tiles + basic other area loading
Getty Ritter
7 years ago
50 | 50 | end |
51 | 51 | end |
52 | 52 | |
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 | ||
53 | 60 | function Board:lookup(x, y) |
54 | 61 | if 0 <= x and x < consts.boardWidth then |
55 | 62 | return self.base[y * consts.boardWidth + x] |
4 | 4 | local Entity = {} |
5 | 5 | Entity.__index = Entity |
6 | 6 | |
7 |
function Entity:new( |
|
7 | function Entity:new(state, x, y, name) | |
8 | 8 | local file = io.open('entities/' .. name .. '.lua') |
9 | 9 | local char_data = loadstring('return' .. file:read('*all'))() |
10 | 10 | |
14 | 14 | end |
15 | 15 | |
16 | 16 | local t = { |
17 |
|
|
17 | state = state, | |
18 | 18 | x = x, |
19 | 19 | y = y, |
20 | 20 | dx = 0, |
33 | 33 | local alignX = ((self.x + dx) % consts.tileSize) == 0 |
34 | 34 | local alignY = ((self.y + dy) % consts.tileSize) == 0 |
35 | 35 | |
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) | |
40 | 40 | |
41 | 41 | if alignX and alignY then |
42 | 42 | return a |
54 | 54 | local bx = math.floor(self.x / consts.tileSize) |
55 | 55 | local by = math.floor(self.y / consts.tileSize) |
56 | 56 | |
57 |
return board:lookupEntity(bx + self.direction[1], |
|
57 | return board:lookupEntity(bx + self.direction[1], | |
58 | by + self.direction[2]) | |
58 | 59 | end |
59 | 60 | |
60 | 61 | function Entity:move(board) |
61 | 62 | local movement = true |
62 | 63 | |
63 |
|
|
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) | |
64 | 67 | |
65 | 68 | if self.dx == 0 and self.dy == 0 then |
66 | 69 | return |
118 | 121 | end |
119 | 122 | end |
120 | 123 | 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 | |
121 | 129 | end |
122 | 130 | |
123 | 131 | 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 | } |
5 | 5 | local event = require 'event' |
6 | 6 | local menu = require 'menu' |
7 | 7 | local draw = require 'draw' |
8 |
local state = { |
|
8 | local state = { | |
9 | loadMap = function(self, name) | |
10 | self.board = board.loadBoard(name) | |
11 | end | |
12 | } | |
9 | 13 | |
10 | 14 | local sprites = {} |
11 | 15 | |
20 | 24 | |
21 | 25 | state.board = board.loadBoard('sample.map') |
22 | 26 | state.char = entity.Entity:new( |
23 |
state |
|
27 | state, 3 * 24, 3 * 24, 'character') | |
24 | 28 | |
25 | 29 | state.canvas = love.graphics.newCanvas( |
26 | 30 | consts.boardWidth * consts.tileSize, |
2 | 2 | {"grass"}, {"grass"}, {"grass"}, {"stonepath"}, {"grass"}, {"water"}, {"water"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, |
3 | 3 | {"grass"}, {"grass"}, {"water"}, {"stonepath"}, {"water"}, {"water"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass", "pine_upper"}, {"grass", "house_nw"}, {"grass", "house_nc"}, {"grass", "house_ne"}, {"grass"}, |
4 | 4 | {"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=" |
|
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"}, | |
6 | 6 | {"grass"}, {"water"}, {"grass"}, {"stonepath"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"grass"}, {"stonepath"}, {"grass"}, {"grass"}, |
7 | 7 | {"grass"}, {"water"}, {"grass"}, {"stonepath"}, {"grass"}, {"grass"}, {"grass", "sign"}, {"stonepath"}, {"stonepath"}, {"stonepath"}, {"stonepath"}, {"stonepath"}, {"stonepath"}, {"stonepath"}, {"grass"}, {"grass"}, |
8 | 8 | {"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"}, |
48 | 48 | return setmetatable(t, Tile) |
49 | 49 | end |
50 | 50 | |
51 |
function Tile:action( |
|
51 | function Tile:action(self, state) | |
52 | end | |
53 | ||
54 | function Tile:enterTile(self, state) | |
52 | 55 | end |
53 | 56 | |
54 | 57 | function tileAnimation(self, x, y, t) |
Binary diff not shown
Binary diff not shown