Пример #1
0
        public Game1()
        {
            currentGameState      = GameState.SPLASHSCREEN;
            graphics              = new GraphicsDeviceManager(this);
            graphics.IsFullScreen = false;
            Content.RootDirectory = "Content";
            graphics.PreferredBackBufferHeight = 1080 - 40 - 20;
            graphics.PreferredBackBufferWidth  = 1920;
            graphics.ApplyChanges();
            Window.AllowUserResizing = true;
            input.ReadImageSizeDataSheet();
            playerSpriteSheets     = new Dictionary <string, Texture2D>();
            enemySpriteSheets      = new Dictionary <string, Texture2D>();
            songDictionnary        = new Dictionary <string, Song>();
            soundEffectDictionnary = new Dictionary <string, SoundEffect>();
            levelEditor            = new LevelEditor();
            cameraOffset           = new Vector2(0, 0);
            texturesDictionary     = new Dictionary <string, Texture2D>();
            enemyList     = new List <Enemy>();
            Enums         = new Enums();
            splashScreen  = new SplashScreen();
            mainMenu      = new MainMenu();
            gameMenu      = new GameMenu();
            credits       = new Credits();
            itemUIManager = new ItemUIManager();
            minimap       = new Minimap();
            loadAndSave   = new LoadAndSave(allGameObjectList, texturesDictionary);

            //MUSIC
            turnOnMusic = true;
            //must be the first instance!
            audioManager = AudioManager.AudioManagerInstance();
        }
Пример #2
0
        //Contains Player Movement in all 4 directions and the attack
        private void PlayerControls(GameTime gameTime, List <Enemy> enemyList, List <GameObject> interactiveObject, ref List <GameObject> GameObjectsList, LoadAndSave loadAndSave, IngameMenus ingameMenus, List <GameObject> levelGameObjects, ShopKeeper shopKeeper, ItemUIManager itemUIManager, Boss hakume)
        {
            //using item:
            if ((Keyboard.GetState().IsKeyDown(Keys.F) || GamePad.GetState(0).IsButtonUp(Buttons.B)) && !previousState.IsKeyDown(Keys.B) && previousGamepadState.IsButtonDown(Buttons.B))
            {
                int temp = itemUIManager.RemoveObject();
                if (temp == (int)Enums.ObjectsID.HEALTHPOTION)
                {
                    playerHP += 0.1f;
                    if (playerHP >= 1f)
                    {
                        playerHP = 1f;
                    }
                }
                if (temp == (int)Enums.ObjectsID.POWERPOTION)
                {
                    playerDamage *= 2;
                }
                if (temp == (int)Enums.ObjectsID.JUMPPOTION)
                {
                    defaultJumpValue = -22f;
                }
            }


            mouseState = Mouse.GetState();
            if (!firstJump && !secondJump)
            {
                if (AnimationManager.currentAnimation == AnimationManager.Animations.Jump_Left ||
                    AnimationManager.currentAnimation == AnimationManager.Animations.Jump_Hat_Left ||
                    AnimationManager.currentAnimation == AnimationManager.Animations.Jump_Armor_Left ||
                    AnimationManager.currentAnimation == AnimationManager.Animations.Jump_Armor_Hat_Left)
                {
                    if (ItemUIManager.snailShellPickedUp && ItemUIManager.armorPickedUp)
                    {
                        AnimationManager.nextAnimation = AnimationManager.Animations.Walk_Armor_Hat_Left;
                    }
                    else if (ItemUIManager.snailShellPickedUp)
                    {
                        AnimationManager.nextAnimation = AnimationManager.Animations.Walk_Hat_Left;
                    }
                    else if (ItemUIManager.armorPickedUp)
                    {
                        AnimationManager.nextAnimation = AnimationManager.Animations.Walk_Armor_Left;
                    }
                    else
                    {
                        AnimationManager.nextAnimation = AnimationManager.Animations.Walk_Left;
                    }
                }
                if (AnimationManager.currentAnimation == AnimationManager.Animations.Jump_Right ||
                    AnimationManager.currentAnimation == AnimationManager.Animations.Jump_Hat_Right ||
                    AnimationManager.currentAnimation == AnimationManager.Animations.Jump_Armor_Right ||
                    AnimationManager.currentAnimation == AnimationManager.Animations.Jump_Armor_Hat_Right)
                {
                    if (ItemUIManager.snailShellPickedUp && ItemUIManager.armorPickedUp)
                    {
                        AnimationManager.nextAnimation = AnimationManager.Animations.Walk_Armor_Hat_Right;
                    }
                    else if (ItemUIManager.snailShellPickedUp)
                    {
                        AnimationManager.nextAnimation = AnimationManager.Animations.Walk_Hat_Right;
                    }
                    else if (ItemUIManager.armorPickedUp)
                    {
                        AnimationManager.nextAnimation = AnimationManager.Animations.Walk_Armor_Right;
                    }
                    else
                    {
                        AnimationManager.nextAnimation = AnimationManager.Animations.Walk_Right;
                    }
                }
            }
            if (!playerGameElementInteraction)
            {
                //if (Keyboard.GetState().IsKeyDown(Keys.P))
                //    ReducePlayerHP();
                if (Keyboard.GetState().IsKeyDown(Keys.A) || GamePad.GetState(0).ThumbSticks.Left.X < -0.5f || GamePad.GetState(0).IsButtonDown(Buttons.DPadLeft))
                {
                    //Camera won't move after simple turning
                    camera.IncreaseLeftCounter();
                    camera.ResetRightCounter();

                    //Camera moves to a direction so that you see better what is coming to you
                    camera.cameraOffset(gameTime, false, true);

                    if (firstJump == true || secondJump == true)
                    {
                        if (ItemUIManager.armorPickedUp && ItemUIManager.snailShellPickedUp)
                        {
                            AnimationManager.nextAnimation = AnimationManager.Animations.Jump_Armor_Hat_Left;
                        }
                        else if (ItemUIManager.snailShellPickedUp)
                        {
                            AnimationManager.nextAnimation = AnimationManager.Animations.Jump_Hat_Left;
                        }
                        else if (ItemUIManager.armorPickedUp)
                        {
                            AnimationManager.nextAnimation = AnimationManager.Animations.Jump_Armor_Left;
                        }
                        else
                        {
                            AnimationManager.nextAnimation = AnimationManager.Animations.Jump_Left;
                        }
                    }

                    else
                    {
                        if (ItemUIManager.armorPickedUp && ItemUIManager.snailShellPickedUp)
                        {
                            AnimationManager.nextAnimation = AnimationManager.Animations.Walk_Armor_Hat_Left;
                        }
                        else if (ItemUIManager.snailShellPickedUp)
                        {
                            AnimationManager.nextAnimation = AnimationManager.Animations.Walk_Hat_Left;
                        }
                        else if (ItemUIManager.armorPickedUp)
                        {
                            AnimationManager.nextAnimation = AnimationManager.Animations.Walk_Armor_Left;
                        }
                        else
                        {
                            AnimationManager.nextAnimation = AnimationManager.Animations.Walk_Left;
                        }
                    }


                    if (!playerGameElementInteraction)
                    {
                        velocity.X = -movementSpeed;
                    }
                    pressedLeftKey       = true;
                    facingDirectionRight = false;
                    pressedRightKey      = false;
                }
                else if (Keyboard.GetState().IsKeyDown(Keys.D) || GamePad.GetState(0).ThumbSticks.Left.X > 0.5f || GamePad.GetState(0).IsButtonDown(Buttons.DPadRight))
                {
                    //Camera won't move after simple turning
                    camera.IncreaseRightCounter();
                    camera.ResetLeftCounter();

                    //Camera moves to a direction so that you see better what is coming to you
                    camera.cameraOffset(gameTime, true, true);

                    if (firstJump || secondJump)
                    {
                        if (ItemUIManager.armorPickedUp && ItemUIManager.snailShellPickedUp)
                        {
                            AnimationManager.nextAnimation = AnimationManager.Animations.Jump_Armor_Hat_Right;
                        }
                        else if (ItemUIManager.armorPickedUp)
                        {
                            AnimationManager.nextAnimation = AnimationManager.Animations.Jump_Armor_Right;
                        }
                        else if (ItemUIManager.snailShellPickedUp)
                        {
                            AnimationManager.nextAnimation = AnimationManager.Animations.Jump_Hat_Right;
                        }
                        else
                        {
                            AnimationManager.nextAnimation = AnimationManager.Animations.Jump_Right;
                        }
                    }
                    else
                    {
                        if (ItemUIManager.armorPickedUp && ItemUIManager.snailShellPickedUp)
                        {
                            AnimationManager.nextAnimation = AnimationManager.Animations.Walk_Armor_Hat_Right;
                        }
                        else if (ItemUIManager.armorPickedUp)
                        {
                            AnimationManager.nextAnimation = AnimationManager.Animations.Walk_Armor_Right;
                        }
                        else if (ItemUIManager.snailShellPickedUp)
                        {
                            AnimationManager.nextAnimation = AnimationManager.Animations.Walk_Hat_Right;
                        }
                        else
                        {
                            AnimationManager.nextAnimation = AnimationManager.Animations.Walk_Right;
                        }
                    }
                    if (!playerGameElementInteraction)
                    {
                        velocity.X = movementSpeed;
                    }
                    facingDirectionRight = true;
                    pressedLeftKey       = false;
                    pressedRightKey      = true;
                }
                else if (Keyboard.GetState().IsKeyDown(Keys.S) /*|| GamePad.GetState(0).IsButtonDown()*/)
                {
                    velocity.Y = movementSpeed;
                }
            }
            //Player Jump Input
            if ((Keyboard.GetState().IsKeyDown(Keys.Space) && !previousState.IsKeyDown(Keys.Space) && !jumpButtonPressed) ||
                (GamePad.GetState(0).IsButtonDown(Buttons.A) && !previousGamepadState.IsButtonDown(Buttons.A) && !jumpButtonPressed))
            {
                if (facingDirectionRight)
                {
                    if (ItemUIManager.armorPickedUp && ItemUIManager.snailShellPickedUp)
                    {
                        AnimationManager.nextAnimation = AnimationManager.Animations.Jump_Armor_Hat_Right;
                    }
                    else if (ItemUIManager.armorPickedUp)
                    {
                        AnimationManager.nextAnimation = AnimationManager.Animations.Jump_Armor_Right;
                    }
                    else if (ItemUIManager.snailShellPickedUp)
                    {
                        AnimationManager.nextAnimation = AnimationManager.Animations.Jump_Hat_Right;
                    }
                    else
                    {
                        AnimationManager.nextAnimation = AnimationManager.Animations.Jump_Right;
                    }
                }
                else
                {
                    if (ItemUIManager.armorPickedUp && ItemUIManager.snailShellPickedUp)
                    {
                        AnimationManager.nextAnimation = AnimationManager.Animations.Jump_Armor_Hat_Left;
                    }
                    else if (ItemUIManager.armorPickedUp)
                    {
                        AnimationManager.nextAnimation = AnimationManager.Animations.Jump_Armor_Left;
                    }
                    else if (ItemUIManager.snailShellPickedUp)
                    {
                        AnimationManager.nextAnimation = AnimationManager.Animations.Jump_Hat_Left;
                    }
                    else
                    {
                        AnimationManager.nextAnimation = AnimationManager.Animations.Jump_Left;
                    }
                }
                jumpButtonPressed            = true;
                playerGameElementInteraction = false;
                climbAllowed  = false;
                isStanding    = false;
                gravityActive = true;
                if (firstJump == false || secondJump == false)
                {
                    jumpSpeed = defaultJumpValue;
                }
                PlayerJump();

                //MUSIC
                if (secondJump != true)
                {
                    audioManager.Play("ReggieJump");
                }
            }

            //Player Attack Input
            if ((ButtonState.Pressed == mouseState.LeftButton && cooldown == 0 && !playerGameElementInteraction) ||
                GamePad.GetState(0).IsButtonDown(Buttons.X) && cooldown == 0 && !playerGameElementInteraction)
            {
                audioManager.Play("ReggieAttack");
                audioManager.Play("ReggieGroaning");

                if (facingDirectionRight)
                {
                    if (ItemUIManager.armorPickedUp && ItemUIManager.snailShellPickedUp)
                    {
                        AnimationManager.nextAnimation = AnimationManager.Animations.Attack_Armor_Hat_Right;
                    }
                    else if (ItemUIManager.armorPickedUp)
                    {
                        AnimationManager.nextAnimation = AnimationManager.Animations.Attack_Armor_Right;
                    }
                    else if
                    (ItemUIManager.snailShellPickedUp)
                    {
                        AnimationManager.nextAnimation = AnimationManager.Animations.Attack_Hat_Right;
                    }
                    else
                    {
                        AnimationManager.nextAnimation = AnimationManager.Animations.Attack_Right;
                    }
                }
                else
                {
                    if (ItemUIManager.armorPickedUp && ItemUIManager.snailShellPickedUp)
                    {
                        AnimationManager.nextAnimation = AnimationManager.Animations.Attack_Armor_Hat_Left;
                    }
                    else if (ItemUIManager.armorPickedUp)
                    {
                        AnimationManager.nextAnimation = AnimationManager.Animations.Attack_Armor_Left;
                    }
                    else if (ItemUIManager.snailShellPickedUp)
                    {
                        AnimationManager.nextAnimation = AnimationManager.Animations.Attack_Hat_Left;
                    }
                    else
                    {
                        AnimationManager.nextAnimation = AnimationManager.Animations.Attack_Left;
                    }
                }
                // TODO: Step1 activate enemyknockback at the specific currentframe, Step2 depending on the size of an enemy (how tall)
                //foreach (var enemy in enemyList)
                //{
                //    if (PlayerAttackCollision(enemy) && enemy.EnemyAliveState() == true && !enemy.invincibilityFrames)
                //    {
                //        enemy.invincibilityFrames = true;
                //        //worm.KnockBackPosition(facingDirectionRight, 35);
                //        enemy.KnockBackPosition(facingDirectionRight);
                //    }
                //}

                if (ItemUIManager.currentItemEquipped.objectID == (int)Enums.ObjectsID.SCISSORS)
                {
                    //Platform temp = null;
                    playerDamage = 3;
                    foreach (Platform platform in levelGameObjects.Cast <GameObject>().OfType <Platform>().ToList())
                    {
                        if (DetectCollision(platform) && platform.PlatformType == (int)Enums.ObjectsID.SPIDERWEB)
                        {
                            //temp = platform;
                            levelGameObjects.Remove(platform);
                            break;
                        }
                    }
                    //GameObjectsList.Remove(temp);
                }
                if (ItemUIManager.currentItemEquipped.objectID == (int)Enums.ObjectsID.SHOVEL)
                {
                    movementSpeed    = 20f;
                    defaultJumpValue = 20f;
                }
                //TODO:Destroyable? temp
                // Platform temp = null;
                foreach (Platform platform in levelGameObjects.Cast <GameObject>().OfType <Platform>().ToList())
                {
                    if (DetectCollision(platform) && platform.PlatformType == (int)Enums.ObjectsID.VINEDOOR)
                    {
                        levelGameObjects.Remove(platform);
                        break;
                    }
                }
                //GameObjectsList.Remove(temp);



                foreach (Item item in levelGameObjects.Cast <GameObject>().OfType <Item>().ToList())
                {
                    if (item.objectID == (int)Enums.ObjectsID.APPLE)
                    {
                        if (item.gameObjectRectangle.Contains(this.gameObjectPosition))
                        {
                            ingameMenus.saveAnimStart();
                            loadAndSave.Save();
                            Console.WriteLine("Game Saved");
                            break;
                        }
                    }
                }

                foreach (ShopKeeper shopkeeper in levelGameObjects.Cast <GameObject>().OfType <ShopKeeper>().ToList())
                {
                    if (shopkeeper.objectID == (int)Enums.ObjectsID.SHOPKEEPER)
                    {
                        if (shopkeeper.gameObjectRectangle.Contains(this.gameObjectPosition))
                        {
                            shopKeeper.shopOpen = true;
                        }
                        else
                        {
                            shopKeeper.shopOpen = false;
                        }
                    }
                }

                playerAttackPressed = true;
            }

            if (playerAttackPressed)
            {
                attackTimer += (float)gameTime.ElapsedGameTime.Milliseconds / 100;
                if (attackTimer != 0 && attackTimer <= 0.5f)
                {
                    foreach (var enemy in enemyList)
                    {
                        if (PlayerAttackCollision(enemy) && enemy.EnemyAliveState() == true && !enemy.invincibilityFrames)
                        {
                            enemy.invincibilityFrames = true;
                            enemy.KnockBackPosition(facingDirectionRight, playerDamage);
                            //enemy.KnockBackPosition(facingDirectionRight);
                        }
                    }
                    if (PlayerAttackCollision(hakume))
                    {
                        hakume.ReduceEnemyHP(playerDamage);
                    }
                }
                else
                {
                    attackTimer = 0;
                }

                cooldown += (float)gameTime.ElapsedGameTime.TotalSeconds * 2;
            }
            if (cooldown >= .75)
            {
                cooldown            = 0;
                playerAttackPressed = false;
            }


            //Player Gameelement Interactive Input
            if ((ButtonState.Pressed == mouseState.RightButton || Keyboard.GetState().IsKeyDown(Keys.W) || GamePad.GetState(0).IsButtonDown(Buttons.DPadUp) && !playerGameElementInteraction && !previousState.IsKeyDown(Keys.W) && !previousGamepadState.IsButtonDown(Buttons.DPadUp)))
            {
                foreach (var vine in interactiveObject)
                {
                    if (DetectCollision(vine))
                    {
                        jumpSpeed                    = 0;
                        gravityActive                = false;
                        isStanding                   = true;
                        firstJump                    = false;
                        secondJump                   = false;
                        jumpButtonPressed            = false;
                        playerGameElementInteraction = true;
                        pressedLeftKey               = false;
                        pressedRightKey              = false;
                        velocity.X                   = 0;
                        collisionBoxPosition.X       = vine.gameObjectRectangle.X;

                        if (gameObjectPosition != collisionBoxPosition - changeCollisionBox)
                        {
                            gameObjectPosition = collisionBoxPosition - changeCollisionBox;
                        }
                    }
                }
            }
            if ((Keyboard.GetState().IsKeyDown(Keys.W) || GamePad.GetState(0).IsButtonDown(Buttons.DPadUp)) && playerGameElementInteraction)
            {
                climbAllowed = false;
                velocity.X   = 0;
                velocity.Y   = -movementSpeed - 2;
                foreach (var vine in interactiveObject)
                {
                    if (Math.Abs(collisionBoxPosition.X - vine.gameObjectRectangle.X) <= 5)
                    {
                        collisionBoxPosition.X = vine.gameObjectRectangle.X;
                        if (collisionRectangle.Bottom + velocity.Y >= vine.gameObjectRectangle.Top + 30)
                        {
                            climbAllowed = true;
                        }
                    }
                }
                if (gameObjectPosition != collisionBoxPosition - changeCollisionBox)
                {
                    gameObjectPosition = collisionBoxPosition - changeCollisionBox;
                }
                if (climbAllowed)
                {
                    velocity.Y = -movementSpeed - 2;
                }
                else
                {
                    velocity.Y = 0;
                }
            }
            else if ((Keyboard.GetState().IsKeyDown(Keys.S) || GamePad.GetState(0).IsButtonDown(Buttons.DPadDown)) && playerGameElementInteraction)
            {
                climbAllowed = false;
                velocity.X   = 0;
                velocity.Y   = movementSpeed + 2;
                foreach (var vine in interactiveObject)
                {
                    if (Math.Abs(collisionBoxPosition.X - vine.gameObjectRectangle.X) <= 5)
                    {
                        collisionBoxPosition.X = vine.gameObjectRectangle.X;
                        if (collisionRectangle.Top + velocity.Y <= vine.gameObjectRectangle.Bottom - 80)
                        {
                            climbAllowed = true;
                        }
                    }
                }
                if (gameObjectPosition != collisionBoxPosition - changeCollisionBox)
                {
                    gameObjectPosition = collisionBoxPosition - changeCollisionBox;
                }
                if (climbAllowed)
                {
                    velocity.Y = movementSpeed + 2;
                }
                else
                {
                    velocity.Y = 0;
                }
            }

            if (Keyboard.GetState().IsKeyUp(Keys.D) && Keyboard.GetState().IsKeyUp(Keys.A) && !firstJump && !secondJump && !playerGameElementInteraction)
            {
                if (facingDirectionRight)
                {
                    camera.cameraOffset(gameTime, false, false);
                }
                if (!facingDirectionRight)
                {
                    camera.cameraOffset(gameTime, true, false);
                }
            }
            previousState        = Keyboard.GetState();
            previousGamepadState = GamePad.GetState(0);
        }
Пример #3
0
        //Player Update Function that covers collision,controls,movement and inputs
        internal void Update(GameTime gameTime, List <GameObject> gameObjectsToRender, ref List <Enemy> enemyList, List <GameObject> interactiveObject, ref List <GameObject> gameObjects, LoadAndSave loadAndSave, IngameMenus ingameMenus, Levels levelManager, ref List <GameObject> allGameObjects, ShopKeeper shopKeeper, ItemUIManager itemUIManager, ref Boss hakume)
        {
            if (!playerSlowed)
            {
                movementSpeed = 10f;
            }
            if (!facingDirectionRight)
            {
                changeCollisionBox.X = 0;
            }
            else
            {
                changeCollisionBox.X = 50;
            }
            if (!shopKeeper.shopOpen)
            {
                PlayerControls(gameTime, enemyList, interactiveObject, ref gameObjects, loadAndSave, ingameMenus, gameObjects, shopKeeper, itemUIManager, hakume);
            }
            collisionBoxPosition = gameObjectPosition + changeCollisionBox;
            PlayerPositionCalculation(gameTime, gameObjectsToRender, interactiveObject);
            ItemCollisionManager(ref interactiveObject, ref gameObjects, levelManager, ref allGameObjects);
            if (invincibilityFrames)
            {
                InvincibleFrameState(gameTime);
            }

            Vibration();
        }