Showing posts with label Height Maps. Show all posts
Showing posts with label Height Maps. Show all posts

Tuesday, December 30, 2008

MMORPG Day 9

On Day 9 of MMORPG development I turned the player into a grey box and allowed him to walk around. To do that I had to implement collision detection, which is easy to do for tile based maps.

The walking was handled by four methods in the Character class: walkUp, walkDown, walkLeft, walkRight. When a method was called (probably by a key press), it checked if the player would collide with the tile the player was about to walk on and then accordingly moved the player. The collision system looks something like this:


Each tile had four edges, each of which could be walk-through or not. To move the player the walk-methods had to check if the corresponding wall on the current tile was walk-trough and if the corresponding wall on the next tile was walk-through. If this was not the case, the player was not moved. In the above case the player (black dot) wants to move left. The tile the player is on allows that but the tile the player is going to move too doesn't so the player isn't allowed move.

I had to make an additional collision map for my current test map. The collision map stores the collision values of all four walls of each tile in the map. It was a simple arrays of 0's and 1's, where a 1 stands for collision and 0 stands for walk-through.

Each time the player moved his height he had too be properly adjusted so that if he moved to a higher tile, he doesn't sink into the floor and if he moved to a lower tile, he doesn't float above it. This was also handled by the four walk methods. The methods simply found the average of the tiles Vertices and used that as the players height. This has some disadvantages on very very steep tiles but I'm not planing to let the player walk on top of tiles with more than a 45 degrees slope.

It's kind of great to be able to walk around the small test world and I'm happy because the MMORPG is now a big step closer to being finished.

Monday, December 29, 2008

MMORPG Day 8

On Day 8 I totally restructured the Map class (object). I found my current Map class was going nowhere and I saw no way out. I had one of those "Java Revelations" where you suddenly think of a way a lot easier and elegant than the one you're currently using. I shrank the code for the Map by half and now it's a lot easier to alter and more open to different options.

What I basically did was to substitute arrays and loops for things I was doing in a totally different way. I'm pretty surprised that I hadn't thought about this stuff before but I probably didn't think it was necessary. I now have an array of tiles in my Map class. Each tile holds all the variables about itself and almost nothing gets stored in the Map class itself except very general things. A Tiles variables include: Walkability (collision of all four sides), Colour(s), Object (ex. thing on top), Heights (all four corners), Actions (some script of a scripting language I haven't created yet triggered by character moving near/on tile).

I thought of a way to determine an objects/characters height when on a Tile. I would simply take the four sides of a Tile and find the average (height1+height2+height3+height4/4). The Characters height would have to be altered accordingly when moving. I hope to interpolate between nearby tiles when the character is not standing on any to find the next best height.

Nothing else really happened on day 8 which is kind of disappointing but I hope twice as much is going to happen on day 9 as I kind of pre-worked.

Sunday, December 28, 2008

MMORPG Day 7

Day 7 improved the look of the MMORPG a lot. Here's how the MMORPG looked after day 7:


It was very easy to add colour to the height field I had already created. I simply created a text file similar to the height field file and put colours inside instead of heights. The colours where given as rgb (red green blue) as that was the only option I would even consider. There was one simple problem I had to face:


The height field had a number for each Vertex (those red dots) so the colour file had stored a colour for each vertex too. I could probably have Interpolated Colours between the vertices to create the gradient colours inside the squares but that would have slowed down the Applet a lot so I simply assigned the colour of a squares bottom-right vertex to the entire square. This way the first row of vertices from the left and top simply got ignored but if I ever change my mind to interpolating colours I won't have to change any files.

I plan to approach the adding of objects on top of the tiles the same way. I'll simply create another file for the same map and store objects numbers instead of Colours or heights. I hope it works. I'll see if it works tomorrow (hopefully).

Saturday, December 27, 2008

MMORPG Day 6

Merry Christmas Again!

The MMORPG became interactive on day 6 of it's development. I made it possible to move around the map and change the camera angle.

To move around the map I either had to move the Map itself or the Character and the Camera. I decided to move only the Map since it was harder to move the Camera and the Character. Every time the character "moves" a tile, the map gets translated by the TileSize to make it look like the character moved.

The camera angle can be moved freely which isn't so great yet. I'm going to have to find some proper camera restrictions so that the player can't rotate the map 180 degrees and look below it.

The MMORPG of day 6 can be found Here. You can move around by using the arrow keys. You can change the camera angle by holding down the control key and pressing an arrow key. Unfortunately you have to press the arrow key each time you want to change the camera angle by 0.5. I'm probably going to change that.

To finish the Map I need to be able to load Objects and add them on top of the height map. Then I need to be able to display everything in color, not in grey tones. Then I need to put the character class into the map at the proper height. Then I'm finished with a lot of the MMORPG and I will be happy.

Monday, December 22, 2008

MMORPG Day 5

I got a lot done on Day 5. I started working on a Height Map loader which can load a 3D map from a 2D height map. It looks really good although I don't have any great maps yet.

First I had to create a height map to test the loader. I wasn't sure if I should use a picture or a text file. I decided on a text file since it's easier to store additional information about the map this way. I decided on a really simple format:


// A random 5*5 Sized Map
1,-2,4,1,4
-2,8,5,6,2
1,0,0,2,3
4,6,2,5,7
-1,0,4,3,2



To load that height map I first created a grid of 5*5 Vertices and connected them together with triangles so that they would form a Square pattern like so:


After that I simply assigned a number to each vertex so that they would be the height they should be in. A resulting height map of the Loader looked something like this in my 3D Engine:


Now I just would have to find the perfect size of the squares and the Height Map loader would be finished. I though of 32 times 32 pixels because most 2D video games use this tile size. I found 32 pixels too small to fit a 3D human into so I set it to 50 pixels. 50 Pixels is quite good and I'll probably stay at that size but I'm not sure yet.

Now to finish the Map loader I need to find a way to load objects (ex. trees, houses, chairs) into the map and place them at the appropriate position. Then I need to find a way to add colour to the whole thing, grey is kind of boring. After that I should find a way to make the Camera focus on a certain tile (probably the one with the player on it). I'm not quite sure how much more time I have before Christmas so I'm saying that the next MMORPG Day might be more than 3 days from now.

Merry Christmas!