-
Notifications
You must be signed in to change notification settings - Fork 0
/
apple.js
56 lines (47 loc) · 1 KB
/
apple.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
var APPLE_HEIGHT = 20
var APPLE_WIDTH = 20
function Apple()
{
this.x = random(20, width-20);
//this.x = 200;
this.y = 0;
this.gravity = 0.07;
this.velocity = 0;
//this.IsPoison = false;
this.IsPoison = random([false,true]);
this.show = function()
{
if (this.IsPoison)
{
fill(138, 43, 226);
}
else
{
fill(255,0,0);
}
ellipse(this.x, this.y, APPLE_WIDTH, APPLE_HEIGHT);
};
this.update = function()
{
this.velocity += this.gravity;
this.y += this.velocity;
}
this.hit = function(human)
{
if (this.x > human.x && this.x < human.x + HUMAN_WIDTH)
{
if (this.y > human.y)
{
this.isHit = true;
return true;
}
}
return false;
};
this.hasPassed = function()
{
if (this.y - APPLE_HEIGHT > height)
return true;
return false;
};
}