This project is read-only.

These instructions were copied from a quick email I sent to a colleague. Better writen instructions will soon be posted. Download the newest release under downloads before following the instructions below.




When you open up the files you downloaded, you should see references to many different classes including GameStatus, LevelInfo, Player, Tile, and PathTile.

LevelInfo and GameStatus are simple classes that contain information about the game. GameStatus keeps information about the game, while LevelInfo holds information concerning the current level. I also use GameStatus to save and load the game.

Here are the contents of my LevelInfo class:

using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using FarseerGames.FarseerPhysics;
using System.Linq;
using System.Text;

namespace DSSGame1
{
public class LevelInfo
{
public ContentManager content;
public PhysicsSimulator physicsSimulator;
public GLEED2D.Level level;
public List<Tiles> tiles;
public List<PathTile> paths;
public Player player;
public List<Player> enemies = new List<Player>();
public List<Player> neutrals = new List<Player>();
public List<Player> friendlies = new List<Player>();
}
}

and GameStatus (not including the saving and loading methods)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace DSSGame1
{
public class GameStatus
{
/// <summary>
/// This class is the temporary storage for all information related to the game.
/// When a game is loaded, all information from that load is placed in this class,
/// and when the game is saved all the information in this class is copied over to
/// the storage file.
/// </summary>

public string currentLevel;
public LevelInfo levelInfo;
public AIOverlord aiOverlord;

You may not require all the info in those two classes, for example AIOverlord is part of my AI system which is unrelated, and you may not want to use my LevelInfo and GameStatus system, but I included them so you can see that I am storing information there that the attached Level.cs file needs and uses, you could easily change Level.cs to access this info in a different location.

The included Tiles.cs and PathTile.cs classes take the primitives from Gleed2D and add them to Farseer a Tile is a simple rectangle, whereas PathTile takes a path created in Gleed2D and makes it into a polygon. You can give these 'tiles' an enum TileCollision which can allow you use to define them in different ways to effect the collisions, but you will have to code that in yourself, they were intentionally meant to differentiate between passable tiles (no collision), impassible tiles, and platform tiles (can go through bottom, but not through the top) but that did not fit my needs to I changed the names of them, but at this point they don't do anything, so whatever you name them doesn't matter.

Player is obviously my player class, but I also use it to create AIs. Sadly, I cannot send you that class, so you will need to change the parts that mention Player to fit your needs. It only shows up near the bottom of Level.cs, and is used to spawn the players and AIs.

If you havent noticed already, I would warn you against reading any comments I have along side the code, as I am notorious for having stray and old comments that may no longer be accurate.

To make your Gleed2D files work with Level.cs, you will have to create a Collisions layer that contains all the primitives that create the collisions. Each item in that layer must be a rectangle or path and must contain a custom property called "Type". Make the description of Type Impassible, Passable, or whatever you name the TileCollisions I mentioned above.

The name of my project is DSSGame1, so wherever you see that, you are going to need to change it to the name of your project. You also may be missing some assembly references you need, if you are missing references, the ones you are missing should be obvious by the types of errors you are getting.

The way I label code I would not not be surprised if I left out an Important piece of information, or if there was something very complicated to understand, so if you need help just email me again.



forgot to tell you, in the main LoadContent method, this is how I load a level

levelInfo = new LevelInfo();

if (levelInfo.content == null)
levelInfo.content = new ContentManager(ScreenManager.Game.Services, "Content");
if (levelInfo.physicsSimulator == null)
levelInfo.physicsSimulator = new PhysicsSimulator(new Vector2(0, 300));

gameFont = levelInfo.content.Load<SpriteFont>("Fonts/gamefont");

level = Level.FromFile(gameStatus.currentLevel, levelInfo.content);
levelInfo.tiles = level.loadLevelTiles(gameStatus.currentLevel, levelInfo.content, levelInfo.physicsSimulator, level);
levelInfo.paths = level.loadLevelPaths(gameStatus.currentLevel, levelInfo.content, levelInfo.physicsSimulator, level);
level.allSpawn(levelInfo, gameStatus);
gameStatus.levelInfo = levelInfo;
levelInfo.player.gameStatus = gameStatus;
levelInfo.level = level;

Again, some of that may be unnecessary (like the gameFont), but most of it is necessary. And I think you will need to create a folder called Levels in your Content, and name all your levels Level1, Level2, etc... for them to load correctly.


Sorry for all the gibberish you had to read, but I decided it was more important to get the code up here as soon as possible, then to wait until I had made more eloquent instructions.

Last edited Jun 14, 2011 at 10:48 PM by DragonSwordsStdio, version 2

Comments

No comments yet.