XNA中的开始和结束屏幕

XNA中的开始和结束屏幕,xna,xna-4.0,Xna,Xna 4.0,这是我在XNA的第一个节目,如果我错过了一些明显的东西,我深表歉意。我第一次尝试通过case逻辑实现加载和结束屏幕,当这不起作用时,我想知道我是否在某个地方搞砸了,所以我切换到if/else语句 到目前为止,我的结果是,无论我改变什么,我的游戏都会加载InGame逻辑。没有开始屏幕,没有结束屏幕,没有矢车菊蓝对我的InGame Bisque。我不知道为什么 using System; using System.Collections.Generic; using System.Linq; usi

这是我在XNA的第一个节目,如果我错过了一些明显的东西,我深表歉意。我第一次尝试通过case逻辑实现加载和结束屏幕,当这不起作用时,我想知道我是否在某个地方搞砸了,所以我切换到if/else语句

到目前为止,我的结果是,无论我改变什么,我的游戏都会加载InGame逻辑。没有开始屏幕,没有结束屏幕,没有矢车菊蓝对我的InGame Bisque。我不知道为什么

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace FeedMe
{
    public enum GameState
    {
        Start,
        InGame,
        GameOver
    }

    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        Texture2D kitty;
        Texture2D cheese;
        Vector2 kittyPosition;
        Vector2 cheesePosition = Vector2.Zero;
        float speed1 = 4f;
        float speed2 = 5f;
        float secs = 30000.0f;
        MouseState prevMouseState;
        bool wasDown;
        int clicks;
        int speedUp = 5;
        AudioEngine audioEngine;
        WaveBank waveBank;
        SoundBank soundBank;
        Cue trackCue;
        SpriteFont splashFont;
        GameState currentGameState = new GameState();

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        public Random rnd { get; private set; }

        protected bool Collide()
        {
            Rectangle kittyRect = new Rectangle(
                (int)kittyPosition.X,
                (int)kittyPosition.Y, 
                kitty.Width, 
                kitty.Height
            );

            Rectangle cheeseRect = new Rectangle(
                (int)cheesePosition.X,
                (int)cheesePosition.Y, 
                cheese.Width, 
                cheese.Height
            );

            return kittyRect.Intersects(cheeseRect);
        }

        protected override void Initialize()
        {
            currentGameState = GameState.Start;
            kittyPosition = Vector2.Zero;
            wasDown = false;
            clicks = 0;
            this.IsMouseVisible = false;
            rnd = new Random();
            base.Initialize();
        }

        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            kitty = Content.Load<Texture2D>(@"Images/kitty");
            cheese = Content.Load<Texture2D>(@"Images/cheese");
            audioEngine = new AudioEngine(@"Content\Audio\GameAudio.xgs");
            waveBank = new WaveBank(audioEngine, @"Content\Audio\Wave Bank.xwb");
            soundBank = new SoundBank(audioEngine, @"Content\Audio\Sound Bank.xsb");
            splashFont = Content.Load<SpriteFont>(@"Fonts\Splash");
        }

        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        protected override void Update(GameTime gameTime)
        {
            if (currentGameState == GameState.Start)
                soundBank.PlayCue("gameStart");

            if (Keyboard.GetState().GetPressedKeys().Length > 0)
            {
                currentGameState = GameState.InGame;
            }
            else if (currentGameState == GameState.InGame)
            {
                kittyPosition.X += speed1;

                if (kittyPosition.X > Window.ClientBounds.Width - kitty.Width || kittyPosition.X < 0)
                    speed1 *= -1;

                kittyPosition.Y += speed2;

                if (kittyPosition.Y > Window.ClientBounds.Height - kitty.Height || kittyPosition.Y < 0)
                    speed2 *= -1;

                MouseState mouseState = Mouse.GetState();

                if (mouseState.X != prevMouseState.X || mouseState.Y != prevMouseState.Y)
                    cheesePosition = new Vector2(mouseState.X, mouseState.Y);

                if (cheesePosition.X < 0)
                    cheesePosition.X = 0;
                if (cheesePosition.Y < 0)
                    cheesePosition.Y = 0;
                if (cheesePosition.X > Window.ClientBounds.Width - cheese.Width)
                    cheesePosition.X = Window.ClientBounds.Width - cheese.Width;
                if (cheesePosition.Y > Window.ClientBounds.Height - cheese.Height)
                    cheesePosition.Y = Window.ClientBounds.Height - cheese.Height;

                secs -= (float)gameTime.ElapsedGameTime.TotalMilliseconds;

                if (secs <= 0.0f)
                {
                    secs = 0;
                }

                ButtonState bs = mouseState.LeftButton;
                bool nowDown = bs == ButtonState.Pressed;

                if (Collide() && (!nowDown && wasDown))
                {
                    soundBank.PlayCue("chomp");
                    clicks++;
                    Window.Title = "Cheeseburgers fed = " + clicks + "     Time Remaining = " + (int)secs / 1000;
                    kittyPosition = new Vector2(
                        (rnd.Next(0, Window.ClientBounds.Width - kitty.Width)),
                        (rnd.Next(0, Window.ClientBounds.Height - kitty.Height))
                    );
                }

                wasDown = nowDown;

                if (clicks == speedUp)
                {
                    soundBank.PlayCue("turbo");
                    speedUp = speedUp + 5;
                    speed1 = speed1 * 1.5f;
                    speed2 = speed2 * 1.5f;
                }
            }
            else if (currentGameState == GameState.GameOver)
            {
                soundBank.PlayCue("gameOver");

                if (Keyboard.GetState().GetPressedKeys().Length > 0)
                {
                    currentGameState = GameState.InGame;
                }
            }

            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            audioEngine.Update();
            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            if(currentGameState == GameState.Start)
            {
                GraphicsDevice.Clear(Color.CornflowerBlue);
                spriteBatch.Begin();
                string text = "Testing!";
                spriteBatch.DrawString(
                    splashFont, 
                    text, 
                    new Vector2((Window.ClientBounds.Width / 2) - (splashFont.MeasureString(text).X / 2), 
                    (Window.ClientBounds.Height / 2) - (splashFont.MeasureString(text).Y / 2)), 
                    Color.DarkBlue
                );

                text = "Testing2!";

                spriteBatch.DrawString(
                    splashFont, 
                    text, 
                    new Vector2((Window.ClientBounds.Width/2) - (splashFont.MeasureString(text).X/2),        
                    (Window.ClientBounds.Height/2) - (splashFont.MeasureString(text).Y/2) + 30), 
                    Color.DarkBlue
                );

                spriteBatch.End();
            }
            else if(currentGameState == GameState.InGame)
            {
                GraphicsDevice.Clear(Color.Bisque);

                spriteBatch.Begin();
                spriteBatch.Draw(kitty, kittyPosition, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
                spriteBatch.Draw(cheese, cheesePosition, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
                spriteBatch.End();
            }
            else if (currentGameState == GameState.GameOver)
            {
                GraphicsDevice.Clear(Color.CornflowerBlue);
                spriteBatch.Begin();
                string text = "Testing3";
                spriteBatch.DrawString(
                    splashFont, 
                    text, 
                    new Vector2((Window.ClientBounds.Width / 2) - (splashFont.MeasureString(text).X / 2), 
                    (Window.ClientBounds.Height / 2) - (splashFont.MeasureString(text).Y / 2)), 
                    Color.DarkBlue
                );

                text = "Testing4";

                spriteBatch.DrawString(
                    splashFont, 
                    text, 
                    new Vector2((Window.ClientBounds.Width/2) - (splashFont.MeasureString(text).X/2, 
                    (Window.ClientBounds.Height/2) - (splashFont.MeasureString(text).Y/2) + 30), 
                    Color.DarkBlue
                );

                spriteBatch.End();
            }

            base.Draw(gameTime);
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用Microsoft.Xna.Framework;
使用Microsoft.Xna.Framework.Audio;
使用Microsoft.Xna.Framework.Content;
使用Microsoft.Xna.Framework.GamerServices;
使用Microsoft.Xna.Framework.Graphics;
使用Microsoft.Xna.Framework.Input;
使用Microsoft.Xna.Framework.Media;
名称空间FeedMe
{
公共枚举博弈状态
{
开始
英格梅,
游戏结束
}
公共类游戏1:Microsoft.Xna.Framework.Game
{
图形管理器图形;
雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧雪碧;
质感2d基蒂;
质地为2D的奶酪;
向量2小猫位置;
Vector2 cheesePosition=Vector2.0;
浮动速度1=4f;
浮动速度2=5f;
浮点数=30000.0f;
穆斯庄园;
布尔倒下了;
int点击;
整数加速比=5;
音频引擎;
波班克波班克;
声库声库;
线索追踪线索;
SpriteFont字体;
游戏状态currentGameState=新游戏状态();
公共游戏1()
{
graphics=新的GraphicsDeviceManager(此);
Content.RootDirectory=“Content”;
}
公共随机rnd{get;私有集;}
受保护的布尔碰撞()
{
矩形kittyRect=新矩形(
(int)kittyPosition.X,
(int)kittyPosition.Y,
基蒂,宽度,
基蒂,身高
);
矩形cheeseRect=新矩形(
(int)cheesePosition.X,
(int)cheesePosition.Y,
奶酪,宽度,
奶酪,身高
);
返回kittyRect.相交(cheeseRect);
}
受保护的覆盖无效初始化()
{
currentGameState=GameState.Start;
kittyPosition=Vector2.0;
wasDown=false;
点击次数=0;
this.IsMouseVisible=false;
rnd=新随机数();
base.Initialize();
}
受保护的覆盖void LoadContent()
{
//创建一个新的SpriteBatch,可用于绘制纹理。
spriteBatch=新spriteBatch(图形设备);
kitty=Content.Load(@“Images/kitty”);
奶酪=内容。加载(@“图像/奶酪”);
audioEngine=新的audioEngine(@“Content\Audio\GameAudio.xgs”);
waveBank=新的waveBank(audioEngine,@“Content\Audio\Wave Bank.xwb”);
soundBank=新的soundBank(audioEngine,@“Content\Audio\Sound Bank.xsb”);
splashFont=Content.Load(@“Fonts\Splash”);
}
受保护的覆盖无效UnloadContent()
{
//TODO:在此卸载任何非ContentManager内容
}
受保护覆盖无效更新(游戏时间游戏时间)
{
如果(currentGameState==GameState.Start)
soundBank.PlayCue(“游戏开始”);
如果(键盘.GetState().GetPressedKeys().Length>0)
{
currentGameState=GameState.InGame;
}
else if(currentGameState==GameState.InGame)
{
kittyPosition.X+=速度1;
if(kittyPosition.X>Window.ClientBounds.Width-kitty.Width | | kittyPosition.X<0)
速度1*=-1;
kittyPosition.Y+=速度2;
if(kittyPosition.Y>Window.ClientBounds.Height-kitty.Height | | kittyPosition.Y<0)
速度2*=-1;
MouseState=Mouse.GetState();
if(mouseState.X!=prevMouseState.X | | mouseState.Y!=prevMouseState.Y)
cheesePosition=新矢量2(mouseState.X,mouseState.Y);
if(cheesePosition.X<0)
cheesePosition.X=0;
if(奶酪位置Y<0)
cheesePosition.Y=0;
if(cheesePosition.X>Window.ClientBounds.Width-cheese.Width)
cheesePosition.X=Window.ClientBounds.Width-cheese.Width;
if(cheesePosition.Y>Window.ClientBounds.Height-cheese.Height)
cheesePosition.Y=Window.ClientBounds.Height-cheese.Height;
secs-=(float)gameTime.ElapsedGameTime.total毫秒;
如果(秒0)
{
currentGameState=GameState.InGame;
}
}
//允许游戏退出
if(GamePad.GetState(PlayerIndex.One).Buttons.Back==ButtonState.Pressed)
这是Exit();
audioEngine.Update();
更新(游戏时间);
}
受保护覆盖无效绘制(游戏时间游戏时间)
{
如果(currentGameState==GameState.Start)
{
图形设备。清晰(颜色:矢车菊蓝);
spriteBatch.Begin();
string text=“测试!”;
spriteBatch.抽绳(
splashFont,
文本,
新矢量2((Window.ClientBounds.Width/2)-(splashFont.MeasureString(text.X/2),
(Window.ClientBounds.Height/2)-(splashFont.MeasureString(text.Y/2)),
深蓝色
);
text=“Testing2!”;
spriteBatch.抽绳(
splashFont,
if (currentGameState == GameState.Start)
{
                soundBank.PlayCue("gameStart");
                if(Keyboard.GetState().GetPressedKeys().Length>0)
                {
                    currentGameState = GameState.InGame;
                } 
}
 if(Keyboard.GetState().GetPressedKeys().Length>0)
                {
                    currentGameState = GameState.InGame;
                }
            else if (currentGameState == GameState.InGame)