-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBackground.js
86 lines (76 loc) · 2.68 KB
/
Background.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import Canvas from './Canvas';
import Door from './Door';
import Room from './CanvasElements/Room';
export default class Background extends Canvas {
canvasRect = null;
constructor() {
super();
this.canvas = document.getElementById('canvas-background');
this.ctx = this.canvas.getContext('2d');
this.canvas.width = this.dimensions;
this.canvas.height = this.dimensions;
this.doorMin = this.dimensions * (5/12);
this.doorMax = this.dimensions * (7/12);
this.canvasRect = this.canvas.getBoundingClientRect();
}
draw() {
this.clear();
let id = global.player.room
this.ctx.lineWidth = 20;
this.drawWalls();
this.drawDoors(id);
this.drawMarkers();
}
drawWalls() {
this.ctx.beginPath();
this.ctx.strokeStyle = 'black';
this.ctx.moveTo(0, 0);
this.ctx.lineTo(this.doorMin, 0);
this.ctx.moveTo(this.doorMax, 0);
this.ctx.lineTo(this.canvas.width, 0);
this.ctx.lineTo(this.canvas.width, this.doorMin);
this.ctx.moveTo(this.canvas.width, this.doorMax);
this.ctx.lineTo(this.canvas.width, this.canvas.height);
this.ctx.lineTo(this.doorMax, this.canvas.height);
this.ctx.moveTo(this.doorMin, this.canvas.height);
this.ctx.lineTo(0, this.canvas.height);
this.ctx.lineTo(0, this.doorMax);
this.ctx.moveTo(0, this.doorMin);
this.ctx.lineTo(0, 0);
this.ctx.stroke();
}
drawDoors(id) {
let upDoor = new Door('up');
let rightDoor = new Door('right');
let downDoor = new Door('down');
let leftDoor = new Door('left');
if(Room.rooms[id].up) {
upDoor.status = 'active'
}
if(Room.rooms[id].right) {
rightDoor.status = 'active'
}
if(Room.rooms[id].down) {
downDoor.status = 'active'
}
if(Room.rooms[id].left) {
leftDoor.status = 'active'
}
upDoor.draw()
rightDoor.draw()
downDoor.draw()
leftDoor.draw()
}
drawMarkers() {
const markerImage = document.getElementById('marker');
let self = this;
Object.keys(Room.rooms[global.player.room].markers).forEach(function(index) {
let marker = Room.rooms[global.player.room].markers[index];
self.ctx.beginPath();
self.ctx.drawImage(markerImage, marker.x - marker.radius, marker.y - marker.radius, marker.width, marker.height);
self.ctx.arc(marker.x, marker.y, marker.radius, 0, Math.PI * 2);
self.ctx.fillStyle = 'transparent';
self.ctx.fill();
})
}
}