Exemple #1
0
        /// <summary>
        /// Move to next screen
        /// </summary>
        public void NextScreen()
        {
            if (curScreenIndex <= 3)
                curScreen = screens[curScreenIndex++];
            else
                curScreen = new GameOverScreen(this, Content, "menubackground");

            if (curScreen is GameScreen)
            {
                level = ((GameScreen)curScreen).CurLevel;
                player = level.MainPlayer;
            }
        }
Exemple #2
0
        /// <summary>
        /// Update game
        /// </summary>
        /// <param name="gameTime">Game time</param>
        protected override void Update(GameTime gameTime)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
                this.Exit();

            Vector2 mousePos = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);

            // Update game screens
            if (curScreen is GameScreen)
            {

                // Launch player
                if (!dragging && player.PointIn(mousePos) && Mouse.GetState().LeftButton == ButtonState.Pressed)
                    dragging = true;

                if (dragging)
                {
                    Vector2 diff = player.Position - (mousePos - Vector2.UnitY * level.Scroll);
                    float length = diff.Length();
                    if (length > maxVelocity)
                    {
                        diff.Normalize();
                        diff *= maxVelocity;
                        length = maxVelocity;
                    }

                    player.Tail.Scale = length * 0.001f;
                    player.Tail.Rotation = MathHelper.ToDegrees((float)Math.Atan2(diff.Y, diff.X)) + 90;

                    if (Mouse.GetState().LeftButton == ButtonState.Released)
                    {
                        dragging = false;
                        player.Tail.Scale = 0;

                       // Vector2 diff = player.Position - (mousePos - Vector2.UnitY * level.Scroll);

                        player.AddForce(diff * 40);
                        player.Active = true;
                        player.ApplyGravity = true;
                    }
                }

                // Collide with edges
                if (player.Position.X < 60 || player.Position.X > 740)
                    player.Velocity = new Vector2(-player.Velocity.X, player.Velocity.Y);

                // Screen limits
                if (player.Position.X <= 60)
                    player.Position = new Vector2(60, player.Position.Y);
                if (player.Position.X >= 740)
                    player.Position = new Vector2(740, player.Position.Y);
                if (level.Inverted)
                {
                    if (player.Position.Y <= 200)
                        level.Scroll = 100 - player.Position.Y;
                }
                else
                {
                    if (player.Position.Y <= 100)
                        level.Scroll = 100 - player.Position.Y;     // Scroll
                }
                if (!level.Inverted && player.Position.Y < -1000)
                    player.Position = new Vector2(player.Position.X, -1000);
                else if (level.Inverted && player.Position.Y > 800)
                    player.Position = new Vector2(player.Position.X, 800);

                if (level.Scroll > 1100)
                    level.Scroll = 1100;

                // Collide with soup
                if ((!level.Inverted && player.Position.Y > 800) || (level.Inverted && player.Position.Y < -1200))
                {
                    if (player.ChildCount >= 6)
                    {
                        NextScreen();
                        if (lifeCount < 5)
                            lifes[lifeCount++].Open = true;
                    }
                    else
                    {
                        // Die
                        if (lifeCount > 0)
                        {
                            lifes[--lifeCount].Close();
                           // level = Level.LoadLevel((GameScreen)curScreen, Content, level.Filename);
                            player = level.MainPlayer;
                        }
                        else
                        {
                            // Game over
                            curScreen = new GameOverScreen(this, Content, "menubackground");
                        }
                    }
                }

                // Update level
                level.Update(gameTime);

            }

            base.Update(gameTime);
        }