-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathloadScreen.ts
89 lines (80 loc) · 3.93 KB
/
loadScreen.ts
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
module tileworld {
const loadLeft = 3;
const loadTop = 1;
const numRows = 4;
export class LoadScreen extends RuleVisualsBase {
constructor() {
super(null);
controller.setRepeatDefault(500, 80);
controller.A.onEvent(ControllerButtonEvent.Pressed, () => {
const first = this.col() >= loadLeft && this.col() <= loadLeft+1;
const second = this.col() >= loadLeft+2 && this.col() <= loadLeft+3;
if ( ( first || second) && (this.row() > loadTop && this.row() <= loadTop+numRows) ) {
const slot = (this.row()-loadTop) + (first ? 0 : numRows);
const prefix = "TW"+slot.toString()+"-";
this.p = loadProject(prefix);
this.update();
if (!this.p) {
this.p = emptyProject(prefix);
this.p.saveProject();
}
this.lastDir = -1;
this.lastDir = -1;
game.pushScene();
new GameHome(this.p);
} else if (this.col() == 9 && this.row() == 0) {
game.pushScene();
new ProjectSettings(null);
}
});
this.update();
}
private lastDir: MoveDirection = -1;
protected cursorMove(dir: MoveDirection, pressed: boolean): void {
this.lastDir = pressed ? dir : -1;
}
private makeIt(col: number, row: number, id: string) {
const prefix = "TW" + id + "-";
const projectAvailable = settings.list(prefix).length > 0;
this.drawImage(col, row, diskIcon);
this.fillTile(col+1, row, (this.col() == col || this.col() == col + 1) && this.row() == row ? 7 :
(projectAvailable ? 6 : 12));
screen.print(id, ((col+1) << 4) + 6, (row << 4) + 4 + yoff);
}
protected update(): void {
for(let col = 0; col < 10; col ++) {
for (let row = 0; row < 7; row++) {
this.drawImage(col, row, emptyTile)
}
}
for(let i = 0; i < 10; i++) {
this.drawImage(i, 0, genericSprite);
this.drawImage(i, 6, genericSprite);
if (i > 6) continue;
this.drawImage(0, i, genericSprite);
this.drawImage(9, i, genericSprite);
}
for(let i = 0; i < 4; i++) {
this.fillTile(i,0,12);
}
this.drawImage(1, 6, this.lastDir == MoveDirection.Down ? downButton : utilities.greyImage(downButton));
this.drawImage(1, 4, this.lastDir == MoveDirection.Up ? upButton : utilities.greyImage(upButton));
this.drawImage(0, 5, this.lastDir == MoveDirection.Left ? leftButton : utilities.greyImage(leftButton));
this.drawImage(2, 5, this.lastDir == MoveDirection.Right ? rightButton : utilities.greyImage(rightButton));
screen.print("TileCode", 6, yoff + 4);
this.fillTile(loadLeft,loadTop,12); this.fillTile(loadLeft+1,loadTop,12);
screen.print("Load", (loadLeft << 4) + 4, (loadTop << 4) + 4 + yoff);
this.fillTile(loadLeft+2, loadTop, 12); this.fillTile(loadLeft+3, loadTop, 12);
screen.print("Game", ((loadLeft +2) << 4) + 4, (loadTop << 4) + 4 + yoff);
for(let r = 0; r<numRows; r++) {
this.makeIt(loadLeft, 2+r, (r + loadTop).toString());
this.makeIt(loadLeft+2, 2+r, (r + loadTop + numRows).toString());
}
this.drawImage(8, 4, player);
this.drawImage(8, 6, dog);
this.drawImage(7, 5, snakeHead);
this.drawImage(9, 5, enemy);
this.drawImage(9, 0, settingsIcon);
}
}
}