I'm learning JS, i created a class Entity
like this :
class Entity {
constructor(x=0, y=0, dx=0, dy=0, width=50, height=50, solid=false,
color="black", name="entity", id=Math.random()) {
this.x = x;
this.y = y;
this.dx = dx;
this.dy = dy;
this.width = width;
this.height = height;
this.solid = solid;
this.color = color;
this.name = name;
this.id = id;
entityList[id] = this;
}
UpdatePosition() {
this.x += this.dx;
this.y += this.dy;
}
Draw() {
ctx.save();
ctx.fillStyle = this.color;
ctx.fillRect(this.x, this.y, this.width, this.height);
ctx.restore();
}
BorderCollision() {
if (this.solid == true) {
if (this.x <= 0) {
this.dx = -this.dx;
}
if (this.x + this.width >= canvas.width) {
this.dx = -this.dx;
}
if (this.y <= 0) {
this.dy = -this.dy;
}
if (this.y + this.height >= canvas.height) {
this.dy = -this.dy;
}
}
}
EntityUpdate() {
this.UpdatePosition();
this.Draw();
this.BorderCollision();
}
}
And now, i want to extend this class in a new one called Player
who have a new member : canMove
But i don't know how to do a new constructor cause when i write constructor(canMove) {this.canMove = canMove; +}
i got an error :(
thanks ;) !