gdritter repos animaltransiro / 8f4a6a9
Factored out drawing code into separate file Getty Ritter 6 years ago
5 changed file(s) with 68 addition(s) and 47 deletion(s). Collapse all Expand all
99 base = {},
1010 entity = {},
1111 }
12 for x = 0, consts.boardWidth do
13 for y = 0, consts.boardHeight do
12 for x = 0, consts.boardWidth - 1 do
13 for y = 0, consts.boardHeight - 1 do
1414 t.base[x * consts.boardWidth + y] = tile.getTile('grass')
1515 t.entity[x * consts.boardWidth + y] = nil
1616 end
1 local consts = require 'constants'
2
3 function drawAll(state)
4 -- create a canvas to blit to
5 love.graphics.setCanvas(state.canvas)
6
7 -- draw the board background
8 for x = 0, consts.boardWidth - 1 do
9 for y = 0, consts.boardHeight - 1 do
10 state.board:lookup(x, y):draw(x, y, state.t)
11 end
12 end
13
14 -- draw the entities
15 for x = 0, consts.boardWidth - 1 do
16 for y = 0, consts.boardHeight - 1 do
17 -- if the character is in this space, draw it first
18 -- XXX: extend this to mobile entities in general
19 local sX, sY = state.char:gameCoords()
20 if sX == x and sY == y then
21 state.char:draw()
22 end
23 -- if an entity is in this space, draw it
24 local e = state.board:lookupEntity(x, y)
25 if e then e:draw(x, y, state.t) end
26 end
27 end
28
29 -- if we've got dialogue up, then show that, too
30 -- XXX: factor this out!
31 if state.message then
32 love.graphics.setColor(255, 255, 255)
33 local w = consts.boardWidth * consts.tileSize
34 local h = consts.boardHeight * consts.tileSize / 2
35 love.graphics.rectangle('fill', 8, 8 + h, w - 16, h - 16)
36 love.graphics.setColor(0, 0, 0)
37 love.graphics.print(state.message, 12, h + 12)
38 end
39
40 -- print the debug message
41 love.graphics.setColor(255, 255, 255)
42 love.graphics.print(debug, 8, 8)
43
44 love.graphics.setCanvas()
45 -- blank out the screen
46 love.graphics.setColor(255, 255, 255)
47 love.graphics.rectangle('fill', 0, 0,
48 love.graphics.getWidth(),
49 love.graphics.getHeight())
50
51 love.graphics.setColor(255, 255, 255)
52
53 -- blit the smaller canvas back onto the larger screen
54 love.graphics.draw(state.canvas, 0, 0, 0, 2, 2)
55
56 end
57
58 return { drawAll = drawAll }
44 local tile = require 'tile'
55 local event = require 'event'
66 local menu = require 'menu'
7 local draw = require 'draw'
78 local state = {}
89
910 local sprites = {}
6869 end
6970
7071 function love.draw()
71 love.graphics.setColor(0, 0, 0)
72 love.graphics.rectangle('fill', 0, 0,
73 love.graphics.getWidth(),
74 love.graphics.getHeight())
75
76 love.graphics.setColor(255, 255, 255)
77
78 love.graphics.setCanvas(state.canvas)
79
80 for x = 0, consts.boardWidth, 1 do
81 for y = 0, consts.boardHeight, 1 do
82 state.board:lookup(x, y):draw(x, y, state.t)
83 end
84 end
85
86 for x = 0, consts.boardWidth, 1 do
87 for y = 0, consts.boardHeight, 1 do
88 local e = state.board:lookupEntity(x, y)
89 if e then e:draw(x, y, state.t) end
90 local sX, sY = state.char:gameCoords()
91 if sX == x and sY == y then
92 state.char:draw()
93 end
94 end
95 end
96
97 if state.message then
98 local w = consts.boardWidth * consts.tileSize
99 local h = consts.boardHeight * consts.tileSize / 2
100 love.graphics.rectangle('fill', 8, 8 + h, w - 16, h - 16)
101 love.graphics.setColor(0, 0, 0)
102 love.graphics.print(state.message, 12, h + 12)
103 end
104
105 love.graphics.print(debug, 8, 8)
106
107 love.graphics.setCanvas()
108
109 love.graphics.setColor(255, 255, 255)
110 love.graphics.rectangle('fill', 0, 0,
111 love.graphics.getWidth(),
112 love.graphics.getHeight())
113
114 love.graphics.draw(state.canvas, 0, 0, 0, 2, 2)
72 draw.drawAll(state)
11573 end
7979 return tileCache[name]
8080 end
8181
82 local function allTiles()
83 return tileCache
84 end
85
8286 local nilTile = {
8387 pass = false,
8488 name = 'nil',
8993
9094 return {
9195 getTile = getTile,
96 allTiles = allTiles,
9297 nilTile = nilTile,
9398 }
33 name = 'water',
44 spriteX = 5,
55 spriteY = 0,
6 animation = { {5, 0}, {6, 0}, {7, 0} },
6 animation = { {5, 0}, {6, 0}, {7, 0}, {6, 0} },
77 }