Fancy Mansion – Better collision and a start on A.I.

Last week we had a showcase of our alpha-release of the game. I think it was quite well received and we were given some tips on how we should continue. This week we have started working on an A.I. for our enemy in the game, Mr.Fancy. Also, during last week we implemented new walls into our game with a different perspective and the collision between the player and the walls were not working as intended.

So this week I have changed the size and position of some of the wall colliders to fit the size of the walls. Before, all walls were as big as a tile, 128×128 pixels, but now they have different shapes depending of what orientation the wall has, horizontal or vertical. The horizontal walls are as wide as a tile but are taller, while the vertical walls are much thinner than a tile but also a bit taller. I use a class called Collider, which basically is a rectangle, to define areas that can be checked for collision. When creating the walls we check what kind of wall it is (a corner piece, a regular horizontal wall, a doorpost, etc.) and create a new instance of the Collider class according to the wall piece. We wanted the player to be able to walk behind the walls and thus we made the colliders as big as the walls were thick. As seen in the picture below some of the walls have different sized colliders depending of what kind of wall they are and where they are placed.

FancyMansion_Blogpost_3_printscreen_5

If the second (yellow) collider had had the same size of the third (red) collider the player would have been able to walk through the wall in between the first (blue) and second (yellow) tile. So to make sure no gaps existed I had to make sure every different piece covered areas that they had to cover, in this case the bottom doorpost.

So with this the player would be able to stay close to the walls and be able to stand behind them, as seen in the next pictures. The blue box at the player’s feet is the collider of the player for collision with walls.

FancyMansion_Blogpost_3_printscreen_1

FancyMansion_Blogpost_3_printscreen_2

In the last picture we see the player standing behind the wall. To simulate this we had to make sure things the walls that had a bigger y-value were drawn on top of the player. This is done by giving each object in the game a depth index which is then used to draw things in according on where they are in the game. By looking at the picture above you can see the tiles make up of rows. Each row is drawn after each other, starting at the top. So the first row, which is the walls in this case, have a depth index of 1, the second row a depth index of 2, and so on.

We still have a long way to go with implementing A.I. for Mr.Fancy, but we have made him follow the player (when pressing a button) and also he has a collider so he will not move through the walls. This is a very basic start on an A.I.

FancyMansion_Blogpost_3_printscreen_4

Next step is to make Mr.Fancy follow a path to the player, instead of just moving towards the exact position of the player. We have been researching some path finding methods, including A* (a-star). A very useful website to show different kinds of path finding methods is this website (click it!).

We will continue working on optimizing collision and also making Mr.Fancy a real threat to the player.

About Sven Almberg

2014  Programming