-
Notifications
You must be signed in to change notification settings - Fork 0
/
Apple.js
45 lines (39 loc) · 960 Bytes
/
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
/**
* Apple class constructor
* @param Ground ground
* @param int x
* @param int y
*/
function Apple(ground, x, y){
//The ground for the apple
this.ground = ground;
//The apple's position
this.point = new Point(x,y);
//If the apple is good (more points) or bad (less points)
this.isBad = false;
//The time life for bad apples
this.timeLife = 30;
}
/**
* Apple class definition
*/
Apple.prototype = {
/**
* Draw the applen on the ground
*/
draw: function(){
var ctx = this.ground.ctx;
var midBlock = parseInt(this.ground.blockSize/2)
var radius = 8;
if(this.isBad){
ctx.fillStyle = '#F00';
}else{
ctx.fillStyle = '#00F';
}
ctx.beginPath();
ctx.arc(this.point.x+midBlock, this.point.y+midBlock,
this.ground.blockSize/1.5, 0, Math.PI*2, false);
ctx.closePath();
ctx.fill();
}
};