I am facing a challenge with my programming classes. I have two classes, "Player" and "Enemy", each with similar methods and properties. I want them to inherit from a parent class that I'll create called "Game Object".
How can I approach creating this inheritance structure?
I am working in Javascript and have attempted to research on my own but haven't fully grasped the concept yet.
class Enemy
{
constructor(sprite, positionX, positionY, speed)
{
this.sprite = sprite;
this.positionX = positionX;
this.positionY = positionY;
this.speed = speed;
this.direction = Math.floor(Math.random()*7) + 1;
this.direction *= Math.floor(Math.random()*2) == 1 ? 1 : -1;
this.active = false;
}
getCenterPoint()
{
return new Point(this.positionX + 16, this.positionY + 16);
}
}
class Player
{
constructor(sprite, positionX, positionY, speed)
{
this.sprite = sprite;
this.positionX = positionX;
this.positionY = positionY;
this.speed = speed;
this.animationFrame = true;
}
getCenterPoint()
{
return new Point(this.positionX + 16, this.positionY + 16);
}
}
I have not been able to achieve the desired results and would appreciate some guidance on how to proceed.