Exemplo n.º 1
0
        public Point Move(Direction direction, Rectangle boundaries)
        {
            Point newLocation = location;
            switch (direction)
            {
                case  Direction.Up:
                    if (newLocation.Y - moveInterval >= boundaries.Top)
                        newLocation.Y -= moveInterval;
                    break;
                case Direction.Down:
                    if (newLocation.Y + moveInterval <= boundaries.Bottom)
                        newLocation.Y += moveInterval;
                    break;
                case Direction.Left:
                    if (newLocation.X - moveInterval >= boundaries.Left)
                        newLocation.X -= moveInterval;
                    break;
                case Direction.Right:
                    if (newLocation.X + moveInterval <= boundaries.Right)
                        newLocation.X += moveInterval;
                    break;

                default:
                    break;
            }
            return newLocation;
        }
Exemplo n.º 2
0
        public Prop(Vector2 position, Texture texture, Direction angle, bool canSeeThrough = false)
            : base(position)
        {
            this.texture = texture;

            CanSeeThrough = canSeeThrough;
            PropAngle = angle;
        }
Exemplo n.º 3
0
 public override void OnCollision(Entity entity, Direction direction)
 {
     if (((int)direction + (int)PropAngle) % 180 == 0 && Destination != null && canEnter)
     {
         Direction exitDirection = (Direction)(MathUtil.Mod((int)direction + ((int)Destination.PropAngle - (int)PropAngle), 360));
         Destination.Exit(entity, exitDirection);
     }
 }
Exemplo n.º 4
0
 public void Move(Direction direction, Random random)
 {
     player.Move(direction);
     if (Enemies !=null)
     {
         foreach (Enemy enemy in Enemies)
             enemy.Move(random);
     }
 }
Exemplo n.º 5
0
        private void Exit(Entity entity, Direction direction)
        {
            enterTimeout = 1;

            if (entity.Map != Map)
            {
                Map.AddEntity(entity);
            }

            entity.Position = Position + direction.GetDirectionVector() * (Size / 2 + entity.Size / 2);
        }
Exemplo n.º 6
0
 public static Vector3 DirectionOffset(Direction Direction)
 {
     switch (Direction)
     {
         case Direction.North: return new Vector3(0, -1, 0);
         case Direction.East: return new Vector3(1, 0, 0);
         case Direction.South: return new Vector3(0, 1, 0);
         case Direction.West: return new Vector3(-1, 0, 0);
         default: throw new InvalidOperationException();
     }
 }
Exemplo n.º 7
0
 public void setup(Type type, Direction dir_to, Direction dir_from)
 {
     this.type = type;
     this.direction = dir_to;
     switch (type) {
     case Type.straight:
         GetComponent<SpriteRenderer>().sprite = straight;
         if (dir_to == Direction.up || dir_to == Direction.down) {
             rotate (90);
         }
         break;
     case Type.bend:
         GetComponent<SpriteRenderer>().sprite = bend;
         if (dir_to == Direction.up && dir_from == Direction.right ||
             dir_to == Direction.right && dir_from == Direction.up) {
             rotate (90);
         } else if (dir_to == Direction.down && dir_from == Direction.right ||
                    dir_to == Direction.right && dir_from == Direction.down) {
             rotate (180);
         } else if (dir_to == Direction.down && dir_from == Direction.left ||
                    dir_to == Direction.left && dir_from == Direction.down) {
             rotate (270);
         }
         break;
     case Type.terminal:
         GetComponent<SpriteRenderer>().sprite = terminal;
         Direction dir = dir_to != Direction.none ? dir_to : dir_from;
         if (dir == Direction.up) {
             rotate (90);
         } else if (dir == Direction.right) {
             rotate (180);
         } else if (dir == Direction.down) {
             rotate (270);
         }
         break;
     case Type.singular:
         GetComponent<SpriteRenderer>().sprite = singular;
         break;
     default:
         Debug.LogError("UIGridSegment not given direction");
         break;
     }
 }
Exemplo n.º 8
0
 public virtual void OnCollision(Entity entity, Direction direction)
 {
 }
Exemplo n.º 9
0
 public abstract void Atack(Direction direction, Random random);
Exemplo n.º 10
0
 protected bool DemageEnemy(Direction direction, int radius, int demage, Random random)
 {
     return false;
 }
Exemplo n.º 11
0
    protected void Start()
    {
        this.seekActor = null;
        this.spriteAnimation.addClip(ANIM_IDLE, new SpriteAnimation.Clip(0, 1, 150, WrapMode.Loop));
        this.spriteAnimation.addClip(ANIM_WALK, new SpriteAnimation.Clip(1, 6, 150, WrapMode.Loop));
        this.spriteAnimation.play(ANIM_IDLE);

        this.changeState(POL_BEHAVIOR_PATROL);
        this.patrolDirection = Game.Direction.LEFT;

        this.baseSpeed = speed;
        this.setPathfindingEnabled(false);
        this.updateCount = 0;
        //this.destination = this.transform.position;
    }
Exemplo n.º 12
0
    private void updatePatrolState()
    {
        emote(EMOTE_NONE);

        if (seekActor != null && seesEntity(seekActor))
        {
            informActorPosition(playerLastSeen,seekActor);
            //changeState(POL_BEHAVIOR_CHASING);
        } else
        {

            if (this.justCollided)
            {
                this.patrolDirection = Game.reverseDirection(this.patrolDirection);
            }
            this.moveDelta(Game.directionVector(this.patrolDirection));

            this.spriteAnimation.play(ANIM_WALK, true);
        }
    }
Exemplo n.º 13
0
        // update & draw
        public void update_Player()
        {
            if (MainMenu.CurrentGameState == MainMenu.GameState.Playing)
            {
                if (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.LeftThumbstickRight) || Keyboard.GetState().IsKeyDown(Keys.Right))
                {
                    if (borddroit)
                    {
                        for (int i = 1; i <= speed && player_hitbox.X + player_hitbox.Width <= largeurecran; i++)
                        {
                            player_hitbox.X += 1;
                        }
                    }
                    if (bordgauche)
                    {
                        for (int i = 1; i <= speed && !(player_hitbox.X == centreecran.X); i++)
                        {
                            player_hitbox.X += 1;
                        }
                    }

                    this.direction = Direction.Right;
                    this.frameline = 1;
                    this.Animate();

                }
                else if (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.LeftThumbstickLeft) || Keyboard.GetState().IsKeyDown(Keys.Left))
                {
                    if (bordgauche)
                    {
                        for (int i = 1; i <= speed && player_hitbox.X > 0; i++)
                        {
                            player_hitbox.X -= 1;
                        }
                    }
                    if (borddroit)
                    {
                        for (int i = 1; i <= speed && !(player_hitbox.X == centreecran.X); i++)
                        {
                            player_hitbox.X -= 1;
                        }
                    }
                    this.frameline = 1;
                    this.direction = Direction.Left;
                    this.Animate();
                }
                else if (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.LeftThumbstickUp) || Keyboard.GetState().IsKeyDown(Keys.Up))
                {
                    if (bordhaut)
                    {
                        for (int i = 1; i <= speed && player_hitbox.Y > 0; i++)
                        {
                            player_hitbox.Y -= 1;
                        }
                    }
                    if (bordbas)
                    {
                        for (int i = 1; i <= speed && !(player_hitbox.Y == centreecran.Y); i++)
                        {
                            player_hitbox.Y -= 1;
                        }
                    }
                    this.frameline = 5;
                    this.direction = Direction.Up;
                    this.Animate();

                }
                else if (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.LeftThumbstickDown) || Keyboard.GetState().IsKeyDown(Keys.Down))
                {
                    if (bordbas)
                    {
                        for (int i = 1; i <= speed && player_hitbox.Y + player_hitbox.Height < hauteurecran; i++)
                        {
                            player_hitbox.Y += 1;
                        }
                    }
                    if (bordhaut)
                    {
                        for (int i = 1; i <= speed && !(player_hitbox.Y == centreecran.Y); i++)
                        {
                            player_hitbox.Y += 1;
                        }
                    }
                    this.frameline = 3;
                    this.direction = Direction.Down;
                    this.Animate();
                }

                if (Keyboard.GetState().IsKeyUp(Keys.Up) && Keyboard.GetState().IsKeyUp(Keys.Down) && Keyboard.GetState().IsKeyUp(Keys.Left) && Keyboard.GetState().IsKeyUp(Keys.Right))
                {
                    if (direction == Direction.Left || direction == Direction.Right)
                        this.frameline = 0;
                    else if (direction == Direction.Down)
                        this.frameline = 2;
                    else if (direction == Direction.Up)
                        this.frameline = 4;
                    this.Animate();
                }
                switch (this.direction)
                {
                    case Direction.Up:
                        this.Mirror = SpriteEffects.None;
                        break;
                    case Direction.Down:
                        this.Mirror = SpriteEffects.None;
                        break;
                    case Direction.Left:
                        this.Mirror = SpriteEffects.None;
                        break;
                    case Direction.Right:
                        this.Mirror = SpriteEffects.FlipHorizontally;
                        break;
                }
            }
        }
Exemplo n.º 14
0
        public static bool TryParse( String str, out Direction dir )
        {
            switch ( str )
            {
                case "n":
                    dir = North; return true;
                case "s":
                    dir = South; return true;
                case "e":
                    dir = East; return true;
                case "w":
                    dir = West; return true;
            }

            dir = Direction.None;
            return false;
        }
Exemplo n.º 15
0
        // update & draw
        public void update()
        {
            if (MainMenu.CurrentGameState == MainMenu.GameState.Playing)
            {
                if (enemy_hitbox.X < Player.player_hitbox.X)
                {

                    enemy_hitbox.X += speed_e;
                    this.direction = Direction.Right;
                    this.frameline = 1;
                    this.Animate();

                }

                else

                if (enemy_hitbox.X > Player.player_hitbox.X)
                {

                    enemy_hitbox.X -= speed_e;
                    this.frameline = 1;
                    this.direction = Direction.Left;
                    this.Animate();

                }

                else
                {
                    if (enemy_hitbox.Y > Player.player_hitbox.Y)
                    {
                        enemy_hitbox.Y -= speed_e - 1;
                        this.frameline = 5;
                        this.direction = Direction.Down;
                        this.Animate();

                    }
                    else

                    if (enemy_hitbox.Y < Player.player_hitbox.Y)
                    {
                        enemy_hitbox.Y += speed_e - 1;
                        this.frameline = 3;
                        this.direction = Direction.Up;
                        this.Animate();
                    }

                }

            }
            switch (this.direction)
            {
                case Direction.Up:
                    this.Mirror = SpriteEffects.None;
                    break;
                case Direction.Down:
                    this.Mirror = SpriteEffects.None;
                    break;
                case Direction.Left:
                    this.Mirror = SpriteEffects.None;
                    break;
                case Direction.Right:
                    this.Mirror = SpriteEffects.FlipHorizontally;
                    break;
            }
        }
Exemplo n.º 16
0
        private Vector2 MoveWithCollisions(Vector2 movement, RectangleF collisionBox, ref Direction direction)
        {
            collisionBox.Inflate(Size.X / 2, Size.Y / 2);

            Vector2 end = Position + movement;
            Vector2 newMovement = movement;

            if (movement.X > 0) // Right
            {
                if (Position.X >= collisionBox.Right)
                {
                    return movement;
                }
                else if (Position.X > collisionBox.Left)
                {
                    //TODO: Move the player out the box? Let im free?
                    newMovement.X = 0;
                }
                else if (end.X > collisionBox.Left)
                {
                    newMovement.X = collisionBox.Left - Position.X;
                    direction = Direction.Left;
                }
                else
                {
                    return movement;
                }
            }
            else if (movement.X < 0) // Left
            {
                if (Position.X <= collisionBox.Left)
                {
                    return movement;
                }
                else if (Position.X < collisionBox.Right)
                {
                    //TODO: Move the player out the box? Let im free?
                    newMovement.X = 0;
                }
                else if (end.X < collisionBox.Right)
                {
                    newMovement.X = collisionBox.Right - Position.X;
                    direction = Direction.Right;
                }
                else
                {
                    return movement;
                }
            }
            else if (Position.X <= collisionBox.Left || Position.X >= collisionBox.Right)
            {
                return movement;
            }

            if (movement.Y > 0) // Down
            {
                if (Position.Y >= collisionBox.Bottom)
                {
                    return movement;
                }
                else if (Position.Y > collisionBox.Top)
                {
                    //TODO: Move the player out the box? Let im free?
                    newMovement.Y = 0;
                }
                else if (end.Y > collisionBox.Top)
                {
                    newMovement.Y = collisionBox.Top - Position.Y;
                    direction = Direction.Up;
                }
                else
                {
                    return movement;
                }
            }
            else if (movement.Y < 0) // Up
            {
                if (Position.Y <= collisionBox.Top)
                {
                    return movement;
                }
                else if (Position.Y < collisionBox.Bottom)
                {
                    //TODO: Move the player out the box? Let im free?
                    newMovement.Y = 0;
                }
                else if (end.Y < collisionBox.Bottom)
                {
                    newMovement.Y = collisionBox.Bottom - Position.Y;
                    direction = Direction.Down;
                }
                else
                {
                    return movement;
                }
            }
            else if (Position.Y <= collisionBox.Top || Position.Y >= collisionBox.Bottom)
            {
                return movement;
            }

            return newMovement;
        }
Exemplo n.º 17
0
 public Door(Vector2 position, Direction propAngle)
     : base(position, Textures.Door, propAngle)
 {
 }
Exemplo n.º 18
0
 public void Move(Direction direction)
 {
     base.location = Move(direction, game.Boundaries);
 }
Exemplo n.º 19
0
 public override void Atack(Direction direction, Random random)
 {
 }