Xna游戏在更新中引用游戏

时间:2013-03-14 04:34:00

标签: xna-4.0

嗨我的XNA游戏有问题我试图在另一个类中引用Game但是每次我尝试的东西都说没有合适的方法来覆盖它所以我可以使用Mouse.SetPosition(window.ClientBounds.Width / 2, window.ClientBounds.Height / 2);在game1.cs以外的另一个类中,我的game1代码是

namespace _3d
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;


    MouseState mState;

    List<gameObject> gameobjectlist = new List<gameObject>();

    terrain Terrain;
    Camera mycam;

    Turret_Base turretBase;
    Turret_Barrel turretBarrel;
    //physicsObject Missile;


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

    /// <summary>

    /// This is where it can query for any required services and load any non-graphic
    /// related content.  Calling base.Initialize will enumerate through any components
    /// and initialize them as well.
    /// </summary>
    protected override void Initialize()
    {
        // TODO: Add your initialization logic here



        mycam = new Camera(MathHelper.ToRadians(45.0f),
            (float)graphics.GraphicsDevice.Viewport.Width / 
        (float)graphics.GraphicsDevice.Viewport.Height,
        1.0f, 10000.0f, Vector3.Zero, Vector3.Up);
        mycam.Position = new Vector3(0.0f, 53.0f, 155.0f);

        //MouseState mouseState = Mouse.GetState();
        //Vector3 mousePosition = new Vector3(mouseState.Y, mouseState.X, 0.0f);





        base.Initialize();
    }

    /// <summary>
    /// LoadContent will be called once per game and is the place to load
    /// all of your content.
    /// </summary>
    protected override void LoadContent()
    {
        // Create a new SpriteBatch, which can be used to draw textures.
        spriteBatch = new SpriteBatch(GraphicsDevice);
        Terrain = new terrain("models/terrain/desert", Content);
        turretBase = new Turret_Base("models/turret/Turret_Base", Content);
        turretBarrel = new Turret_Barrel("models/turret/Turret_Barrel", Content);
        //Missile = new physicsObject("models/turret/ammo", Content);

        gameobjectlist.Add(Terrain);
        gameobjectlist.Add(turretBase);
        gameobjectlist.Add(turretBarrel);
        gameobjectlist.Add(mycam);


        // TODO: use this.Content to load your game content here
    }

    /// <summary>
    /// UnloadContent will be called once per game and is the place to unload
    /// all content.
    /// </summary>
    protected override void UnloadContent()
    {
        // TODO: Unload any non ContentManager content here
    }

    /// <summary>
    /// Allows the game to run logic such as updating the world,
    /// checking for collisions, gathering input, and playing audio.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void update(GameTime gameTime)
    {


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


        foreach (gameObject go in gameobjectlist)
        {
        }




        mycam.update(gameTime);

        Terrain.update(gameTime);
        turretBase.update(gameTime);
        turretBarrel.update(gameTime);

        if (exitGame() == false)
        {
            base.Update(gameTime);
        }

        // TODO: Add your update logic here


    }

    /// <summary>
    /// This is called when the game should draw itself.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.CornflowerBlue);

        foreach (gameObject go in gameobjectlist)
        {
        }


        // TODO: Add your drawing code here


        Terrain.draw(mycam);
        turretBase.draw(mycam);
        turretBarrel.draw(mycam);

        base.Draw(gameTime);
    }

    bool exitGame()
    {
        if (Keyboard.GetState().IsKeyDown(Keys.Escape))
        {
            Exit();
            return true;
        }
        return false;
    }
    } 
   }

我试图将它放入的类是&gt;&gt;

{
class Turret_Base : gameObject 



 {
    Turret_Barrel Parent;

    public Turret_Base(string fileName, ContentManager content, Turret_Barrel parent =      
    null)
        : base(fileName, content)
    {

        GameWindow window;
        Parent = parent;
        Pitch = 25;
        Yaw = 0;
        Roll = 0;
        Position = new Vector3(0, 50, 120);
        Scale = 0.1f; //Base Transform

    }

    public override void update(GameTime gametime)
    {
        float dt = (float)gametime.ElapsedGameTime.TotalSeconds;

        // mouse movement
        //MouseState mState = Mouse.GetState();

        //Vector3 newPos = new Vector3(mState.X, Position.Y, mState.Y);

        //Position = newPos;

        KeyboardState keyboardstate = Keyboard.GetState();
        if (keyboardstate.IsKeyDown(Keys.W))
            Position -= Vector3.UnitZ * 25.0f * dt;
        if (keyboardstate.IsKeyDown(Keys.A))
            Position -= Vector3.UnitX * 25.0f *dt;
        if (keyboardstate.IsKeyDown(Keys.S))
            Position += Vector3.UnitZ * 25.0f * dt;
        if (keyboardstate.IsKeyDown(Keys.D))
            Position += Vector3.UnitX * 25.0f * dt;



        base.update(gametime);


    }
}

}

抱歉,如果这是一个明显的错误

谢谢

0 个答案:

没有答案
相关问题