Exemplo n.º 1
0
 public override CharacterEnums.ECharacterAction determineAction(HittableCharacter me, HittableTarget frontEnemy)
 {
     if (me.facing == CharacterEnums.EDirection.RIGHT)
     {
         if (me.getFrontLocationX() + meleeAttackDistance >= frontEnemy.getFrontLocationX())
         {
             return(CharacterEnums.ECharacterAction.MELEEATTACK);
         }
         if (me.getFrontLocationX() + rangedAttackDistance >= frontEnemy.getFrontLocationX())
         {
             return(CharacterEnums.ECharacterAction.RANGEATTACK);
         }
     }
     else
     {
         if (me.getFrontLocationX() - meleeAttackDistance <= frontEnemy.getFrontLocationX())
         {
             return(CharacterEnums.ECharacterAction.MELEEATTACK);
         }
         if (me.getFrontLocationX() - rangedAttackDistance <= frontEnemy.getFrontLocationX())
         {
             return(CharacterEnums.ECharacterAction.RANGEATTACK);
         }
     }
     return(CharacterEnums.ECharacterAction.WALKFORWARD);
 }
Exemplo n.º 2
0
 /** altered attack method to spawn projectiles on ranged attack */
 protected override void attack(HittableTarget target, Boolean isMelee, Castle enemy)
 {
     if (canAttackType == CharacterEnums.EType.BOTH || canAttackType == target.myType || target.myType == CharacterEnums.EType.BOTH)
     {
         attackCounter++;
         if (attackCounter >= getAttackCount())
         {
             attackCounter = 0;
             if (isMelee)
             {
                 Logger.d(ToString() + " attacked " + target.ToString() + "(Melee " + getMeleeDamage() + " dmg)");
                 target.getHit(getMeleeDamage());
             }
             else
             {
                 Rectangle r            = getLocation();
                 int       bulletHeight = (int)(r.Center.Y + r.Height / getOffSetDivisor());
                 Logger.d(ToString() + " attacked " + target.ToString() + "(Ranged " + getRangedDamage() + " dmg)");
                 if (getFrontLocationX() > target.getFrontLocationX())
                 {
                     projectiles.Add((Projectile)Activator.CreateInstance(getProjectileType(),
                                                                          new object[] { CharacterEnums.EDirection.LEFT, new Vector2(getFrontLocationX(), bulletHeight),
                                                                                         getRangedDamage(), target, enemy }));
                 }
                 else
                 {
                     projectiles.Add((Projectile)Activator.CreateInstance(getProjectileType(),
                                                                          new object[] { CharacterEnums.EDirection.RIGHT, new Vector2(getFrontLocationX(), bulletHeight),
                                                                                         getRangedDamage(), target, enemy }));
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
 /** returns true when hit payload */
 public override Boolean update()
 {
     if (moving == CharacterEnums.EDirection.LEFT)
     {
         location.X -= getSpeed();
         if (location.X <= target.getFrontLocationX())
         {
             hitTarget();
             return(true);
         }
     }
     else if (moving == CharacterEnums.EDirection.RIGHT)
     {
         location.X += getSpeed();
         if (location.X >= target.getFrontLocationX())
         {
             hitTarget();
             return(true);
         }
     }
     return(false);
 }