-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.js
84 lines (74 loc) · 2.04 KB
/
game.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
c.addEventListener("mousemove", changeCursor, false);
/**
* A clickable object
* inBounds returns true if co-ordinates are within the bounds of the object
*
* optional `canMouseOver` allowing a function to state whether an object can be
* moused over or not.
*
* The `canMouseOver` function should return a boolean.
*/
function GameObject(x1, x2, y1, y2, wall, click, canMouseOver) {
this.x1 = x1; this.x2 = x2;
this.y1 = y1; this.y2 = y2;
this.wall = wall;
this.click = click || function() {};
this.inBounds = function(x, y) {
return (this.x1 <= x && this.x2 >= x && this.y1 <= y && this.y2 >= y);
};
this.canMouseOver = canMouseOver || function() {return true;};
}
function clicked(e) {
e.preventDefault();
var x = e.clientX;
var y = e.clientY;
console.log("click: (" + x + ", " + y + ")");
for (var key in objects) {
if (objects[key].wall == currentWall) {
if (objects[key].inBounds(x,y)) {
console.log(key);
objects[key].click();
}
}
}
}
function changeCursor(e) {
e.preventDefault();
var rect = c.getBoundingClientRect();
var x = e.clientX - rect.left;
var y = e.clientY - rect.top;
// console.log("move: (" + x + ", " + y + ")");
if(currentWall==5 && eyeFollow==2){
if(x>625 && eyesX <= 614 ){
eyesX+=1;
}else if(x<625 && eyesX >=603){
eyesX-=1;
}
if(y>152 && eyesY <= 138 ){
eyesY+=1;
}else if(y<152 && eyesY >=136){
eyesY-=1;
}
//alert(eyesY);
ctx.putImageData(Background,300, 0);
ctx.drawImage(eyes,0,0, eyes.width,eyes.height,eyesX,eyesY,eyes.width,eyes.height);
}
function mouseoverobject() {
for (var key in objects) {
if (objects[key].wall == currentWall) {
if (objects[key].canMouseOver()) {
if (objects[key].inBounds(x,y)) {
return true;
}
}
}
}
return false;
}
if (mouseoverobject()) {
c.style.cursor = 'url(images/ScaldyHand.png), crosshair';
}
else {
c.style.cursor = 'default';
}
}