Пример #1
0
        public GameState(GraphicsDeviceManager g, ContentManager c, Viewport v)
            : base(g, c, v)
        {
            me = this;
            viewport = v;

            ButtonSize = new Vector2(viewport.Width * 0.34f, viewport.Width * 0.17f);
            btnPlay = content.Load<Texture2D>("btnPlay");
            playLocation = new Vector2((viewport.Width - ButtonSize.X) / 2, viewport.Height * 0.6f);

            score = new Score(v, c);
            score.display = true;

            player = new Player(v);
            player.LoadContent(c);

            obstacles = new Obstacles(viewport);
            obstacles.LoadContent(content);

            spriteFont = content.Load<SpriteFont>("ScoreFont");
            READEsize = spriteFont.MeasureString("Get Ready");
            Menusize = spriteFont.MeasureString("Twerkopter");
            GameOverSize = spriteFont.MeasureString("Game Over");

            GameOverLocation = new Vector2((viewport.Width - spriteFont.MeasureString("Game Over").X) / 2, -GameOverSize.Y);

            Scoreboard = content.Load<Texture2D>("Dashboard");
            ScoreboardSize = new Vector2(viewport.Width * .9f, viewport.Width * 0.545625f);
            ScoreboardLocation = new Vector2((viewport.Width - ScoreboardSize.X) / 2, viewport.Height);

            buttonSound = c.Load<SoundEffect>("swing");
        }
Пример #2
0
        public override State Update(GameTime gameTime)
        {
            if (Menu)
            {
                TouchCollection touchCollection = TouchPanel.GetState();
                foreach (TouchLocation tl in touchCollection)
                {
                    if (tl.State == TouchLocationState.Pressed)
                    {
                        if (new Rectangle((int)playLocation.X, (int)playLocation.Y, (int)ButtonSize.X, (int)ButtonSize.Y).Contains((int)tl.Position.X, (int)tl.Position.Y))
                        {
                            playLocation.Y += 5;
                        }
                    }

                    if (tl.State == TouchLocationState.Released)
                    {
                        if (new Rectangle((int)playLocation.X, (int)playLocation.Y, (int)ButtonSize.X, (int)ButtonSize.Y).Contains((int)tl.Position.X, (int)tl.Position.Y))
                        {
                            playLocation.Y -= 5;
                            Menu = false;
                            IsGameOver = false;
                            GetReadE = true;
                            buttonSound.Play();
                        }
                    }
                }

                obstacles.Update(gameTime, 0);
            }

            else
            {
                if (GetReadE)
                {
                    TouchCollection touchCollection = TouchPanel.GetState();
                    foreach (TouchLocation tl in touchCollection)
                    {
                        if (tl.State == TouchLocationState.Released)
                        {
                            buttonSound.Play();
                            GetReadE = false;
                        }
                    }
                    obstacles.Update(gameTime, 0);
                }

                else //The actual game loop
                {
                    if (IsGameOver)
                    {
                        GameOverLocation.Y = TransitionY((viewport.Height / 30), viewport.Height / 4, GameOverLocation.Y);
                        ScoreboardLocation.Y = TransitionY(-(viewport.Height / 30), GameOverLocation.Y + GameOverSize.Y + viewport.Height / 20, ScoreboardLocation.Y);
                        playLocation.Y = ScoreboardLocation.Y + ScoreboardSize.Y + viewport.Height / 20;

                        TouchCollection touchCollection = TouchPanel.GetState();
                        foreach (TouchLocation tl in touchCollection)
                        {
                            if (tl.State == TouchLocationState.Pressed)
                            {
                                if (new Rectangle((int)playLocation.X, (int)playLocation.Y, (int)ButtonSize.X, (int)ButtonSize.Y).Contains((int)tl.Position.X, (int)tl.Position.Y))
                                {
                                    playLocation.Y += 5;
                                }
                            }

                            if (tl.State == TouchLocationState.Released)
                            {
                                if (new Rectangle((int)playLocation.X, (int)playLocation.Y, (int)ButtonSize.X, (int)ButtonSize.Y).Contains((int)tl.Position.X, (int)tl.Position.Y))
                                {
                                    buttonSound.Play();

                                    playLocation.Y -= 5;

                                    player = new Player(viewport);
                                    player.LoadContent(content);

                                    obstacles = new Obstacles(viewport);
                                    obstacles.LoadContent(content);

                                    score.score = 0;

                                    Menu = false;
                                    IsGameOver = false;
                                    GetReadE = true;
                                }
                            }
                        }

                        obstacles.Update(gameTime, 0);
                    }

                    else
                    {
                        TouchCollection touchCollection = TouchPanel.GetState();
                        foreach (TouchLocation tl in touchCollection)
                        {
                            if (tl.State == TouchLocationState.Released)
                            {
                                buttonSound.Play();
                                player.TapUpdate();
                            }
                        }
                        obstacles.Update(gameTime, 4);
                        player.Update(gameTime);

                        if (PlayerIsRekt())
                        {
                            IsGameOver = true;
                            score.saveScore();
                        }
                    }
                }
            }
            return this;
        }