Пример #1
0
        public static GameObject CreateGameObject(int spriteValue, Vector2 position)
        {
            switch (spriteValue)
            {
            case 32:
                return(GameObjectManager.InstantiatePlayer(position));

            case 1:
                var           messages    = GlobalVars.GetMessageListAt((int)(position.X / 8), (int)(position.Y / 8));
                List <string> messageList = new List <string>();

                if (messages != null)
                {
                    foreach (var m in messages)
                    {
                        messageList.Add((string)m.Value);
                    }
                }
                return(GameObjectManager.AddObject(
                           new OldMan(position, spriteValue, messageList)
                           ));

            case 98:
                return(GameObjectManager.AddObject(
                           new FirePit(
                               position
                               )
                           ));

            case 76:
                return(GameObjectManager.AddObject(
                           new Chimney(
                               position
                               )
                           ));

            case 7:
                return(GameObjectManager.AddObject(new Blob(position, spriteValue)));

            case 55:
                return(GameObjectManager.AddObject(new Bat(position, spriteValue)));

            case 21:
                return(GameObjectManager.AddObject(new Tortuga(position, spriteValue)));

            case 122:
                return(GameObjectManager.AddObject(new Spike(position, spriteValue)));

            case 42:
                return(GameObjectManager.AddObject(new Goose(position, spriteValue)));

            case 11:
                return(GameObjectManager.AddObject(new Gate(position)));

            case 12:
                return(GameObjectManager.AddObject(new Gate(position, Gate.OpenCondition.NO_ENEMIES)));

            case 19:
                return(GameObjectManager.AddObject(new Snake(position, spriteValue)));

            case 105:
                return(GameObjectManager.AddObject(new Key(position)));

            case 78:
                return(GameObjectManager.AddObject(new Altar(position)));

            case 126:
                return(GameObjectManager.AddObject(new Stairs(position, spriteValue)));

            case 51:
                return(GameObjectManager.AddObject(new RunningBoots(position)));

            case 123:
                return(GameObjectManager.AddObject(new RunningBoots(position)));

            default:
                return(GameObjectManager.AddObject(new GameObject(position, new Graphics.P8Sprite(spriteValue))));
            }
        }
Пример #2
0
        void AttackingInit(PlayerStates previous)
        {
            if (!_player.CanAttack)
            {
                Init(PlayerStates.Walking);
                return;
            }


            //
            // Remove input so it can't move while atacking
            //

            _player.RemoveComponent <AInput>();

            //
            // Stop player.
            //

            var physics = _player.GetComponent <TopDownPhysics>();

            physics.velocity = Vector2.Zero;

            //
            // Figure out sword's direction.
            //

            Vector2 facingDir = _player.transform.direction == Vector2.Zero ? physics.facingDirection : _player.transform.direction;

            if (facingDir.X != 0)
            {
                facingDir.Y = 0;
            }
            if (facingDir != Vector2.Zero)
            {
                facingDir.Normalize();
            }

            //
            // Reset player's direction so it doesn't keep moving to the previous set direction.
            //

            _player.transform.direction = Vector2.Zero;

            //
            // Instantiate sword.
            //

            _player.swordInstance = new Sword(_player.transform.position + 8 * facingDir, facingDir);
            GameObjectManager.AddObject(_player.swordInstance);
            var ratio = (_player.lifeTime / _player.initialLifetime);

            if (ratio < 0.2)
            {
                _player.swordInstance.timeGivenAdjustment = 1f;
            }
            else if (ratio < 0.8)
            {
                _player.swordInstance.timeGivenAdjustment = 1.7f;
            }
            else
            {
                _player.swordInstance.timeGivenAdjustment = 2.3f;
            }
        }