/// <summary> /// Let the unit walk to the targetdirection in the specified direction. When the direction is null North is used. /// the unit value should be set by properties later on /// </summary> /// <param name="targetX"></param> /// <param name="targetY"></param> /// <param name="targetDirection"></param> public Walk(Unit unit, Tile targetPosition, ActionType? actionType = ActionType.Walk) : base(unit, actionType.Value) { this.TargetPosition = targetPosition; this.Speed = unit.UnitSpeed; this.TargetDirection = Direction.East; }
public static string GetSpriteName(this string suffix, Unit unit) { if (unit == null) { return string.Empty; } var returnString = string.Format("{0}_{1}", unit.SpriteBaseName, unit.CurrentDirection); if (unit.CurrentAction == null) { returnString = string.Format("{0}_{1}", returnString, suffix); } return returnString; }
public Idle(Unit unit) { Unit = unit; }
public Face(Unit unit, Direction direction) : base(unit, ActionType.Face) { TargetDirection = direction; }
public Charge(Unit unit, Tile targetPosition) : base(unit, targetPosition, ActionType.Charge) { Speed = Unit.UnitSpeed * 1.5; }
private void HandleInput() { MouseState newMouseState = Mouse.GetState(); Rectangle cursorRectangle = Cursor.Instance.ScreenRectangle; cursorRectangle.X += (int)Camera.Instance.Position.X; cursorRectangle.Y += (int)Camera.Instance.Position.Y; foreach (Unit unit in this.Units) { // Display the select icon when we hover over a unit if (cursorRectangle.Intersects(unit.Rectangle)) { Cursor.Instance.SetCursor(Cursor.CursorType.Select); // When we click on a unit, select him if (newMouseState.LeftButton == ButtonState.Pressed) { this.SelectedUnit = unit; } } } // If we click the right mouse button when we have a selected unit, order him to move if (this.SelectedUnit != null) { if (newMouseState.RightButton == ButtonState.Released && oldMouseState.RightButton == ButtonState.Pressed) { // Get the map coordinates that were clicked Vector2 targetPosition = new Vector2( newMouseState.X + (int)Camera.Instance.Position.X, newMouseState.Y + (int)Camera.Instance.Position.Y ); // Get the tile thats at the clicked coordinates Tile targetTile = Map.Instance.GetTileByCoordinates(targetPosition); // Order the unit to move there this.SelectedUnit.DoAction(new Walk(this.SelectedUnit, targetTile)); } } oldMouseState = newMouseState; }
/// <summary> /// when the unit should be shown but does nothing the unit is idle. This is the default action that is loaded for a unit. /// </summary> /// <param name="unit"></param> public Idle(Unit unit) : base(unit, ActionType.Idle) { Unit = unit; }
/// <summary> /// Creates a new unitaction for the unit /// </summary> /// <param name="actionType"></param> /// <param name="actionType"></param> protected UnitAction(Unit unit, ActionType actionType) { this.Unit = unit; this.ActionType = actionType; }
public Deliver(Unit unit) : base(unit, ActionType.Deliver) { }
public Attack(Unit unit, Unit targetUnit) : base(unit, ActionType.Attack) { }
public Shoot(Unit unit) : base(unit, ActionType.Shoot) { }
public UnitSprite(Unit unit) { this.Unit = unit; }
public Die(Unit unit) : base(unit, ActionType.Die) { }