-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTeleport.js
66 lines (57 loc) · 1.5 KB
/
Teleport.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
/*global Colors*/
"use strict";
function Teleport() {
this.transparency = 1;
this.mouseOn = false;
this.right = 0;
this.safeOffset = 20;
this.active = false;
this.maxY = 45;
this.minY = 25;
this.rightOffset = 30;
}
Teleport.prototype.collide = function (absPos) {
var left = this.right - this.rightOffset,
right = this.right;
if (absPos.x > left && absPos.x < right) {
if (absPos.y > this.minY && absPos.y < this.maxY) {
return true;
}
}
return false;
};
Teleport.prototype.resize = function (right) {
this.right = right - this.rightOffset;
};
Teleport.prototype.fadeOut = function () {
var tranTresh = 0.15,
tranFade = 0.025;
if (this.mouseOn === false) {
if (this.transparency > tranTresh) {
this.transparency -= tranFade;
}
}
};
Teleport.prototype.draw = function (context) {
var right = this.right - this.safeOffset;
context.save();
context.font = '20px Calibri';
context.fillStyle = '#FFFFFF';
context.globalAlpha = this.transparency;
context.textAlign = "center";
context.fillText("T", right, 40);
context.restore();
context.restore();
};
Teleport.prototype.click = function () {
return this.mouseOn;
};
Teleport.prototype.deactivate = function () {
this.active = false;
};
Teleport.prototype.hoverButton = function (mousePos) {
this.mouseOn = this.collide(mousePos);
if (this.mouseOn) {
this.transparency = 1;
}
};