-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDrawer.jack
More file actions
55 lines (48 loc) · 1.18 KB
/
Drawer.jack
File metadata and controls
55 lines (48 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/** Implements drawing the games elements */
class Drawer {
/** Draws the grid */
function void grid() {
var int x, y, i, j;
let x = 208;
let y = 226;
do Screen.setColor(true);
while (i < 8) {
do Screen.drawLine(x, 16, x, 226);
let x = x + 14;
let i = i + 1;
}
while (j < 16) {
do Screen.drawLine(208, y, 306, y);
let y = y - 14;
let j = j + 1;
}
return;
}
/** Draws a row given the block arrangement (row) and the level */
function void row(Array row, int level) {
var int col;
let col = 0;
while (col < Constants.COLS()) {
if (row[col]) {
do Drawer.block(col, level, true);
} else {
do Drawer.block(col, level, false);
}
let col = col + 1;
}
return;
}
/** Draws a block at an offset (xoff, yoff) to the bottom left block in
* black or white (isBlack)
*/
function void block(int xoff, int yoff, boolean isBlack) {
var int i, addr, x, y;
let i = 0;
let addr = 16896;
let x = 210 + (xoff * 14);
let y = 214 - (yoff * 14);
do Screen.setColor(isBlack);
do Screen.drawRectangle(x, y, x + 10, y + 10);
return;
}
}