Spaces:
Running
Running
Create enemy.js
Browse files
enemy.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class Enemy {
|
| 2 |
+
constructor(x, y) {
|
| 3 |
+
this.x = x;
|
| 4 |
+
this.y = y;
|
| 5 |
+
this.size = 30;
|
| 6 |
+
this.speed = 1;
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
update() {
|
| 10 |
+
this.move();
|
| 11 |
+
this.draw();
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
move() {
|
| 15 |
+
this.y += this.speed;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
draw() {
|
| 19 |
+
ctx.beginPath();
|
| 20 |
+
ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
|
| 21 |
+
ctx.fillStyle = 'red';
|
| 22 |
+
ctx.fill();
|
| 23 |
+
}
|
| 24 |
+
}
|