This project is read-only.

To be able to use Neat, you need to create a class that inherits NeatGame, the core of Neat Engine. NeatGame inherits the Game class which is the main class in XNA games, so it is easy to modify the code you’ve already written to use Neat.

To create a Neat-based project, follow these steps:

  1. First, you have to create a regular XNA Game Studio 4.0 Windows Game project.
    neat_tut_1
  2. Now, we should add a reference to Neat.exe in our project. To add a reference, you have to right click on the References folder in your solution explorer, and click Add Reference…

    neat_tut_1_add_reference

    Locate Neat.exe using the Browse tab:

    neat_tut_1_add_reference2StandAloneConsole3

  3. We also need to include Neat content files in our project. To do that, we must first add Neat content project to our solution and then add a Content Reference from our main game project to it.

    Right click on the solution, and choose Add…>Existing Project… .Then locate NeatContent project file using the Add Existing Project dialog.

    neat_tut_1_content1

    Now you should be able to see Neat content files in your solution. To add a reference to these content, right click on the Content References folder of your main game project and click Add Content Reference…

    Choose NeatContent.

    neat_tut_1_content2neat_tut_1_content3

  4. Alright. Now we are ready to modify the code to make use of Neat in it. To use Neat classes in your code, you should add this line at the top of your code:
    using Neat;

    And your main class should inherit from Neat.NeatGame instead of Microsoft.Xna.Framework.Game; Which means you should change public class Game1 : Microsoft.Xna.Framework.Game to public class Game1 : NeatGame .

    Because Neat handles most of the stuff internally, you must delete these lines from the code and let Neat take care of them:

    GraphicsDeviceManager graphics; 
    SpriteBatch spriteBatch;
    
    graphics = new GraphicsDeviceManager(this); 
    Content.RootDirectory = "Content";
    
    spriteBatch = new SpriteBatch(GraphicsDevice);

Basically, your could should be like this:

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; 
using Neat;

namespace MyNeatGame 
{ 
    /// <summary> 
    /// This is the main type for your game 
    /// </summary> 
    public class Game1 : NeatGame 
    { 
        public Game1() 
        { 
        }

        /// <summary> 
        /// Allows the game to perform any initialization it needs to before starting to run. 
        /// 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
            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() 
        { 
            base.LoadContent(); 
        }

        /// <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) 
        { 
            // TODO: Add your update logic here 
            base.Update(gameTime); 
        }

        /// <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) 
        { 
            // TODO: Add your drawing code here
            base.Draw(gameTime); 
        } 
    } 
} 

If you build and run the project at this time, you can see the Main Menu screen in front of an undefined sprite. You can also access a fully functional Options menu where you are able to change the basic settings of the game like the resolution and the sound, and if you press the Tilde (~) button, you can work with Neat Console and Neat’s scripting features.

Each Neat game is made of a couple of Screens. for example, Each menu is a different screen. Neat’s Screen class helps you create a screen.

You can skip steps mentioned above by downloading the NeatStarter project which acts as a template for new Neat-based games. The NeatStarter project can be downloaded from the Releases section.

Good Luck!

neat_tut_1_run

Last edited Jan 28, 2011 at 9:30 PM by saeedoo, version 3

Comments

No comments yet.