public void Update(Actor caller) { if (CycleCount < 120) { ++CycleCount; caller.StopMovement(); switch (direction) { case 0: caller.MoveDown(); break; case 1: caller.MoveLeft(); break; case 2: caller.MoveRight(); break; case 3: caller.MoveUp(); break; } } else if (PauseCount < 60) { ++PauseCount; caller.StopMovement(); } else { CycleCount = 0; PauseCount = 0; direction = rand.Next(0, 3); } }
public void Update(Actor caller) { if (caller.Target != null) { Vector2 callerPos = caller.AbsolutePosition; Vector2 targetPos = caller.Target.AbsolutePosition; caller.Rotation = MathFunctions.AngleBetweenPositions(callerPos, targetPos); } }
public void SetTarget(Actor caller) { if (InputHelper.LeftMouseDown()) { Vector2 screenPos = InputHelper.MousePositionAsVector; Vector2 cameraPos = GameScreens.TestLevel.SceneGraph.Camera.Position; Vector2 worldPos = screenPos + cameraPos; List<GameObject> targets = GameScreens.TestLevel.SceneGraph.GetObjectsAtWorldPosition(new Point((int)worldPos.X, (int)worldPos.Y)); if (targets.Count != 0) { caller.Target = targets[0]; } else { caller.Target = null; } } }
public void FireLaser(Actor caller) { //TODO: This cast shouldn't be done twice per frame SpaceShip ship = caller as SpaceShip; if (InputHelper.KeyPressed(Keys.Space)) { foreach (Weapon weapon in ship.Weapons) { weapon.BeginFire(); } } if (InputHelper.KeyReleased(Keys.Space)) { foreach (Weapon weapon in ship.Weapons) { weapon.EndFire(); } } }
public void CalculateThrust(Actor caller) { SpaceShip ship = caller as SpaceShip; if (InputHelper.KeyDown(Keys.W)) { ship.ApplyThrust(-Vector2.UnitY); } else if (InputHelper.KeyDown(Keys.S)) { ship.ApplyThrust(Vector2.UnitY); } if (InputHelper.KeyDown(Keys.A)) { ship.ApplyThrust(-Vector2.UnitX); } else if (InputHelper.KeyDown(Keys.D)) { ship.ApplyThrust(Vector2.UnitX); } }
public void Update(Actor caller) { caller.StopMovement(); if (InputHelper.KeyDown(Keys.W)) { caller.MoveUp(); } else if (InputHelper.KeyDown(Keys.S)) { caller.MoveDown(); } if (InputHelper.KeyDown(Keys.A)) { caller.MoveLeft(); } else if (InputHelper.KeyDown(Keys.D)) { caller.MoveRight(); } }
public void Update(Actor caller) { if (InputHelper.KeyDown(Keys.R)) { caller.Position = new Vector2(500, 500); } SetTarget(caller); FireLaser(caller); CalculateThrust(caller); }