I do have base classes because I intended to make different types of enemies from the begginig.Can I have a feedback on this? Also, I am trying to implement a cooldown to my characters because the game is to easy. Can I use time passed?
public class Unit : Basic2D
{
protected bool isDead;
protected float speed;
protected float attackArea;
protected int damage;
protected int currentHealth, healthMax;
protected int scoreAwarded;
protected int ownerId;
protected int projectilesOnScreen;
protected int maxProjectilesOnScreen;
protected float range; //how long can the unit shoot projectiles
public Unit(string _path, Vector2 _position, Vector2 _dimensions,int _ownerId) : base(_path, _position, _dimensions)
{
isDead = false;
ownerId = _ownerId;
}
public int GetDamage()
{
return damage;
}
public float GetAttackArea()
{
return attackArea;
}
public bool IsDead()
{
return isDead;
}
public int GetHealth()
{
return currentHealth;
}
public int GetHealthMax()
{
return healthMax;
}
public float GetSpeed()
{
return speed;
}
public int GetScoreAwarded()
{
return scoreAwarded;
}
public int GetProjectilesOnScreen()
{
return projectilesOnScreen;
}
public void SetProjectilesOnScreen(int _projectiles)
{
projectilesOnScreen = _projectiles;
}
public float GetRange()
{
return range;
}
public int GetOwnerId()
{
return ownerId;
}
public void SetOwnerId(int _ownerId)
{
ownerId = _ownerId;
}
public virtual void Update(Vector2 _offset,Player _player)
{
base.Update(_offset);
}
public virtual void GetHit(int _damageTaken)
{
if (_damageTaken >= currentHealth)
{
currentHealth = 0;
isDead = true;
}
else
{
currentHealth -= _damageTaken;
}
}
public override void Draw(Vector2 _offset)
{
base.Draw(_offset);
}
}
public class Enemy : Unit
{
public Enemy(string _path, Vector2 _position, Vector2 _dimensions, int _id) : base(_path, _position, _dimensions,_id)
{
}
public override void Update(Vector2 _offset, Player _player)
{
ArtificialIntelligence(_player.GetCharacter());
base.Update(_offset);
}
//the enemy will move to the point where the player currently is
public virtual void ArtificialIntelligence(Character _character)
{
SetPosition(GetPosition() + Globals.RadialMovement(_character.GetPosition(), this.GetPosition(), this.speed));
SetRotation(Globals.RotateTowards(this.GetPosition(), _character.GetPosition()));
if(Vector2.Distance(this.GetPosition(), _character.GetPosition()) < this.GetAttackArea())
{
_character.GetHit(GetDamage());
isDead = true;
}
}
public override void Draw(Vector2 _offset)
{
base.Draw(_offset);
}
}
public class Character : Unit
{
public Character(string _path, Vector2 _position, Vector2 _dimensions,int _ownerId) : base(_path, _position, _dimensions,_ownerId)
{
projectilesOnScreen = 0;
}
public override void Update(Vector2 _offset)
{
bool checkScroll = false;
if (Globals.keyboard.GetPress("A"))
{
SetPosition(new Vector2(GetPosition().X - speed, GetPosition().Y));
checkScroll = true;
}
if (Globals.keyboard.GetPress("D"))
{
SetPosition(new Vector2(GetPosition().X + speed, GetPosition().Y));
checkScroll = true;
}
if (Globals.keyboard.GetPress("W"))
{
SetPosition(new Vector2(GetPosition().X, GetPosition().Y - speed)); //Y is inverted, this means that 0 is on top .So if the player wants to go up Y has do decrease
checkScroll = true;
}
if (Globals.keyboard.GetPress("S"))
{
SetPosition(new Vector2(GetPosition().X, GetPosition().Y + speed)); //Again, Y is inverted
checkScroll = true;
}
if (checkScroll)
{
GameGlobals.CheckScroll(GetPosition());
}
SetRotation(Globals.RotateTowards(GetPosition(), new Vector2(Globals.mouseControl.newMousePos.X, Globals.mouseControl.newMousePos.Y) - _offset));
}
public override void Draw(Vector2 _offset)
{
base.Draw(_offset);
}
}