Showing posts with label Character. Show all posts
Showing posts with label Character. 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.

Saturday, December 20, 2008

MMORPG Day 3

I finished the Character class on Day 3 of my MMORPG developing experience. It was pretty simple to create a method which would piece together a character from various 3D files. First I had to find a good way to save 3D models into files. I got myself a copy of K-3D and Blender to look at common file formats. I wanted it to be really simple so I wouldn't have any trouble with the data, I decided that maybe later I could think about using a proper file format. I picked the K-3D raw format since I as a human could understand it easily. It looks something like this:


# comments.. bla bla bla

# points
-1 2 3
6 -3 6
9 3 -5
1 5 8
-4 2 6
# polygons
1 2 3
3 4 1
1 3 2
1 3 4
1 2 4
1 2 3
1 2 3

First of all I loaded the file using the Java method I had created for loading text files. Then I excluded all lines starting with "#" except "# points" and "# polygons". I used those two comments as references as to what I was loading right now. I simply loaded all the points into a List using each of the three numbers as a coordinate (x,y,z). When I got to loading the polygons, triangles in this case, I picked the points out of the list with the corresponding index (ex. List Item number 1, 2, and 3) and created a Triangle with them which I then added to my Model.

I created a Model.merge method so I could load another model and merge it into the first model. This allowed for loading each part of a model separately, as was needed for my Character class.

Next I created a folder layout to save all my Character parts in. It would bring some more order into all the files I would need to create so that players could customise their character as they wanted. The folder layout looked something like this:

+CParts (character parts)
--Body
--Hat
--Gloves
--Shoes
--etc.

Each folder would have files in it with names ranging from the number 1 to something hopefully below 100. So to generate my players model I could simply load the corresponding file to the corresponding number in his Look Array from the correct folder. The number 0 in a players Look Array means that he isn't wearing that right now (ex. hat=0; not wearing a hat).

Once I finished that I started thinking about the Item class I would hopefully create on the next day. I didn't come up with anything but since my current speed is pretty good I hope I'll think of something tomorrow. If I don't, I'll start working on the Map class.