Beispiel #1
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="position"> Location in game.</param>
        /// <param name="width"> Width of the BubbleGumEnemy.</param>
        /// <param name="height"> Height of the BubbleGumEnemy.</param>
        /// <param name="content"> The content manager to laod the texture from.</param>
        /// <param name="level"> The level the BubbleGumEnemy is in.</param>
        public BubbleGumEnemy(Vector2 position, int width, int height, ContentManager content, Level level) :
            base(position, width, height, level)
        {
            Sprite = new MonoSprite(content.Load <Texture2D>("Images/Enemy/BubbleGumEnemy"), new Rectangle(0, 16, 16, 16), position, width, height);

            // Set the terminal velocity.
            TerminalVelocity = new Vector2(70, 350);

            // Add walking animation.
            Animations.Add(new Animation(
                               id: (int)BubbleGumEnemyAnimation.WALKING,
                               baseFrame: Vector2.Zero,
                               frameSize: new Vector2(width, height),
                               rows: 1,
                               columns: 2,
                               msPerFrame: 150
                               ));

            // Add death animation.
            Animations.Add(new Animation(
                               id: (int)BubbleGumEnemyAnimation.DEATH,
                               baseFrame: new Vector2(32, 8),
                               frameSize: new Vector2(17, 8),
                               rows: 1,
                               columns: 1,
                               msPerFrame: 0
                               ));

            // By default play the walking animation.
            Animations.Play((int)BubbleGumEnemyAnimation.WALKING);

            // Set horizontal velocity to the terminal horizontal velocity.
            velocity.X = TerminalVelocity.X;
        }
Beispiel #2
0
        /// <summary>
        /// Initialize scene.
        /// </summary>
        public override void Init()
        {
            // Call base init.
            base.Init();

            // Set texture of the scene.
            Texture2D texture = Game.Content.Load <Texture2D>("Images/Screens/GameOver");

            // Load the nintendo logo.
            MonoSprite logo = new MonoSprite(texture, new Rectangle(0, 0, SuperPlatformerGame.RESOLUTION_X, SuperPlatformerGame.RESOLUTION_Y), Vector2.Zero, SuperPlatformerGame.RESOLUTION_X, SuperPlatformerGame.RESOLUTION_Y);

            // Add the logo to the drawlist.
            Children.Add(logo);

            _sound = Game.Content.Load <SoundEffect>("Audio/smw_gameover");

            if (_sound != null)
            {
                _sound.Play();
            }

            // Set and start the timer.
            _durationTimer = new TimedEvent(OnTimerElapsed, _duration);
            _durationTimer.Enable();
        }
Beispiel #3
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="position"> Location in game.</param>
        /// <param name="width"> Width.</param>
        /// <param name="height"> Height.</param>
        /// <param name="item"> Mystery item.</param>
        /// <param name="content"> The content manager.</param>
        /// <param name="level"> The level the giftblock is in.</param>
        public GiftBlock(Vector2 position, int width, int height, PowerUp item, ContentManager content, Level level) :
            base(position, width, height, level)
        {
            Gravity = 0;

            Sprite = new MonoSprite(content.Load <Texture2D>("Images/Tile/Blocks"), new Rectangle(0, 0, 16, 16), position, width, height);

            // The block should not check its own collisions.
            CheckCollisions = false;

            // Add rotating animation.
            Animations.Add(new Animation(
                               id: (int)GiftBlockAnimation.ROTATING,
                               baseFrame: Vector2.Zero,
                               frameSize: new Vector2(width, height),
                               rows: 1,
                               columns: 4,
                               msPerFrame: 150
                               ));

            // Add wood animation.
            Animations.Add(new Animation(
                               id: (int)GiftBlockAnimation.WOOD,
                               baseFrame: new Vector2(64, 0),
                               frameSize: new Vector2(width, height),
                               rows: 1,
                               columns: 1,
                               msPerFrame: 50
                               ));

            // By default start rotating animation.
            Animations.Play((int)GiftBlockAnimation.ROTATING);

            _item = item;
        }
Beispiel #4
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="items"> The option list items.</param>
        /// <param name="keyboard"> Keyboard device.</param>
        /// <param name="indicator"> Sprite which indicates the selected item.</param>
        /// <param name="position"> Position of this list.</param>
        /// <param name="lineHeight"> Height per line.</param>
        /// <param name="scale"> Scale.</param>
        public OptionList(List <OptionListItem> items, KeyboardInput keyboard, MonoSprite indicator, Vector2 position, int lineHeight, int scale)
        {
            _items        = items;
            _keyboard     = keyboard;
            _currentIndex = 0;
            _indicator    = indicator;
            _scale        = scale;

            // Position the lists relatively to the list's position
            int i = 0;

            items.ForEach((item) =>
            {
                item.Position = new Vector2(position.X * _scale, (position.Y + (lineHeight * i)) * _scale);
                item.Scale    = _scale;

                ++i;
            });

            // Move the indicator to the position
            Vector2 indicatorPosition = _indicator.Position;

            int paddingRight = 5;

            indicatorPosition.X = (_items[_currentIndex].Position.X / _scale) - _indicator.Width - paddingRight;
            indicatorPosition.Y = _items[_currentIndex].Position.Y / _scale;

            _indicator.Position = indicatorPosition;
        }
Beispiel #5
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="position"> Location in game.</param>
        /// <param name="level"> Level object.</param>
        /// <param name="content"> Content manager object.</param>
        public FinishLine(Vector2 position, Level level, ContentManager content) :
            base(position, 32, 64, level)
        {
            Sprite = new MonoSprite(content.Load <Texture2D>("Images/Finish"), new Rectangle(0, 0, Width, Height), position, Width, Height);
            _state = FinishState.OPEN;

            // Add finishing animation
            Animations.Add(new Animation(
                               id: (int)FinishState.OPEN,
                               baseFrame: Vector2.Zero,
                               frameSize: new Vector2(Width, Height),
                               rows: 1,
                               columns: 4,
                               msPerFrame: 150
                               ));

            Animations.Add(new Animation(
                               id: (int)FinishState.CLOSED,
                               baseFrame: new Vector2(0, 64),
                               frameSize: new Vector2(Width, Height),
                               rows: 1,
                               columns: 4,
                               msPerFrame: 150
                               ));

            Padding = new Vector2(8, 3);
            Solid   = false;

            Animations.Play((int)_state);
        }
Beispiel #6
0
        /// <summary>
        /// Initialize scene.
        /// </summary>
        public override void Init()
        {
            // Call base init.
            base.Init();

            // Create background.
            MonoSprite background = new MonoSprite(Game.Content.Load <Texture2D>("Images/Screens/TitleScreen"), new Rectangle(0, 0, SuperPlatformerGame.RESOLUTION_X, SuperPlatformerGame.RESOLUTION_Y), Vector2.Zero, SuperPlatformerGame.RESOLUTION_X, SuperPlatformerGame.RESOLUTION_Y);

            // Add background to children.
            Children.Add(background);

            // Create indicator for the option list
            MonoSprite indicator = new MonoSprite(Game.Content.Load <Texture2D>("Images/Arrow"), new Rectangle(0, 0, 8, 8), Vector2.Zero, 8, 8);

            // The font for our option list
            SpriteFont font = Game.Content.Load <SpriteFont>("Font/PixelFont");

            _song = Game.Content.Load <Song>("Audio/smw_titlescreen");

            MediaPlayer.Play(_song);
            MediaPlayer.IsRepeating = true;
            MediaPlayer.Volume      = 0.6f;

            // We want a white text
            Color fillStyle = Color.White;

            // Create the option list
            _optionList = new OptionList(new List <OptionListItem>
            {
                new OptionListItem("Play \"Starter's Home\"", font, fillStyle, () =>
                {
                    Game.SceneActivator.ActivateScene(new LevelScene(Game, "StartersHome"));
                }),
                new OptionListItem("Play \"Hill Climb Forest\"", font, fillStyle, () =>
                {
                    Game.SceneActivator.ActivateScene(new LevelScene(Game, "HillClimbForest"));
                }),
                new OptionListItem("Play \"Pipe Maze\"", font, fillStyle, () =>
                {
                    Game.SceneActivator.ActivateScene(new LevelScene(Game, "PipeMaze"));
                }),
                new OptionListItem("Play \"The Cloud\"", font, fillStyle, () =>
                {
                    Game.SceneActivator.ActivateScene(new LevelScene(Game, "TheCloudLevel"));
                }),
                new OptionListItem("Play \"Kaizo\"", font, fillStyle, () =>
                {
                    Game.SceneActivator.ActivateScene(new LevelScene(Game, "Kaizo"));
                }),
                new OptionListItem("Quit", font, fillStyle, () =>
                {
                    Game.Exit();
                })
            }, Game.KeyboardDevice, indicator, new Vector2(25, 90), 15, SuperPlatformerGame.SCALE);

            // Add option list to children.
            Children.Add(_optionList);
        }
Beispiel #7
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="position"> Location in game.</param>
        /// <param name="width"> Width of the mushroom.</param>
        /// <param name="height"> Height of the mushroom.</param>
        /// <param name="content"> The content manager to get the texutre from.</param>
        /// <param name="level"> The level the mushroom is in.</param>
        public Mushroom(Vector2 position, int width, int height, ContentManager content, Level level) :
            base(position, width, height, level, content)
        {
            _content = content;

            Sprite = new MonoSprite(content.Load <Texture2D>("Images/Item/Mushroom"), new Rectangle(0, 0, 16, 16), position, width, height);

            Collidable = false;
        }
Beispiel #8
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="position"> Position in the level.</param>
        /// <param name="width"> Width of the PlungerEnemy.</param>
        /// <param name="height"> Height of the PlungerEnemy.</param>
        /// <param name="content"> Content manager of the game.</param>
        /// <param name="level"> The level the PlungerEnemy is in.</param>
        public PlungerEnemy(Vector2 position, int width, int height, ContentManager content, Level level) : base(position, width, height, level)
        {
            Sprite = new MonoSprite(content.Load <Texture2D>("Images/Enemy/PlungerEnemy"), new Rectangle(0, 0, width, height), position, width, height);

            // Remove gravity.
            Gravity = 0;

            // PlungerEnemy is not solid.
            Solid = false;

            // PlungerEnemy shouldn't check for collisions.
            CheckCollisions = false;

            // Set default direction.
            _direction = Direction.Down;

            // Enemy doesnt walk.
            AllowMovement = false;

            // Set spawn position.
            _spawnPosition = position;

            // Set default height.
            _startHeight = height;

            // Set some padding
            Padding = new Vector2(3, 3);

            // This enemy is invunreble.
            Invulnerable = true;

            // Add biting animation.
            Animations.Add(new Animation(
                               id: (int)PlungerEnemyAnimation.BITING,
                               baseFrame: Vector2.Zero,
                               frameSize: new Vector2(width, height),
                               rows: 1,
                               columns: 2,
                               msPerFrame: 150
                               ));

            // Start biting animation.
            Animations.Play((int)PlungerEnemyAnimation.BITING);

            // Create timer.
            _turnTimer = new TimedEvent(Turn, 2250);

            // Start timer.
            _turnTimer.Enable();
        }
Beispiel #9
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="texture"> Texture of this tile.</param>
        /// <param name="source"> Location of the image.</param>
        /// <param name="position"> Location in game.</param>
        /// <param name="width"> Width of the tile.</param>
        /// <param name="height"> Height of the tile.</param>
        /// <param name="collidable"> Collidable state of the tile.</param>
        /// <param name="level"> The level the Tile is in.</param>
        public Tile(Texture2D texture, Rectangle source, Vector2 position, int width, int height, bool collidable, Level level) :
            base(position, width, height, level)
        {
            // Texture of this tile
            Sprite = new MonoSprite(texture, source, position, width, height);

            // Default cornerside is none.
            CornerSide = Corner.NONE;

            // Tiles should not check for collision on their own.
            CheckCollisions = false;

            Collidable = collidable;
        }
Beispiel #10
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="position"> Location in game.</param>
        /// <param name="content"> The content manager to get the texture from.</param>
        /// <param name="level"> The level the coin is in.</param>
        public Coin(Vector2 position, ContentManager content, Level level) :
            base(position, 12, 16, level)
        {
            _score = level.Score;

            Sprite = new MonoSprite(content.Load <Texture2D>("Images/Item/Coin"), new Rectangle(0, 0, 12, 16), position, 12, 16);

            // Make it float.
            Gravity = 0;

            // Coin is not solid.
            Solid = false;

            // Coin does't check for collisions on its own.
            CheckCollisions = false;

            // Set max spawn distance to 20.
            _maxSpawnDistance = 20;

            // Set max spawn speed to 100.
            _spawnSpeed = 100;

            _disappearSound = content.Load <SoundEffect>("Audio/smw_coin");

            // Add rotating animation.
            Animations.Add(new Animation(
                               id: (int)CoinAnimation.ROTATING,
                               baseFrame: Vector2.Zero,
                               frameSize: new Vector2(12, 16),
                               rows: 1,
                               columns: 4,
                               msPerFrame: 125
                               ));

            // Add spawning animation.
            Animations.Add(new Animation(
                               id: (int)CoinAnimation.SPAWNING,
                               baseFrame: Vector2.Zero,
                               frameSize: new Vector2(12, 16),
                               rows: 1,
                               columns: 1,
                               msPerFrame: 0
                               ));

            // On default start the rotating animation.
            Animations.Play((int)CoinAnimation.ROTATING);
        }
Beispiel #11
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="position"> Location in game.</param>
        /// <param name="width"> Width of the ChickenEnemy.</param>
        /// <param name="height"> Height of the ChickenEnemy.</param>
        /// <param name="content"> The content manager.</param>
        /// <param name="level"> The level the ChickenEnemy is in.</param>
        public ChickenEnemy(Vector2 position, int width, int height, ContentManager content, Level level) :
            base(position, width, height, level)
        {
            Padding  = new Vector2(1, 10);
            _content = content;

            Sprite = new MonoSprite(content.Load <Texture2D>("Images/Enemy/ChickenEnemy"), new Rectangle(0, 27, width, height), position, width, height);

            // Set terminal velocity.
            TerminalVelocity = new Vector2(70, 350);

            // Add walking animation.
            Animations.Add(new Animation(
                               id: (int)ChickenEnemyAnimation.WALKING,
                               baseFrame: new Vector2(16, 0),
                               frameSize: new Vector2(width, height),
                               rows: 1,
                               columns: 2,
                               msPerFrame: 150
                               ));

            // Add turning animation.
            Animations.Add(new Animation(
                               id: (int)ChickenEnemyAnimation.TURNING,
                               baseFrame: Vector2.Zero,
                               frameSize: new Vector2(width, height),
                               rows: 1,
                               columns: 1,
                               msPerFrame: 175
                               ));

            // Add death animation.
            Animations.Add(new Animation(
                               id: (int)ChickenEnemyAnimation.DEATH,
                               baseFrame: new Vector2(48, 0),
                               frameSize: new Vector2(16, 15),
                               rows: 1,
                               columns: 1,
                               msPerFrame: 0
                               ));

            // By default play the walking animation.
            Animations.Play((int)ChickenEnemyAnimation.WALKING);

            // Set horizontal velocity to the terminal horizontal velocity.
            velocity.X = TerminalVelocity.X;
        }
Beispiel #12
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="level"> The level.</param>
        /// <param name="camera"> The camera.</param>
        /// <param name="content"> The content manager.</param>
        public HUD(Level level, Camera2D camera, ContentManager content)
        {
            // Get background texture.
            Texture2D texture = content.Load <Texture2D>("Images/HUD");

            // Set level.
            _level = level;

            // Set camera.
            _camera = camera;

            // Set background texture.
            _background = new MonoSprite(texture, new Rectangle(0, 0, 256, 28), new Vector2(0, 5), 256, 28);

            // Set player name texture.
            _playerName = new MonoSprite(texture, new Rectangle(0, 0, 0, 0), new Vector2(14, 10), 40, 8);

            // rectangle to store location of playername.
            Rectangle playerNameSource;

            // If player is protagonist use this texture.
            if (level.TypePlayer == Level.PlayerType.PROTAGONIST)
            {
                playerNameSource = new Rectangle(0, 28, 40, 8);
            }
            // If player is luigi use this texture.
            else
            {
                playerNameSource = new Rectangle(40, 28, 40, 8);
            }

            // Set player name source.
            _playerName.source = playerNameSource;

            // Set the font.
            _font = content.Load <SpriteFont>("Font/PixelFont");

            // Set the scale.
            _scale = SuperPlatformerGame.SCALE;

            // set locations to draw text.
            _livesPosition       = new Vector2(35 * _scale, 19 * _scale);
            _currentTimePosition = new Vector2(153 * _scale, 20 * _scale);
            _totalCoinsPosition  = new Vector2(227 * _scale, 10 * _scale);
            _totalScorePosition  = new Vector2(200 * _scale, 20 * _scale);
        }
Beispiel #13
0
        /// <summary>
        /// Initialize scene.
        /// </summary>
        public override void Init()
        {
            // Call base init.
            base.Init();

            // Set texture of the scene.
            Texture2D texture = Game.Content.Load <Texture2D>("Images/Screens/Nintendo");

            // Load the nintendo logo.
            MonoSprite logo = new MonoSprite(texture, new Rectangle(0, 0, SuperPlatformerGame.RESOLUTION_X, SuperPlatformerGame.RESOLUTION_Y), Vector2.Zero, SuperPlatformerGame.RESOLUTION_X, SuperPlatformerGame.RESOLUTION_Y);

            // Add the logo to the drawlist.
            Children.Add(logo);

            // Set and start the timer.
            _introPhaseTimer = new TimedEvent(OnIntroPhaseTimerElapsed, _introPhaseDuration);
            _introPhaseTimer.Enable();
        }
Beispiel #14
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="camera"> The camera.</param>
        /// <param name="backgroundLeft"> Left background sprite.</param>
        /// <param name="backgroundRight"> Right background sprite.</param>
        public ParallaxBackground(Camera2D camera, MonoSprite backgroundLeft, MonoSprite backgroundRight)
        {
            // Set the scale.
            _scale = SuperPlatformerGame.SCALE;

            // Set the paralax effect strength.
            _parallaxEffect = 3f;

            // Set the camera.
            _camera = camera;

            // Create the backgrounds list.
            _backgrounds = new List <MonoSprite>();

            // Add the backgrounds.
            _backgrounds.Add(backgroundLeft);
            _backgrounds.Add(backgroundRight);
        }
Beispiel #15
0
        /// <summary>
        /// Load the level.
        /// </summary>
        /// <param name="game"> The game object.</param>
        /// <param name="fileName"> The filename of the level file.</param>
        public void Load(SuperPlatformerGame game, string fileName)
        {
            _loader = new LevelLoader(_title, this, game);

            _loader.Parse(@"Resources/Data/" + fileName + ".json");

            // Load background
            Texture2D texture = game.Content.Load <Texture2D>(_loader.GetBackgroundPath());

            MonoSprite backgroundImageLeft  = new MonoSprite(texture, new Rectangle(0, 0, 512, 432), Vector2.Zero, 512, 432);
            MonoSprite backgroundImageRight = new MonoSprite(texture, new Rectangle(0, 0, 512, 432), Vector2.Zero, 512, 432);

            _background = new ParallaxBackground(_camera, backgroundImageLeft, backgroundImageRight);

            // Set the current time to the given level duration
            CurrentTime = _loader.GetTotalTime();

            // Set the given tilesize
            _tileSize = _loader.GetTileSize();

            // Initialize the background tiles
            _loader.InitializeBackgroundTiles(out _backgroundTiles);

            // Initialize the decorations
            _loader.InitializeDecoration(out _decorations);

            // Set the player spawn point
            _spawn = _loader.GetSpawnPoint();

            // Initialize the player's position
            Player.Position = _spawn;

            // Load entities
            LoadEntities();

            // Set pixel sizes
            PixelSizeX = (_loader.TilesX * _tileSize) * (int)_scale;
            PixelSizeY = (_loader.TilesY * _tileSize) * (int)_scale;

            // Set camera bounds
            _camera.SetBounds(PixelSizeX, PixelSizeY);
        }
Beispiel #16
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="position"> Location in game.</param>
        /// <param name="width"> Width of the FlowerEnemy.</param>
        /// <param name="height"> Height of the FlowerEnemy.</param>
        /// <param name="content"> The content manager.</param>
        /// <param name="level"> The level the FlowerEnemy is in.</param>
        public FlowerEnemy(Vector2 position, int width, int height, ContentManager content, Level level) :
            base(position, width, height, level)
        {
            Sprite = new MonoSprite(content.Load <Texture2D>("Images/Enemy/FlowerEnemy"), new Rectangle(0, 16, width, height), position, width, height);

            // This enemy is invulnerable.
            Invulnerable = true;

            // Add biting animation.
            Animations.Add(new Animation(
                               id: (int)FlowerEnemyAnimation.BITING,
                               baseFrame: Vector2.Zero,
                               frameSize: new Vector2(width, height),
                               rows: 1,
                               columns: 2,
                               msPerFrame: 150
                               ));

            // Start biting animation.
            Animations.Play((int)FlowerEnemyAnimation.BITING);
        }
Beispiel #17
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="position"> Location in game.</param>
        /// <param name="width"> Width.</param>
        /// <param name="height"> Height.</param>
        /// <param name="totalCoins"> Total amount of coins.</param>
        /// <param name="level"> The level this block belongs to.</param>
        /// <param name="content"> The content manager.</param>
        public ValueBlock(Vector2 position, int width, int height, int totalCoins, ContentManager content, Level level) :
            base(position, width, height, level)
        {
            _content = content;

            // Let the block float
            Gravity = 0;

            // Texture
            Sprite = new MonoSprite(content.Load <Texture2D>("Images/Tile/Blocks"), new Rectangle(0, 16, 16, 16), position, width, height);

            // Set amount of coins.
            _coins = totalCoins;

            // Coin does't check for collisions on its own.
            CheckCollisions = false;

            // Add solid animation.
            Animations.Add(new Animation(
                               id: (int)ValueBlockAnimations.SOLID,
                               baseFrame: new Vector2(0, 16),
                               frameSize: new Vector2(width, height),
                               rows: 1,
                               columns: 1,
                               msPerFrame: 125
                               ));

            // Add wood animation.
            Animations.Add(new Animation(
                               id: (int)ValueBlockAnimations.WOOD,
                               baseFrame: new Vector2(64, 0),
                               frameSize: new Vector2(width, height),
                               rows: 1,
                               columns: 1,
                               msPerFrame: 50
                               ));

            // By default play solid animation.
            Animations.Play((int)ValueBlockAnimations.SOLID);
        }
Beispiel #18
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="position"> Location in game.</param>
        /// <param name="width"> Width of the EggEnemy.</param>
        /// <param name="height"> Height of the EggEnemy.</param>
        /// <param name="content"> Content manager of the game.</param>
        /// <param name="level"> The level the EggEnemy is in.</param>
        public EggEnemy(Vector2 position, int width, int height, ContentManager content, Level level) :
            base(position, width, height, level)
        {
            Sprite = new MonoSprite(content.Load <Texture2D>("Images/Enemy/EggEnemy"), new Rectangle(32, 0, width, height), position, width, height);

            // EggEnemy is invulnerable.
            Invulnerable = true;

            // By default shell lays still.
            AllowMovement = false;

            // Set the terminal velocity of the shell.
            TerminalVelocity = new Vector2(110f, 150f);

            _startMovingSound = content.Load <SoundEffect>("Audio/smw_kick");

            // Add idle animation.
            Animations.Add(new Animation(
                               id: (int)EggEnemyAnimation.IDLE,
                               baseFrame: Vector2.Zero,
                               frameSize: new Vector2(width, height),
                               rows: 1,
                               columns: 1,
                               msPerFrame: 50
                               ));

            // Add moving animation.
            Animations.Add(new Animation(
                               id: (int)EggEnemyAnimation.MOVING,
                               baseFrame: Vector2.Zero,
                               frameSize: new Vector2(width, height),
                               rows: 1,
                               columns: 4,
                               msPerFrame: 85
                               ));

            // Play the idle animation.
            Animations.Play((int)EggEnemyAnimation.IDLE);
        }
Beispiel #19
0
        /// <summary>
        /// Initialize decoration.
        /// </summary>
        /// <param name="decorations"> List of decorations.</param>
        public void InitializeDecoration(out List <MonoSprite> decorations)
        {
            decorations = new List <MonoSprite>();

            Texture2D signTexture = _game.Content.Load <Texture2D>("Images/Decoration/Waypoint");
            Texture2D bushTexture = _game.Content.Load <Texture2D>("Images/Decoration/Bush");

            JToken[] decorationData = JsonConvert.DeserializeObject <JToken[]>(_entityData.GetValue("decoration").ToString());
            int      tileSize       = GetTileSize();

            int        i;
            JToken     deco;
            MonoSprite sprite;

            for (i = 0; i < decorationData.Length; i++)
            {
                deco   = decorationData[i];
                sprite = null;

                switch ((DecorationType)((int)deco["id"]))
                {
                case DecorationType.SIGN:
                    int translationX = 8;

                    sprite = new MonoSprite(signTexture, new Rectangle(0, 0, 32, 24), new Vector2(((int)deco["x"]) * tileSize, ((int)deco["y"]) * tileSize + translationX), 32, 24);
                    break;

                case DecorationType.BUSH:
                    sprite = new MonoSprite(bushTexture, new Rectangle((int)deco["subtype"] * tileSize, 0, 16, 16), new Vector2(((int)deco["x"]) * tileSize, ((int)deco["y"]) * tileSize), 16, 16);
                    break;
                }

                if (sprite != null)
                {
                    decorations.Add(sprite);
                }
            }
        }
Beispiel #20
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="texture"> Texture.</param>
        /// <param name="position"> Location in game.</param>
        /// <param name="width"> Width.</param>
        /// <param name="height"> Height.</param>
        /// <param name="keyboard"> Keyboard device.</param>
        /// <param name="level"> The level the player is in.</param>
        /// <param name="content"> The content manager.</param>
        public Player(Texture2D texture, Vector2 position, int width, int height, KeyboardInput keyboard, Level level, ContentManager content) :
            base(position, width, height, level)
        {
            Sprite       = new MonoSprite(texture, new Rectangle(80, 10, width, height), position, width, height);
            Padding      = new Vector2(3, 3);
            Invulnerable = false;
            EnableInput();
            MaxLives  = 3;
            Lives     = MaxLives;
            _keyboard = keyboard;

            _timesFlickered = 0;
            _flickerTimer   = new TimedEvent(Flicker, 80);

            _sounds = new Dictionary <string, SoundEffect>()
            {
                { "jump", content.Load <SoundEffect>("Audio/smw_jump") },
                { "grow", content.Load <SoundEffect>("Audio/smw_powerup") },
                { "shrink", content.Load <SoundEffect>("Audio/smw_powerdown") },
                { "death", content.Load <SoundEffect>("Audio/smw_lostalife") },
                { "peace", content.Load <SoundEffect>("Audio/smw_courseclear") }
            };

            TerminalVelocity = new Vector2(150, 350);
            Acceleration     = 290;
            JumpImpulse      = _smallJumpImpulse;

            Grounded      = false;
            _allowWalking = true;

            Animations.Add(new Animation(
                               id: (int)PlayerAnimation.SMALL_LOOKUP,
                               baseFrame: new Vector2(114, 10),
                               frameSize: new Vector2(width, height),
                               rows: 1,
                               columns: 1,
                               msPerFrame: 50
                               ));

            Animations.Add(new Animation(
                               id: (int)PlayerAnimation.SMALL_WALK,
                               baseFrame: new Vector2(0, 10),
                               frameSize: new Vector2(width, height),
                               rows: 1,
                               columns: 2,
                               msPerFrame: 110
                               ));

            Animations.Add(new Animation(
                               id: (int)PlayerAnimation.SMALL_IDLE,
                               baseFrame: new Vector2(0, 10),
                               frameSize: new Vector2(width, height),
                               rows: 1,
                               columns: 1,
                               msPerFrame: 50
                               ));

            Animations.Add(new Animation(
                               id: (int)PlayerAnimation.SMALL_DUCK,
                               baseFrame: new Vector2(96, 10),
                               frameSize: new Vector2(width, height),
                               rows: 1,
                               columns: 1,
                               msPerFrame: 175
                               ));

            Animations.Add(new Animation(
                               id: (int)PlayerAnimation.SMALL_JUMP,
                               baseFrame: new Vector2(64, 10),
                               frameSize: new Vector2(width, height),
                               rows: 1,
                               columns: 1,
                               msPerFrame: 175
                               ));

            Animations.Add(new Animation(
                               id: (int)PlayerAnimation.SMALL_FALL,
                               baseFrame: new Vector2(80, 10),
                               frameSize: new Vector2(width, height),
                               rows: 1,
                               columns: 1,
                               msPerFrame: 175
                               ));

            Animations.Add(new Animation(
                               id: (int)PlayerAnimation.BIG_LOOKUP,
                               baseFrame: new Vector2(145, 32),
                               frameSize: new Vector2(_bigWidth, _bigHeight),
                               rows: 1,
                               columns: 1,
                               msPerFrame: 50
                               ));

            Animations.Add(new Animation(
                               id: (int)PlayerAnimation.BIG_WALK,
                               baseFrame: new Vector2(0, 32),
                               frameSize: new Vector2(_bigWidth, _bigHeight),
                               rows: 1,
                               columns: 2,
                               msPerFrame: 110
                               ));

            Animations.Add(new Animation(
                               id: (int)PlayerAnimation.BIG_IDLE,
                               baseFrame: new Vector2(0, 32),
                               frameSize: new Vector2(_bigWidth, _bigHeight),
                               rows: 1,
                               columns: 1,
                               msPerFrame: 175
                               ));

            Animations.Add(new Animation(
                               id: (int)PlayerAnimation.BIG_DUCK,
                               baseFrame: new Vector2(128, 32),
                               frameSize: new Vector2(_bigWidth, _bigHeight),
                               rows: 1,
                               columns: 1,
                               msPerFrame: 175
                               ));

            Animations.Add(new Animation(
                               id: (int)PlayerAnimation.BIG_JUMP,
                               baseFrame: new Vector2(96, 32),
                               frameSize: new Vector2(_bigWidth, _bigHeight),
                               rows: 1,
                               columns: 1,
                               msPerFrame: 175
                               ));

            Animations.Add(new Animation(
                               id: (int)PlayerAnimation.BIG_FALL,
                               baseFrame: new Vector2(112, 32),
                               frameSize: new Vector2(_bigWidth, _bigHeight),
                               rows: 1,
                               columns: 1,
                               msPerFrame: 175
                               ));

            Animations.Add(new Animation(
                               id: (int)PlayerAnimation.DEATH,
                               baseFrame: new Vector2(131, 8),
                               frameSize: new Vector2(15, 24),
                               rows: 1,
                               columns: 2,
                               msPerFrame: 135
                               ));

            Animations.Add(new Animation(
                               id: (int)PlayerAnimation.SMALL_PEACE,
                               baseFrame: new Vector2(162, 10),
                               frameSize: new Vector2(16, 21),
                               rows: 1,
                               columns: 1,
                               msPerFrame: 0
                               ));

            Animations.Add(new Animation(
                               id: (int)PlayerAnimation.BIG_PEACE,
                               baseFrame: new Vector2(162, 36),
                               frameSize: new Vector2(16, 28),
                               rows: 1,
                               columns: 1,
                               msPerFrame: 0
                               ));
        }