public override void Update(EnemyShip ship, float deltaTime) { ship.CenterX -= speed * deltaTime; GameObject target = null; if (IndexInFlock(ship) == 0) { target = ship.Player; } else { target = Flock(ship).ElementAtOrDefault(IndexInFlock(ship) - 1); } if (target != null) { PointF targetPos = target.Center; if (IndexInFlock(ship) > 0) { float increment = IndexInFlock(ship) * 100 * (IndexInFlock(ship) % 2 == 0 ? -1 : 1); targetPos = new PointF(targetPos.X, targetPos.Y + increment); } float diff = targetPos.Y - ship.CenterY; ship.CenterY += (speed * 5 / ship.Root.Height) * diff * deltaTime; } }
protected virtual IEnumerable <EnemyShip> Flock(EnemyShip ship) { return(ship.AllObjects .Select(obj => obj as EnemyShip) .Where(obj => obj != null) .Where(obj => obj.Behavior.Equals(ship.Behavior))); }
public override void Update(EnemyShip ship, float deltaTime) { ship.X -= speed * deltaTime; if (ship.Parent != null) { ship.CenterY = (float)(function(ship.CenterX / ship.Parent.Width) / 2 + 0.5) * ship.Parent.Height; } }
private int IndexInFlock(EnemyShip ship) { int index = -1; for (int i = 0; i < Flock(ship).Count(); i++) { if (ship.Equals(Flock(ship).ElementAt(i))) { index = i; } } return(index); }
static void Initialize(Engine engine) { int startRow = 0; int startCol = 0; //int endCol = WorldCols - 2; EnemyShip ship = new EnemyShip(new MatrixCoords(startRow, startCol)); engine.AddObject(ship); PlayerAircraft aircraft = new PlayerAircraft(new MatrixCoords(WorldRows - 1, WorldCols / 2)); engine.AddObject(aircraft); //Shot shot = new Shot(new MatrixCoords(15, 5), new MatrixCoords(-1, 0)); //shot.Move(); //engine.AddObject(shot); }
static void Initialize(Engine engine) { int startRow = 0; int startCol = 0; EnemyShip ship = new EnemyShip(new MatrixCoords(startRow, startCol), new MatrixCoords(0, 0)); engine.AddObject(ship); for (int i = startCol; i < WorldCols - 4; i++) { EnemyShipDestructivePart currBlock = new EnemyShipDestructivePart(new MatrixCoords(startRow + 6, i)); engine.AddObject(currBlock); } PlayerAircraft aircraft = new PlayerAircraft(new MatrixCoords(WorldRows - 10, WorldCols / 2)); engine.AddObject(aircraft); }
public override void Update(float deltaTime) { if (!active) { return; } GameObject world = Parent; Center = world.Center; Left = world.Right; int now = Environment.TickCount; if (now - last > emmisionInterval) { last = now; EnemyShip ship = new EnemyShip(shipIndex, behavior); ship.Center = Center; world.AddChild(ship); } }
public override void Update(EnemyShip ship, float deltaTime) { if (!ship.Visible) { ship.CenterY = rnd.Next(ship.Root.Top.FloorToInt(), ship.Root.Bottom.FloorToInt()); } ship.CenterX -= speed * deltaTime; if (ship.Player != null) { double multiplier = Math.Abs(ship.Player.X - ship.X) / (ship.Root.Width); if (ship.Player.Top > ship.CenterY) { ship.CenterY += ((float)(speed * multiplier * deltaTime)); } else if (ship.Player.Bottom < ship.CenterY) { ship.CenterY -= ((float)(speed * multiplier * deltaTime)); } } }
private void ResetEnemy(EnemyShip source) { bool isExist; //int rndX = 0; uint speed = BL_Random.GetFlySpeed(); byte rndYShot = BL_Random.GetRndY(); HashSet <Coordinate> newPosition; do { //rndX = BL_Random.GetX(); newPosition = InitNewEnemy(BL_Random.GetX()); isExist = false; for (int i = 0; i < _amountOfObjects; i++) { if (_gameObjects[i] is EnemyShip enemy) { if (newPosition.Overlaps(enemy.Position) /*!((rndX > enemy.X + enemy.Width) || (rndX + enemy.Width < enemy.X))*/) { isExist = true; break; } } } } while (isExist); source.Active = true; source.Counter = 0; source.HP = 6; source.Position.Clear(); foreach (var item in newPosition) { source.Position.Add(new Coordinate(item)); } }
protected virtual IEnumerable <EnemyShip> Flock(EnemyShip ship) { return(Universe.EShips.Where(obj => obj != null) .Where(obj => obj.Behavior.Equals(ship.Behavior))); }
public abstract void Update(EnemyShip ship, float deltaTime);
protected override IEnumerable <EnemyShip> Flock(EnemyShip ship) { return(base.Flock(ship) .OrderBy(s => s.X) .Where(s => s.Left > (s.Player != null ? s.Player.Left : 0))); }