Fancy Mansion – Adding more AI with pickups

This week I have been working with implementing more of the functionality with the different pickups and how they work with the AI. We have a number of items you can pick up and when you carry a specific item the AI of Mr. Fancy will work in different ways. For example, Mr. Fancy will not shoot you if you carry the armor and he have not seen you move. As stated in a previous post the player picks things up by pressing the E key and drops them by pressing the Q key. By pressing the SPACE key the player is also able to use specific items that they are carrying. More specifically, I have been working with implementing the bear pelt, which hides the player when used, and also the painting, which makes Mr. Fancy not able to see the player if the player is holding the painting in the direction of Mr. Fancy.

When working with implementing the bear pelt there were some things that needed to be fixed, for example the player should not be able to drop the pelt if there are not enough room (standing next to a wall, etc.). Luckily, I could use the array each tile stores with adjacent tiles to see if there is a wall next to this tile. So if the player stand on a tile to the left of a wall and presses the Q key, I check if the adjacent tiles to the right of tile is not a wall and then places it back on the floor. In this case the pelt will not be placed on the floor and will still be in the player’s hands.

FancyMansion_Blogpost_6_printscreen_1

When pressing the SPACE key the player will hide under the pelt and will not be able to move. I have a Boolean variable which will be set to true when hiding, and this is used to make the player unable to move and also for making Mr. Fancy not see you when he walks by.

FancyMansion_Blogpost_6_printscreen_2

The painting works in a similar manner when it comes to where the player should be able to drop it. The bear pelt needs space on the floor so it will not clip through the walls, but the painting needs to be on a wall, and more specifically the wall on the tile straight above the current tile. If there are no wall straight above the player, the player will not be able to drop it.

FancyMansion_Blogpost_6_printscreen_3

If you have read my previous post on how I made Mr. Fancy see the player you know that I use Collider-objects for the walls and that Mr. Fancy will no see you if there are a wall in between you. The painting works in the same way, though the collider moves and changes shape each time the player moves in different directions. So if the player is facing Mr. Fancy he will not see the player. But if the player moves in a different direction Mr. Fancy will probably see the player and attack. In the picture below we can see the collider (light blue) and the line between the player and Mr. Fancy, making up of Mr. Fancy’s vision, and we can see that the collide and thus Mr. Fancy will not see you. Though, if Mr. Fancy gets too close he will still shoot.

FancyMansion_Blogpost_6_printscreen_5

About Sven Almberg

2014  Programming