Exemplo n.º 1
0
        // LOAD CONTENT BEGIN<=========================================================
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            songs[0] = Content.Load <Song>("Sounds/intro");
            songs[1] = Content.Load <Song>("Sounds/end");
            // songs[2] = Content.Load<Song>("Sounds/win");

            endScreen   = Content.Load <Texture2D>("Screens/loseScreen");
            beginScreen = Content.Load <Texture2D>("Screens/introScreen");
            winScreen   = Content.Load <Texture2D>("Screens/winScreen");

            bullet_Sprite = Content.Load <Texture2D>("World/bullet");
            heart_Sprite  = Content.Load <Texture2D>("World/heart");

            eyeEnemy_Sprite   = Content.Load <Texture2D>("Monsters/eyeEnemy");
            snakeEnemy_Sprite = Content.Load <Texture2D>("Monsters/snakeEnemy");

            bush_Sprite = Content.Load <Texture2D>("Collisions/bush");
            tree_Sprite = Content.Load <Texture2D>("Collisions/tree");

            player_Sprite      = Content.Load <Texture2D>("Player/player");
            playerUp_Sprite    = Content.Load <Texture2D>("Player/PlayerUp");
            playerRight_Sprite = Content.Load <Texture2D>("Player/playerRight");
            playerLeft_Sprite  = Content.Load <Texture2D>("Player/playerLeft");
            playerDown_Sprite  = Content.Load <Texture2D>("Player/playerDown");

            zombieFront_Sprite = Content.Load <Texture2D>("Zombie1/zombieFront");
            zombieDown_Sprite  = Content.Load <Texture2D>("Zombie1/zombie1Down");
            zombieUp_Sprite    = Content.Load <Texture2D>("Zombie1/zombie1Up");
            zombieLeft_Sprite  = Content.Load <Texture2D>("Zombie1/zombie1Left");
            zombieRight_Sprite = Content.Load <Texture2D>("Zombie1/zombie1Right");

            //AnimatedSprite zombieWalkDown = new AnimatedSprite(zombieDown_Sprite, 1, 4);
            //AnimatedSprite zombieWalkUp = new AnimatedSprite(zombieUp_Sprite, 1, 4);
            //AnimatedSprite zombieWalkLeft = new AnimatedSprite(zombieLeft_Sprite, 1, 4);
            //AnimatedSprite zombieWalkRight = new AnimatedSprite(zombieRight_Sprite, 1, 4);

            AnimatedSprite playerWalkDown  = new AnimatedSprite(playerDown_Sprite, 1, 4);
            AnimatedSprite playerWalkUp    = new AnimatedSprite(playerUp_Sprite, 1, 4);
            AnimatedSprite playerWalkLeft  = new AnimatedSprite(playerLeft_Sprite, 1, 4);
            AnimatedSprite playerWalkRight = new AnimatedSprite(playerRight_Sprite, 1, 4);

            player.animations[0] = playerWalkDown;
            player.animations[1] = playerWalkUp;
            player.animations[2] = playerWalkLeft;
            player.animations[3] = playerWalkRight;

            screen = new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);

            myMap = Content.Load <TiledMap>("World/game_map");
            MediaPlayer.Play(songs[0]);

            //screen = new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);

            //all enemies is an array that contains tail objects and we are stting it = to are maps
            //enemies layer and all object that that layer contains.

            TiledMapObject[] allEnemies = myMap.GetLayer <TiledMapObjectLayer>("enemies").Objects;
            foreach (var en in allEnemies)
            {
                // Hier worden de enemies aanghemaakt op basis van de enemies layer op de map
                string type;
                en.Properties.TryGetValue("Type", out type);
                if (type == "Snake")
                {
                    Monster.enemies.Add(new Snake(en.Position));
                }
                else if (type == "Eye")
                {
                    Monster.enemies.Add(new Eye(en.Position));
                }
            }

            TiledMapObject[] allObstacles = myMap.GetLayer <TiledMapObjectLayer>("obstacles").Objects;
            foreach (var obs in allObstacles)
            {
                string type;
                obs.Properties.TryGetValue("Type", out type);
                if (type == "Bush")
                {
                    Obstacle.obstacles.Add(new Bush(obs.Position));
                }
                else if (type == "Tree")
                {
                    Obstacle.obstacles.Add(new Tree(obs.Position));
                }
            }


            //Enemy.enemies.Add(new Snake(new Vector2(100, 400)));
            //Enemy.enemies.Add(new Eye(new Vector2(300, 450)));

            //Obstacle.obstacles.Add(new Tree(new Vector2(600, 200)));
            //Obstacle.obstacles.Add(new Bush(new Vector2(800, 400)));
        }
Exemplo n.º 2
0
        public void Update(GameTime gt)
        {
            KeyboardState currentKeyState = Keyboard.GetState();
            float         dt = (float)gt.ElapsedGameTime.TotalSeconds;

            anim = animations[(int)direction];
            if (healthDelay > 0)
            {
                healthDelay -= dt;
            }

            if (isWalking)
            {
                anim.Update(gt);
            }
            else
            {
                anim.setFrame(1);
            }

            isWalking = false;

            if (currentKeyState.IsKeyDown(Keys.Right))
            {
                direction = Dir.Right;
                isWalking = true;
            }
            if (currentKeyState.IsKeyDown(Keys.Left))
            {
                direction = Dir.Left;
                isWalking = true;
            }
            if (currentKeyState.IsKeyDown(Keys.Up))
            {
                direction = Dir.Up;
                isWalking = true;
            }
            if (currentKeyState.IsKeyDown(Keys.Down))
            {
                direction = Dir.Down;
                isWalking = true;
            }
            if (isWalking)
            {
                Vector2 tempPos = pos;
                switch (direction)
                {
                case Dir.Right:
                    tempPos.X += speed * dt;
                    if (!Obstacle._collided(tempPos, rad))
                    {
                        pos.X += speed * dt;
                    }
                    break;

                case Dir.Left:
                    tempPos.X -= speed * dt;
                    if (!Obstacle._collided(tempPos, rad))
                    {
                        pos.X -= speed * dt;
                    }
                    break;

                case Dir.Down:
                    tempPos.Y += speed * dt;
                    if (!Obstacle._collided(tempPos, rad))
                    {
                        pos.Y += speed * dt;
                    }
                    break;

                case Dir.Up:
                    tempPos.Y -= speed * dt;
                    if (!Obstacle._collided(tempPos, rad))
                    {
                        pos.Y -= speed * dt;
                    }
                    break;

                default:
                    break;
                }
            }

            if (currentKeyState.IsKeyDown(Keys.Space) && previousKeyState.IsKeyUp(Keys.Space))
            {
                Shooting.bullets.Add(new Shooting(pos, direction));
            }
            previousKeyState = currentKeyState;
        }