Archive for June, 2008|Monthly archive page

ShackRPG: Game Menus, and Combo Battle System

It has been a while since I’ve posted, and for good reason. I’ve been trying to get the next segments done, but I’ve hit a few snags with a few of my design choices from before. Working through those however, I’ve been able to make a pretty cool little menu system for ShackRPG that keeps your focus on the game world without being too intrusive.

Since the game is being designed with a gamepad in mind, there are only 4 buttons being used to control everything within the game. Press the inventory button and a new screen pops up containing the game menu. Not all of these sub-screens are implemented, and because of this I have not updated the codebank yet, but I will!

Above is the character screen showcasing your equipment as well as character stats.

Modifying your equipment, currently in the ‘Weapon’ slot equipping a new weapon.

When the sub-screen menus are complete I’ll update the code bank. Below is a video of the combo system within the combat, as well as the Game Menus in action!

Keep in mind, all code can be found at;

ShackRPG: Updated Tile Engine Part 2

With the Map class complete, we can no start working extra things into our Tile Engine to display each map to screen. In its current state, the tile engine is incomplete for a few reasons including collision detection between characters and drawing order of all layers. However, i do have enough to get the basics of the engine up and running and continue to work on the rest of the systems of the game. So, on that note, lets begin!

I have 6 seperate regions to help organize the tile engine;
TileEngine Data – Houses all data associated with the engine. 3 data fields and properties; a true / false statement on if we’re loading a new map into memory, a Map file, and the mouse location for the editor.

Constructor(s) – initializes the tile engine on startup

private void Initialize()
map = new Map();

Update / Draw – … can you guess?
Update right now does nothing, but will call the “CheckCollisions();” method.
Draw just calls “map.Draw()” … so thats very easy.

Clamp Camera – Aah this is a fun one. I’ll post the code and see if you can make heads or tails of it.

public void ClampCameraToBoundries(Vector2 position)
//clamps the camera to the players position
Globals.Camera.Position.X = position.X – (Globals.Graphics.GraphicsDevice.Viewport.Width / 2);
Globals.Camera.Position.Y = position.Y – (Globals.Graphics.GraphicsDevice.Viewport.Height / 2);

//Clamps the camera within the game screen
Globals.Camera.Position.X = MathHelper.Clamp(Globals.Camera.Position.X, 0, (map.Width * map.TileWidth) – Globals.Graphics.GraphicsDevice.Viewport.Width);
Globals.Camera.Position.Y = MathHelper.Clamp(Globals.Camera.Position.Y, 0, (map.Height * map.TileHeight) – Globals.Graphics.GraphicsDevice.Viewport.Height);

Make sense? Basically you give the method the players current positional vector and it keeps the player within the center of the screen. If the player moves right, the camera moves right. If the player moves left, the camera left. However, after that it keeps the camera on top of the game world so if the player moves left to the edge of the map, the camera will stop when it reaches the imaginary edge.

Player Movement – This region does 4 things and is quite long compared to the camera clamping method. It will take the keyboard data collected by the games Update() method to determine if the player should be moving, and which direction. It then takes the positional vector of the player, and the speed modifier of the player, and calculates what the new position will be. Finally, it will take that new position, check to see if the player is on a tile it can walk on, and if so passes the new position to the game for update. If the player is on a tile they shouldn’t be on, it passes the old position, in essence, the player has not moved. Confusing huh? It can be.

Save / Load / Create New Map – map editor functions, and these are quite long and deal with loading and saving from an XML file from within the content pipeline. I do not write my own content importers or processors, so I’ve been using the System.XML namespace. If you want to know how its done, inquire within!

I tend to organize my programs by clumping things together. I know some people do “Data fields” “properties” “Constructor(s)” “Public Methods” “Private methods” but in bigger programs I’ve gotten into the habit of clumping everything together that goes with eachother. Might be a bad habit but to each his own. I’ve spent a few days on other systems for the Tile Engine and I’ve updated the code at the projects site. Next update I’ve had a request to post about my particle effects system, so I’ll get that in order and have it out here in a few days. I also will go into my in-game map editor.

As always, if you’re interested in checking out the full source code (newly updated), just head on over to;

ShackRPG: Updated Tile Engine Part 1

Over the past few days, I’ve been re-working my Tile Engine and Map Editor, and before I post on it I would like to say that it has been quite a bit bigger than I had anticipated. For that reason, this post will be broken up into several posts to show the basic features of the various components of the Tile Engine / Map Editor, but without having one big 30 page post on the whole sha-bang.

So on that note, we’ll start with the Map.cs file. This file will hold all of the map information, which is actually quite a bit of data. Some of the data fields include:

string Name – Map Name
int Height – Map Height
int Width – Map Width
int TileHeight – Height of each tile on map
int TileWidth – Width of each tile on map
string Tileset – Tileset used to draw the map

Point PlayerRespawnTile – Players respawn Location

List Tiles – List of textures used for map tiles
List NPCs – List of all NPCs on the current map
List Items – List of all world-items on current map (IE: Treasures)
List Portals – List of all portals leading to OTHER maps

string MusicCue – Music data to be used on map

int[,] BaseLayer – Base Layer Layout (Things you walk on top of, grass etc)
int[,] FringeLayer – Foreground Layers layout (Things you can walk behind)
int[,] ObjectLayer – Object Layers Layout (pots, barrels, plants, etc)
int[,] CollisionLayer – Collision Layer (Tiles you can not walk on)

This is most of the information needed to make a map work with this tile engine. The next step in getting the Map.cs file in order, was a way to Save, Load, and Initialize a map. Obviously for a complex role playing game, you’ll want to have several maps. Maybe a few towns, dungeons, an overworld map, city at sea, a sky level… The choices are limitless, but for every region you have in your game, you’ll have a map to hold the information. All of these maps will hold the same structure which makes it easy for the game to load and display

I really did not want to write my own content importer / content reader in the XNA engine, so I’ve stuck with the System.XML namespace. Because of this, each map will be stored in its own XML file and fed through the XNA content pipeline, but with the map.xml property set to “Do Not Compile.”

Below is a screenshot of a test map I did while testing the map engine showing off some of the map editor.

Red P = Player Respawn
Blue P = Portal to a different map
I = Item
M = NPC / Monster

The map name is called “Map001” and you can see the XML file HERE

Not too many problems came up while working with the Map.cs file, more-so when trying to get the editor up and running.. but I’ll save that writeup for another time. Could this map file be smaller? Probably. As it stands now, it is just under 1300 lines of code. There are also several other systems needed to display the map to screen, but for anyone interested in writing their own map engine in XNA, I figured the best place to start was the map itself.

Full project source code can be found HERE
Project homepage can be found HERE

Next time I’ll go more in depth on the Tile Engine, and some of the Map Editor.