-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblock.js
More file actions
38 lines (34 loc) · 1.21 KB
/
Copy pathblock.js
File metadata and controls
38 lines (34 loc) · 1.21 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
function Block(position, image) {
this.position = position;
this.image = image;
this.width = 20;
this.height = 20;
this.speed_x = 10;
this.speed_y = 10;
this.increment_block_position = function(amount_x,amount_y) {
this.position.increment_position(amount_x,amount_y);
};
this.render = function(ctx) {
ctx.drawImage(image, this.get_position().get_x(),
this.get_position().get_y(), this.get_width(), this.get_height());
}
this.apply_touch_wall = function(canvas,player) {
if(this.get_position().get_x() < 0) {
this.set_position(new Position(0, this.get_position().get_y()));
player.increment_score();
this.reverse_x_speed();
} else if(this.get_position().get_x() > canvas.width) {
this.set_position(new Position(canvas.width, this.get_position().get_y()));
player.increment_score();
this.reverse_x_speed();
} else if(this.get_position().get_y() < 0) {
this.set_position(new Position(this.get_position().get_x(),0));
this.reverse_y_speed();
} else if(this.get_position().get_y() > canvas.height) {
this.set_position(new Position(this.get_position().get_x(),canvas.height));
this.reverse_y_speed();
}
};
};
Block.prototype = new Game_object();
Block.prototype.constructor = Block;