-
Notifications
You must be signed in to change notification settings - Fork 0
/
washer.js
89 lines (61 loc) · 2.19 KB
/
washer.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
87
88
89
function Washer()
{
//create div class item into washerBox
this.CreateNew = function()
{
this.div = document.createElement("div");
this.div.setAttribute("class","item");
$("#washerBox").append($(this.div));
this.x = $(this.div).position().left;
this.maxX= $("#washerBox").width();
$(this.div).click(function(){
var url = "url(red.jpg)";
$(this).css("background-image", url);
var pos = $(this).position().left;
totalScore +=1;
console.log(pos);
console.log("------------------");
$("#score").text(totalScore+" ");
punch();
});
$(this.div).keydown(function(e) {
if (e.keyCode == 40) {
punch();
alert("space pressed");
}
});
};
this.speed = 1.5;
this.Move = function()
{
if (this.x < this.maxX)
{
$(this.div).css("left", this.x+=this.speed);
}
else
{
$(this.div).remove();
}
};
}
function update()
{
var washer;
if ( frameCount ==0 ||gapBetween(150))
{
washer = new Washer();
washers.push(washer);
washer.CreateNew();
}
frameCount++;
for (var i=0; i<washers.length;i++)
{
washers[i].Move();
}
}
function gapBetween(n)
{
if (frameCount % n == 0) {return true;}
return false;
}
$(document).ready