• Create Account

# Valgor

Member Since 07 Oct 2012
Offline Last Active Nov 03 2012 01:10 PM

### Looking for a code/desgin review of continous map implemention

28 October 2012 - 07:22 PM

Hello, incoming huge post! I am creating a 2D RPG where the entire world is open and continous. That is, there are no instances (for now). I am looking for any and all criticism over my design and code. I also hope this will help future developers. I will explain my ideas and walk through the design. At the bottom you can find my entire implemention.

The world is divided up into tiles where each tile is one image. Each tile is named "X_Y" where x and y are the coordinates with respect to the entire world. Suppose our playable character starts in 3_3, and the tile the character is actively in is called the center tile. The character renders to the center of the screen always (think Diablo), so we keep track of the map tile's (x,y) position and also the character's (x,y) position relative to the map. The difference in distance between the two is called the xOffSet and yOffSet.

There are two main steps in the Update method. (1) Checks to see if we need to load nearby tile and (2) see if we are no longer in the center tile.

(1) The center tile has an interboundry rectangle, so that if this boundary is crossed, we must load a nearby tile to render. Suppose we are in 3_3 moving east towards the edge so the 4_3 must be loaded. The code to check for this is here:

[source lang="csharp"]if (Math.Abs(mapPosition.X) > interBoundaryWidth){ if (!bEast) { Load(EAST, 1, 0); bEast = true; }}else if (bEast){ Unload(EAST); bEast = false;}[/source]

Similar sections of code are used for all possible directions including the need to load NE, NW, SE, and SW maps.

(2) This section sees if our character has moved out of the center tile and into another. Continuing with the east example, suppose our character moves from being in 3_3 into 4_3.

[source lang="csharp"]if (Math.Abs(mapPosition.X) + (GraphicsDeviceManager.DefaultBackBufferWidth / 2) > tileWidth){ foreach (MapTile bt in mapTiles) { if (bt.direction == CENTER) bt.direction = WEST; else if (bt.direction == NORTH) bt.direction = NW; else if (bt.direction == SOUTH) bt.direction = SW; } foreach (MapTile bt in mapTiles) { if (bt.direction == EAST) { bt.direction = CENTER; mapName = bt.name; } else if (bt.direction == NE) bt.direction = NORTH; else if (bt.direction == SE) bt.direction = SOUTH; }worldManager.setCharacterPosition(new Vector2(characterPosition.X + tileWidth, characterPosition.Y));[/source]

The first if statement sees if we have crossed outside of the map tile's width and thus into a new map tile. If we have, we want to update all the tiles to reflect the direction on the new center tile. Consider this crude drawing that maps each possible tile into the new direction. Note that only the N/NE or S/SE sections could possibly be loaded at the same time since the north and south tiles cannot be loaded at the same time because the maps are bigger than our screen. "C" is for "Center" which is where our character is located.

--------- -----------
| N | NE | | NW | N |
---------- ------------
| C | E | ---> | W | C |
---------- ------------
|S | SE | | SW | S |
---------- ------------

So our center tile becomes the west tile, and the west tile becomes the center tile, and so on for the other tiles. The order of changing the directions is important, which is why I have two foreach loops. Lastly, we update the character's position to that it starts on the far left side of the new center tile.

Finally, the rendering is based on the tile's direction which can be seen in my code below. If you have read this far, please leave a comment! I'm open to improvements and hopefully would like to help others tackling this problem. Thanks for reading!

### 2D RPG Example Games

20 October 2012 - 07:38 AM

Hello,

Does anyone know of any 2D RPG games that are free or open sourced?

I'm looking for examples of how other games of this genre handle various tasks and organization.

Thanks!

### 2D Animation Scripting

08 October 2012 - 05:32 PM

I posted this in the graphics section and recieved no replies, so maybe I'll have better luck here!

I've been working on a 2D RPG in XNA. While browsing tutorials and videos, I've heard them mention doing animation in a seperate script file. Since tutorials are always brief and never indepth, the following questions persist:

1) Are scripting languages faster than C# for animations? Is that why we would want to use them?

2) Is this only for time/movie like animations and not animations that require input (such as pressing up to animate my sprite to move up compared to a cut scene that plays regardless of input).

3) Good, possible, and best scripting lanuage to use for animation?

4) Any other reason to use scripts in a game?

Thanks!

### 2D Animation Scripting

07 October 2012 - 08:40 AM

I've been working on a 2D RPG in XNA. While browsing tutorials and videos, I've heard them mention doing animation in a seperate script file. Since tutorials are always brief and never indepth, the following questions persist:

1) Are scripting languages faster than C# for animations? Is that why we would want to use them?

2) Is this only for time/movie like animations and not animations that require input (such as pressing up to animate my sprite to move up compared to a cut scene that plays regardless of input).

3) Good, possible, and best scripting lanuage to use for animation?

Thanks!

PARTNERS