-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoint.js
More file actions
47 lines (34 loc) · 1.16 KB
/
point.js
File metadata and controls
47 lines (34 loc) · 1.16 KB
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
'use strict';
function Point (canvas, x, speed) {
var self = this;
self.canvasElement = canvas;
self.size = 35;
self.y = 0 - self.size;
self.x = x;
self.speed = speed;
self.pointImage = new Image();
self.pointsChoices = ["./images/beer.png","./images/coffe.png","./images/pingpong.png"];
self.pointImage.src = self.getRandomImage();
self.ctx = self.canvasElement.getContext('2d');
}
Point.prototype.getRandomImage = function () {
var self = this;
var randomNum = Math.floor(Math.random() * self.pointsChoices.length);
return self.pointsChoices[randomNum];
};
Point.prototype.update = function () {
var self = this;
self.y = self.y + self.speed;
};
Point.prototype.draw = function () {
var self = this;
self.ctx.fillStyle = '#299B41';
self.xPosition = self.x - (self.size/2);
self.yPosition = self.y - (self.size/2);
self.ctx.drawImage(self.pointImage, self.xPosition, self.yPosition, self.size, self.size);
};
Point.prototype.isInScreen = function () {
var self = this;
// if x is smaller than 0 remove from the arry
return self.canvasElement.height + self.size / 2 > 0;
};