Beispiel #1
0
        public override ScreenState Update(DateTime gameTime)
        {
            ScreenState ret = ScreenState.Current;

            if (firstUpdate)
            {
                currentTick = gameTime.Ticks;
                firstUpdate = false;
            }

            if (winAnimation)
            {
                if (elapsed == TimeSpan.Zero)
                {
                    elapsed = TimeSpan.FromTicks(gameTime.Ticks - currentTick);
                }

                rocket.Y = rocket.Y - Convert.ToSingle(rocketVelocity++ *0.2);

                mainField.Update(gameTime);

                if (rocket.Y < -192)
                {
                    ret = ScreenState.Win;
                    Updatebalance(ret, elapsed);
                    StartNewGame();
                }

                return(ret);
            }

            var inp = device.GetInputState();

            if (inp.IsCancel)
            {
                ret = ScreenState.Menu;
            }
            else
            {
                bool isLive = mainField.GetSquareState(omich.X, omich.Y);
                if (!isLive)
                {
                    if (omich.IsLive())
                    {
                        device.PlaySound(soundWater);
                    }

                    omich.Dead();
                }
                else
                {
                    if (!omich.IsLive())
                    {
                        omich.Enabled = false;
                        ret           = ScreenState.Loose;
                    }
                }


                if (omich.IsLive())
                {
                    if (detail.Containts(omich) && detail.Enabled)
                    {
                        detail.Enabled = false;
                        device.PlaySound(soundVzmah);
                    }

                    if (rocket.Containts(omich) && !detail.Enabled)
                    {
                        if (detail.NextFrame())
                        {
                            detail.Enabled = true;
                            mainField.NextLevel();
                        }

                        if (!rocket.NextFrame())
                        {
                            device.PlaySound(soundBomb);
                            omich.Enabled = false;
                            winAnimation  = true;
                        }
                        else
                        {
                            device.PlaySound(soundDrel);
                        }
                    }

                    if (inp.Joystick == JoystickState.Down)
                    {
                        OmichMove(Direction.Down);
                    }
                    else if (inp.Joystick == JoystickState.Up)
                    {
                        OmichMove(Direction.Up);
                    }
                    else if (inp.Joystick == JoystickState.Left)
                    {
                        OmichMove(Direction.Left);
                    }
                    else if (inp.Joystick == JoystickState.Right)
                    {
                        OmichMove(Direction.Right);
                    }
                    else if (inp.Joystick == JoystickState.Press)
                    {
                        var Position = inp.Positions.First();

                        if (
                            (Position.Y <= omich.Y + 96) &&
                            (Position.Y >= omich.Y) &&
                            (Position.X > omich.X + 100)
                            )
                        {
                            OmichMove(Direction.Right);
                        }
                        else if (
                            (Position.Y <= omich.Y + 96) &&
                            (Position.Y >= omich.Y) &&
                            (Position.X < omich.X)
                            )
                        {
                            OmichMove(Direction.Left);
                        }
                        else if (
                            (Position.Y > omich.Y + 96)
                            )
                        {
                            OmichMove(Direction.Down);
                        }
                        else if (
                            (Position.Y < omich.Y)
                            )
                        {
                            OmichMove(Direction.Up);
                        }
                    }

                    if (omich.IsLive())
                    {
                        if (omich.X == 0)
                        {
                            omich.SeeRight();
                        }
                        else if (omich.X == 700)
                        {
                            omich.SeeLeft();
                        }
                    }
                }
            }

            mainField.Update(gameTime);
            omich.Update(gameTime);
            rocket.Update(gameTime);
            detail.Update(gameTime);

            if (ret != ScreenState.Current)
            {
                elapsed = TimeSpan.FromTicks(gameTime.Ticks - currentTick);
                Updatebalance(ret, elapsed);
                StartNewGame();
            }

            return(ret);
        }