Factored out drawing code into separate file
Getty Ritter
7 years ago
9 | 9 | base = {}, |
10 | 10 | entity = {}, |
11 | 11 | } |
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 | |
14 | 14 | t.base[x * consts.boardWidth + y] = tile.getTile('grass') |
15 | 15 | t.entity[x * consts.boardWidth + y] = nil |
16 | 16 | 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 } |
4 | 4 | local tile = require 'tile' |
5 | 5 | local event = require 'event' |
6 | 6 | local menu = require 'menu' |
7 | local draw = require 'draw' | |
7 | 8 | local state = {} |
8 | 9 | |
9 | 10 | local sprites = {} |
68 | 69 | end |
69 | 70 | |
70 | 71 | 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) | |
115 | 73 | end |