The Legend of the Tomato Quest Tutorial - Loading the level

The first thing we need to do is load a level for our game. For this tutorial we will use the [[Media:GrassLevel.zip|Grass Level]]. Download it, and unzip the 2 files into the Resources\maps\ folder of your project.

The next thing we need to do it add the line of code that loads this map into the game.

Adding the Map to Our Game Resources
Open the Project in Visual Studio and Open the GameResources.cs source file.

Scroll to the bottom of the source file until you see the LoadMaps routine.

Add the following line of code to the LoadMaps routine.

This will add our map to the game. Now we to start the Game Structure, Open GameLogic.cs and delete the HelloWorld line in the code, if its there.

The Main Game Class
Let's add the main Game routine to our code. Make a new source file called Game.cs and add the following code as a template for us to make our game class.

Loading and Drawing the Map
First, Create a new Source file called Level.cs, and add the following code as a template for making our levels:

Now modify the Level class in Level.cs to look like the following:

This Level class, stores a Map. When we create a Level object, it loads the Map that we pass in. We also have the DrawLevel method which will draw the map whenever we call it.

Next we need to modify the Game class within the Game.cs source file to look like the following:

We will run this code during every loop. When we first create our Game object, it will load the Map 'Level1' and assigns it to the variable _Map. The Run method is what is executed every loop, it simply draws the map and the frame rate.

Now add the following lines of code to the RunGame method within the GameLogic.cs source file:

What this code is doing is looping through our game, when it first loads, it creates a Game object and stores it in the _Game variable. The game loop is simply Clearing the screen to black, then running the _Game.Run method, and finally finishes by refreshing the screen and processing events.

This loop will continue until the user requests to close the window.

Compiling and Playing the Game
Let's build our project to see where we are. First in Visual Studio, click Build -> Build Solution. No errors should appear if everything above has been done correctly and the SDK has been set up the right way.

Now run the game by either opening the exe manually or by Start Debugging in Visual Studio.

After a brief SwinGame Intro you should see a screen with something like the following:



Next we'll look into Drawing our first character and getting him to move around the world.

The Project so far
Here's a zip containing the source and resources of the tutorials we've completed up to this point. You should find this useful to read through as you read this tutorial.

[[Media:RPGTutorial1.zip|Source Code]]