//----------------------//------------------------//

        public GameCoin(Texture2D texture, Rectangle[] frames, int delay, int x, int y, Vector2 velocity, bool applyPhysics = false)
        {
            CoinSprite = new AnimatedSprite(texture, frames, delay, x, y, true);
            Position = new Vector2(x, y);
            Velocity = velocity;
            _applyPhysics = applyPhysics;
            _xAcceleration = 0f;
        }
        //----------------------//------------------------//

        public Player(Texture2D texture) : base(texture)
        {
            // Stand
            CharacterSprite.CreateFrameList("stand", 140);
            CharacterSprite.AddCollider("stand", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFrames("stand", new List<Rectangle>()
            {
                new Rectangle(0, 0, 32, 32),
                new Rectangle(32, 0, 32, 32),
                new Rectangle(64, 0, 32, 32),
                new Rectangle(96, 0, 32, 32),
            }, new int[] { 0, 0, 0, 0 }, new int[] { 0, 0, 0, 0 });

            // Stand with hat
            CharacterSprite.CreateFrameList("stand_with_hat", 140);
            CharacterSprite.AddCollider("stand_with_hat", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFrames("stand_with_hat", new List<Rectangle>()
            {
                new Rectangle(128, 192, 32, 64),
                new Rectangle(160, 192, 32, 64),
                new Rectangle(192, 192, 32, 64),
                new Rectangle(224, 192, 32, 64),
            }, new int[] { 0, 0, 0, 0 }, new int[] { -32, -32, -32, -32 });

            // Walking
            CharacterSprite.CreateFrameList("walking", 120);
            CharacterSprite.AddCollider("walking", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFrames("walking", new List<Rectangle>()
            {
                new Rectangle(128, 0, 32, 32),
                new Rectangle(160, 0, 32, 32),
                new Rectangle(192, 0, 32, 32),
                new Rectangle(224, 0, 32, 32),
            }, new int[] { 0, 0, 0, 0 }, new int[] { 0, 0, 0, 0 });

            // Walking with hat
            CharacterSprite.CreateFrameList("walking_with_hat", 220);
            CharacterSprite.AddCollider("walking_with_hat", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFrames("walking_with_hat", new List<Rectangle>()
            {
                new Rectangle(32, 256, 32, 64),
                new Rectangle(64, 256, 32, 64),
                new Rectangle(96, 256, 32, 64),
                new Rectangle(128, 256, 32, 64),
            }, new int[] { 0, 0, 0, 0 }, new int[] { -32, -32, -32, -32 });

            // Jumping
            CharacterSprite.CreateFrameList("jumping", 0);
            CharacterSprite.AddCollider("jumping", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFrames("jumping", new List<Rectangle>()
            {
                new Rectangle(0, 32, 32, 32)
            }, new int[] { 0, 0, 0, 0 }, new int[] { 0, 0, 0, 0 });

            // Sword Attack
            CharacterSprite.CreateFrameList("attack_sword", 70);
            CharacterSprite.AddCollider("attack_sword", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFramesToAttack("attack_sword", 1, 2);
            CharacterSprite.AddFrames("attack_sword", new List<Rectangle>()
            {
                new Rectangle(32, 32, 32, 32),
                new Rectangle(64, 32, 64, 32),
                new Rectangle(128, 32, 64, 32),
                new Rectangle(192, 32, 64, 32)
            }, new int[] { 0, 0, 0, 0 }, new int[] { 0, 0, 0, 0 });

            CharacterSprite.AddAttackCollider("attack_sword", new List<List<Rectangle>>()
            {
                new List<Rectangle>() { },
                new List<Rectangle>() { new Rectangle(31, 14, 32, 6) },
                new List<Rectangle>() { new Rectangle(31, 14, 32, 6) }
            }, 64);

            // Aerial Attack
            CharacterSprite.CreateFrameList("attack_aerial", 60);
            CharacterSprite.AddCollider("attack_aerial", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFrames("attack_aerial", new List<Rectangle>()
            {
                new Rectangle(0, 64, 64, 64),
                new Rectangle(64, 64, 64, 64),
                new Rectangle(128, 64, 64, 64),
                new Rectangle(192, 64, 64, 64)
            }, new int[] { 0, 0, -32, -32 }, new int[] { -32, 0, 0, -32 });
            CharacterSprite.AddAttackCollider("attack_aerial", new List<List<Rectangle>>()
            {
                new List<Rectangle>()
                {
                    new Rectangle(25, -21, 27, 21),
                    new Rectangle(31, 0, 25, 27)
                },

                new List<Rectangle>()
                {
                    new Rectangle(32, 25, 21, 27),
                    new Rectangle(5, 31, 27, 25)
                },

                new List<Rectangle>()
                {
                    new Rectangle(-20, 32, 27, 21),
                    new Rectangle(-24, 5, 25, 27)
                },

                new List<Rectangle>()
                {
                    new Rectangle(-21, -20, 21, 27),
                    new Rectangle(0, -24, 27, 25)
                }
            }, 64);
            CharacterSprite.AddFramesToAttack("attack_aerial", 0, 1, 2, 3);

            // Shot Attack
            CharacterSprite.CreateFrameList("attack_shot", 80);
            CharacterSprite.AddCollider("attack_shot", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFramesToAttack("attack_shot", 2);
            CharacterSprite.AddFrames("attack_shot", new List<Rectangle>()
            {
                new Rectangle(0, 128, 32, 32),
                new Rectangle(32, 128, 64, 32),
                new Rectangle(96, 128, 64, 32),
                new Rectangle(160, 128, 64, 32)
            }, new int[] { 0, 0, 0, 0 }, new int[] { 0, 0, 0, 0 });

            // Shot Attack Jumping
            CharacterSprite.CreateFrameList("attack_shot_jumping", 50);
            CharacterSprite.AddCollider("attack_shot_jumping", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFramesToAttack("attack_shot_jumping", 3);
            CharacterSprite.AddFrames("attack_shot_jumping", new List<Rectangle>()
            {
                new Rectangle(0, 160, 32, 32),
                new Rectangle(32, 160, 64, 32),
                new Rectangle(96, 160, 64, 32),
                new Rectangle(160, 160, 64, 32)
            }, new int[] { 0, 0, 0, 0 }, new int[] { 0, 0, 0, 0 });

            // Hat Received
            CharacterSprite.CreateFrameList("hat_received", 1000, false);
            CharacterSprite.AddCollider("hat_received", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFrames("hat_received", new List<Rectangle>()
            {
                new Rectangle(0, 192, 32, 64),
                new Rectangle(32, 192, 32, 64),
            }, new int[] { 0, 0, 0, 0 }, new int[] { -32, -32, -32, -32 });

            // Thumbs up
            CharacterSprite.CreateFrameList("thumbs_up", 140, false);
            CharacterSprite.AddCollider("thumbs_up", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFrames("thumbs_up", new List<Rectangle>()
            {
                new Rectangle(64, 192, 32, 64),
                new Rectangle(96, 192, 32, 64),
            }, new int[] { 0, 0, 0, 0 }, new int[] { -32, -32, -32, -32 });

            // Looking up
            CharacterSprite.CreateFrameList("looking_up", 140);
            CharacterSprite.AddCollider("looking_up", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFrames("looking_up", new List<Rectangle>()
            {
                new Rectangle(0, 256, 32, 64),
            }, new int[] { 0, 0, 0, 0 }, new int[] { -32, -32, -32, -32 });

            // Looking up with hat
            CharacterSprite.CreateFrameList("looking_up_with_hat", 140);
            CharacterSprite.AddCollider("looking_up_with_hat", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFrames("looking_up_with_hat", new List<Rectangle>()
            {
                new Rectangle(0, 192, 32, 64),
            }, new int[] { 0, 0, 0, 0 }, new int[] { -32, -32, -32, -32 });

            Position = new Vector2(32, 160);

            // Attacks setup
            _attackFrameList = new string[]
            {
                "attack_sword",
                "attack_aerial",
                "attack_shot",
                "attack_shot_jumping"
            };

            AttackCooldown = 300f;
            _deathTick = 0.0f;
            _requestRespawn = false;
            _active = true;
            _keysLocked = false;

            // Hat drop
            var hatTexture = ImageManager.loadMisc("PeteHat");
            _hatSprite = new AnimatedSprite(hatTexture, new Rectangle[] {
                new Rectangle(0, 0, 96, 64),
                new Rectangle(96, 0, 96, 64),
                new Rectangle(192, 0, 96, 64),
                new Rectangle(288, 0, 96, 64),
                new Rectangle(384, 0, 96, 64),
                new Rectangle(0, 64, 96, 64),
                new Rectangle(96, 64, 96, 64),
                new Rectangle(192, 64, 96, 64),
                new Rectangle(288, 64, 96, 64),
                new Rectangle(384, 64, 96, 64),
            }, 100, Vector2.Zero);
            _hatSprite.Origin = new Vector2(50, 37);

            // Flash texture
            _flashTexture = new Texture2D(SceneManager.Instance.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
            _flashTexture.SetData(new Color[] { Color.White });

            // SEs init
            _aerialAttackSe = SoundManager.LoadSe("Aerial");
            _normalAttackSe = SoundManager.LoadSe("Sword");
            _shotEmptyAttackSe = SoundManager.LoadSe("ShotPeteEmpty");
            _footstepSe = SoundManager.LoadSe("Footstep");
            _hatSe = SoundManager.LoadSe("Hat");
        }
Exemplo n.º 3
0
        private void UpdateCollapse(GameTime gameTime)
        {
            if (_hudAlpha > 0.0f)
            {
                _hudAlpha -= (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            if (_collapseOpacityTime == 0)
            {
                _flashScreenAlpha += (float)gameTime.ElapsedGameTime.TotalMilliseconds / _flashScreenTime;
                if (_flashScreenAlpha > 1.3f)
                {
                    _collapseOpacityTime = CollapseOpacityTimeMax;
                    EraseCannons();
                }
            }
            else if (_flashScreenAlpha > 0.0f)
            {
                _flashScreenAlpha -= (float)gameTime.ElapsedGameTime.TotalSeconds * 2;
            }
            else if (CharacterSprite.Alpha > 0.0f)
            {
                CharacterSprite.Alpha -= (float)gameTime.ElapsedGameTime.TotalMilliseconds / _collapseOpacityTime;
            }
            else if (CharacterSprite.Alpha <= 0.0f)
            {
                _requestingHatDrop = true;
                _requestErase = true;
            }

            var explosionsToRemove = new List<CollapseExplosion>();
            var explosionsSpriteToRemove = new List<AnimatedSprite>();
            for (var i = 0; i < _collapseExplosionsQueue.Count; i++)
            {
                var explosion = _collapseExplosionsQueue[i];
                if (explosion.Delay <= 0)
                {
                    var texture = ImageManager.loadMisc("Explosion");
                    var frames = new Rectangle[]
                    {
                        new Rectangle(0, 0, 96, 96),
                        new Rectangle(96, 0, 96, 96),
                        new Rectangle(192, 0, 96, 96),
                        new Rectangle(288, 0, 96, 96),
                        new Rectangle(384, 0, 96, 96),
                        new Rectangle(480, 0, 96, 96),
                        new Rectangle(576, 0, 96, 96)
                    };
                    var position = new Vector2(BoundingRectangle.Left - 48, BoundingRectangle.Top - 84) + explosion.Position;
                    var sprite = new AnimatedSprite(texture, frames, 120, position, false);
                    _collapseExplosions.Add(sprite);
                    explosionsToRemove.Add(explosion);
                    _explosionsSes[_rand.Next(3)].PlaySafe();
                }
                else
                {
                    explosion.Delay -= (float)gameTime.ElapsedGameTime.TotalMilliseconds;
                }
            }

            explosionsToRemove.ForEach(x => _collapseExplosionsQueue.Remove(x));
            
            foreach (var explosionSprite in _collapseExplosions)
            {
                explosionSprite.Update(gameTime);
                if (explosionSprite.Looped)
                {
                    explosionsSpriteToRemove.Add(explosionSprite);
                }
            }

            explosionsSpriteToRemove.ForEach(x => _collapseExplosions.Remove(x));
        }
        private void SetupMap()
        {
            var maxLevels = SceneManager.MaxLevels;
            _stageSelectionPositions = new Vector2[]
            {
                new Vector2(111, 130),
                new Vector2(151, 88),
                new Vector2(192, 172),
                new Vector2(231, 126),
                new Vector2(278, 134)
            };
            var currentStage = MathHelper.Clamp(GetCurrentStage(), 0, 4);
            var nextLevelPos = _stageSelectionPositions[currentStage];
            var currentLevelPos = _stageSelectionPositions[Math.Max(currentStage, 0)];
            var stageSelectionPosition = GetCurrentStage() > maxLevels ? _stageSelectionPositions[0] : GetCurrentStage() >= maxLevels ? currentLevelPos : nextLevelPos;

            _stageSelectionSpritesheet = ImageManager.loadScene(ScenePathName, "StageSelectionSpritesheet");
            var stageSelectionFrames = new Rectangle[]
            {
                new Rectangle(0, 0, 19, 19),
                new Rectangle(19, 0, 19, 19),
                new Rectangle(38, 0, 19, 19),
                new Rectangle(57, 0, 19, 19)
            };
            _stageSelectionSprite = new AnimatedSprite(_stageSelectionSpritesheet, stageSelectionFrames, 130, 
                (int)stageSelectionPosition.X, (int)stageSelectionPosition.Y);

            _stageSelectionSprite.Origin = new Vector2(9, 9);

            if (GetCurrentStage() == maxLevels)
                _stageSelectionSprite.IsVisible = false;

            var _stageSelectionPeteSpritesheet = ImageManager.loadScene(ScenePathName, "StageSelectionPeteSpritesheet");
            var _stageSelectionPeteFrames = new Rectangle[]
            {
                new Rectangle(0, 0, 32, 32),
                new Rectangle(32, 0, 32, 32),
                new Rectangle(64, 0, 32, 32),
                new Rectangle(96, 0, 32, 32),
                new Rectangle(128, 0, 32, 32),
                new Rectangle(160, 0, 32, 32),
                new Rectangle(192, 0, 32, 32),
                new Rectangle(224, 0, 32, 32)
            };
            _stageSelectionPeteSprite = new AnimatedSprite(_stageSelectionPeteSpritesheet, _stageSelectionPeteFrames, 100,
                (int)stageSelectionPosition.X, (int)stageSelectionPosition.Y);
            _stageSelectionPeteSprite.Origin = new Vector2(16, 24);

            var stringSize = SceneManager.Instance.GameFont.MeasureString(MapPressMessage);
            _pressZTextPosition = new Vector2(
                62 + (288 - (int)stringSize.X) / 2,
                SceneManager.Instance.VirtualSize.Y - stringSize.Y - 15
            );
            _pressZTextInitY = _pressZTextPosition.Y;
            _pressZTextSide = true;

            UpdatePeteHeadPosition();
        }
        //----------------------//------------------------//

        public override void LoadContent()
        {
            base.LoadContent();

            // Strings init
            _titleStrings = new Dictionary<SceneManager.SceneSavesType, string>()
            {
                { SceneManager.SceneSavesType.Save, "Save Game"},
                { SceneManager.SceneSavesType.Load, "Load Game" }
            };

            // Textures init
            _loadingBackgroundTexture = new Texture2D(SceneManager.Instance.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
            _loadingBackgroundTexture.SetData<Color>(new Color[] { Color.Black });

            _backgroundTexture = ImageManager.loadScene("saves", "SceneSavesBackground");
            _peteSpritesheet = ImageManager.loadScene("saves", "PeteSpritesheet");
            _stageSpritesheet = ImageManager.loadScene("saves", "StageSelectionSpritesheet");
            _iconsSpritesheet = ImageManager.loadSystem("IconsSpritesheet");

            var loadingSpritesheet = ImageManager.loadScene("saves", "SavesLoadingSpritesheet");
            var loadingFrames = new Rectangle[]
            {
                new Rectangle(0, 0, 32, 32),
                new Rectangle(32, 0, 32, 32),
                new Rectangle(64, 0, 32, 32)
            };
            _loadingAnimatedSprite = new AnimatedSprite(loadingSpritesheet, loadingFrames, 200,
                new Vector2(SceneManager.Instance.VirtualSize.X - 35, SceneManager.Instance.VirtualSize.Y - 36));

            var peteFrames = new Rectangle[]
            {
                new Rectangle(0, 0, 32, 32),
                new Rectangle(32, 0, 32, 32),
                new Rectangle(64, 0, 32, 32),
                new Rectangle(96, 0, 32, 32),
                new Rectangle(128, 0, 32, 32),
                new Rectangle(160, 0, 32, 32),
                new Rectangle(192, 0, 32, 32),
                new Rectangle(224, 0, 32, 32)
            };
            _peteAnimatedSprite = new AnimatedSprite(_peteSpritesheet, peteFrames, 100, _peteHeadPosition);
            var nextStageMarkFrames = new Rectangle[]
            {
                new Rectangle(0, 0, 19, 19),
                new Rectangle(19, 0, 19, 19),
                new Rectangle(38, 0, 19, 19),
                new Rectangle(57, 0, 19, 19)
            };
            _nextStageMarkAnimatedSprite = new AnimatedSprite(_stageSpritesheet, nextStageMarkFrames, 130, _stagesPosition);

            _peteDefaultFrame = new Rectangle(0, 0, 32, 32);
            _stagePeteMarkFrame = new Rectangle(76, 0, 19, 19);
            _stageNextMarkFrame = new Rectangle(57, 0, 19, 19);
            _stageDivisorFrame = new Rectangle(95, 9, 2, 1);
            _heartFrame = new Rectangle(0, 0, 11, 10);
            _lifeFrame = new Rectangle(0, 10, 13, 14);
            _ammoFrame = new Rectangle(0, 24, 20, 9);
            _coinFrame = new Rectangle(0, 33, 20, 14);

            // Font color init
            _fontColor = new Color(31, 29, 28);
            _secFontColor = new Color(222, 196, 158);

            // Slots init
            _slotsPosition = new Rectangle[]
            {
                new Rectangle(41, 46, 279, 45),
                new Rectangle(41, 109, 279, 45),
                new Rectangle(41, 169, 279, 45)
            };

            _slotIndex = 0;

            // Positions init
            _peteHeadPosition = new Vector2(0, 5);
            _namePosition = new Vector2(40, 1);
            _stagesPosition = new Vector2(39, 18);
            _livesPosition = new Vector2(3, 2);
            _heartsPosition = new Vector2(3, 17);
            _ammoPosition = new Vector2(184, 33);
            _ammoTextPosition = new Vector2(206, 30);
            _coinsPosition = new Vector2(228, 28);
            _coinsTextPosition = new Vector2(250, 30);

            // Arrow init
            _arrowPosition = new Vector2(10, _slotsPosition[_slotIndex].Y + (_slotsPosition[_slotIndex].Height - 15) / 2);

            // General variables
            _loadingVisible = true;
            _loadResponses = 0;

            // Play BGM
            SoundManager.StartBgm(SoundManager.BGMType.NonMap);

            ReadSaves();
        }