public virtual void orderAttack(BuildingAndUnit e) { _target = e; if (typeof(SpriteEntity).IsAssignableFrom(e.GetType())) { if (e.Size >= 2) { Point a = new Point((int)e.Position.X / data.tSize(), (int)e.Position.Y / data.tSize()); if (e.Position.X < _position.X) { a.X += 2; } else if (e.Position.Y < _position.Y) { a.Y += 2; } orderMove(a); } else { orderMove(new Point((int)e.Position.X / data.tSize(), (int)e.Position.Y / data.tSize())); } } }
public void Defend(BuildingAndUnit e) { if (Agrorange(_position, e.Position) < data.tSize() * 5) { if (_target == null || _target.HitPoints <= 0) { orderAttack(e); } else if (typeof(Unit).IsAssignableFrom(e.GetType()) && typeof(StaticBuilding).IsAssignableFrom(_target.GetType())) { orderAttack(e); } else if (Agrorange(_position, _target.Position) > Agrorange(_position, e.Position)) { orderAttack(e); } } }
public Projectile(Level level, BuildingAndUnit target, Vector2 pos, int layer = 0) : base("", layer) { _level = level; _target = target; _delta = 10; _position = pos; _sprite = GameEnvironment.getAssetManager().GetSprite("Sprites/Units/rock"); /* * if (_shooter.Position.X < _target.Position.X) * { * if (_shooter.Position.Y > _target.Position.Y) * { * _rotation = (float)Math.Atan2((_target.Position.X - _shooter.Position.X), (_target.Position.Y - _shooter.Position.Y)); * Console.WriteLine(_rotation); * } * if(_shooter.Position.Y < _target.Position.Y) * { * _rotation = (float)Math.Atan2((_target.Position.X - _shooter.Position.X), (_target.Position.Y - _shooter.Position.Y)); * Console.WriteLine(_rotation); * } * } * if (_shooter.Position.X > _target.Position.X) * { * if (_shooter.Position.Y > _target.Position.Y) * { * _rotation = (float)Math.Atan2((_target.Position.X - _shooter.Position.X), (_target.Position.Y - _shooter.Position.Y)); * Console.WriteLine(_rotation); * } * if(_shooter.Position.Y < _target.Position.Y) * { * _rotation = (float)Math.Atan2((_target.Position.X - _shooter.Position.X), (_target.Position.Y - _shooter.Position.Y)); * Console.WriteLine(_rotation); * } * } */ // _rotation = (float)Math.Atan2(((_target.Position.X + _target.Size * data.tSize() / 2) - _position.X), (_target.Position.Y - (_position.Y + _target.Size * data.tSize() / 2))); // _velocity = new Vector2((float)Math.Sin(_rotation) * 64, (float)Math.Cos(_rotation) * 64) * 20f ; }
public void removeTarget() { _target = null; }