Best way to code basic stealth-mechanics?

Started by MistyShires, Fri 22/01/2021 08:43:18

Previous topic - Next topic

MistyShires

Hello!

I have been thinking about adding a basic stealth-mechanic during certain areas of my game to increase the tension.

The first moment that I wish to experiment with being in a basement full of boxes with the character only being able to walk pass certain gaps between them when the enemy isn't looking (viewable through some kind of lighting-effect, walking at the wrong time and being seen will off course result in a game over).

I was a tad curious how this could be done in AGS and depending on how difficult it would be to code, I might be interested in adding a bigger stealth-area later on.

PS: I have no idea if this belong here or under Advanced questions. Please tell me if I need to relocate it.

Khris

It's not that hard to implement. AGS has "Regions" you can use to mark certain parts of your walkable areas. And since the enemy character is turning, you can use their .Loop property to check the direction they're facing.

So all you need is to continuously check if the player is being seen.

Code: ags
function room_RepExec()
{
  Region* r = Region.GetAtRoomXY(player.x, player.y);

  if (cEnemy1.Loop == 3 && r.ID == 1) GotCaught(); // cEnemy1 is facing down and player is inside region #1
  if (cEnemy2.Loop == 2 && r.ID == 2) GotCaught(); // cEnemy2 is facing right and player is inside region #2
}

MistyShires

Thank you! This was really helpful, I assume that something similar could be done with sound-effects.

Say, a sound-effect that automatically plays when the monster is in the room that you can hear from the one next to it and if you head inside that room you get a game over?

SMF spam blocked by CleanTalk