-
Notifications
You must be signed in to change notification settings - Fork 0
/
editor.js
65 lines (58 loc) · 2.05 KB
/
editor.js
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
class Editor {
constructor() {
this.selectedType = TileType.Rock;
this.tile = new Tile(mouseX, mouseY, this.selectedType);
this.tile.move = false;
this.tiles = [];
this.eraser = false;
}
display() {
for (let i in this.tiles) {
let tile = this.tiles[i];
tile.move = false;
tile.display();
}
if (this.eraser) {
image(assets.images.delete, mouseX - TILE_SIZE / 2, mouseY - TILE_SIZE / 2, TILE_SIZE, TILE_SIZE);
} else {
this.tile.display();
this.tile.type = this.selectedType;
this.tile.position.x = mouseX - TILE_SIZE / 2;
this.tile.position.y = mouseY - TILE_SIZE / 2;
}
}
mousePressed() {
if (this.eraser) {
this.tiles.forEach((element, index) => {
if (element.over(mouseX, mouseY)) {
this.tiles.splice(index, 1);
console.log("hmm");
}
});
} else if (mouseY > 0) {
this.tiles.push(new Tile(mouseX - TILE_SIZE / 2, mouseY - TILE_SIZE / 2, this.selectedType));
}
}
changeType(type) {
this.eraser = false;
this.selectedType = type;
}
randomizeTiles() {
for (let i = 0; i < random(25, 60); i++)
this.tiles.push(new Tile(random(width), random(height), Math.floor(random(3))));
}
start() {
state = State.Editor;
this.tiles = [];
document.getElementById("game-over-screen").style.display = "none";
document.getElementById("toolbar").childNodes.forEach((element) => {
if (element.id == 'start-game-button') { element.disabled = false; element.innerText = "Start Game"; return; }
element.disabled = false;
});
document.getElementById("win-images").children.forEach((element) => {
element.style.display = "none";
});
document.getElementById("rock").checked = true;
this.selectedType = TileType.Rock;
}
}