Saturday, 2 May 2009

How to: end game when caught by Guards

Ending the game if a guard catches the player

Torque engine comes with a console method called onCollision. This is the function which I will be working on.

In the game we will be colliding with many objects.Hence, if I am going to use this function i need to know what I am colliding with. One way i can do this is the check the collided object and see what kind of datablock it is based on. collided object has to be defined with a datablock other wise wont work.

after studying of the code, I found that the datablock used for A.I guards is AIPlayer. The data block scripted in player.cs (located at gameDirectory/server/scripts). I will also define the oncollision function inside the player.cs file



next thing i need to do is create a way to end the game. I will be checking the $isBeenCought variable. if it is true it will end the game.

The repeatTillQuit function has been discussed in how to add count down timer. I need to modify this function further to end the game if the player get caught. I prefer this function just because it is recursive. The function scheduled to call it self every one second. Basicly I can check the status of the game in every one second.


Note that i also add if else statement to see if the game ends as a result of running out of time or being caught by a guard. By using if else statements, i can change the background images and screen writing based on the way the game ended.

No comments:

Post a Comment