예제 #1
0
        /// <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;
        }
예제 #2
0
        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;
        }
예제 #3
0
 public Idle(Unit unit)
 {
     Unit = unit;
 }
예제 #4
0
 public Face(Unit unit, Direction direction)
     : base(unit, ActionType.Face)
 {
     TargetDirection = direction;
 }
예제 #5
0
 public Charge(Unit unit, Tile targetPosition)
     : base(unit, targetPosition, ActionType.Charge)
 {
     Speed = Unit.UnitSpeed * 1.5;
 }
예제 #6
0
        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;
        }
예제 #7
0
 /// <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;
 }
예제 #8
0
 /// <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;
 }
예제 #9
0
 public Deliver(Unit unit)
     : base(unit, ActionType.Deliver)
 {
 }
예제 #10
0
 public Attack(Unit unit, Unit targetUnit)
     : base(unit, ActionType.Attack)
 {
 }
예제 #11
0
 public Shoot(Unit unit)
     : base(unit, ActionType.Shoot)
 {
 }
예제 #12
0
 public UnitSprite(Unit unit)
 {
     this.Unit = unit;
 }
예제 #13
0
 public Die(Unit unit)
     : base(unit, ActionType.Die)
 {
 }