Benjamin Yang · EAE 6320

Final Project Proposal: Kitchen Raid

A small top-down sneaking game: a mouse steals cheese from a kitchen at night while the cats patrol. It uses my collision system and Feiyang Yang's AI state machine library.

My Engine System: collision Feiyang Yang's Engine System: AI state machine This is the proposal for my final project, so there is nothing to download or play yet. The game, its download and its controls will be in the final write-up (due December 6; presentations are on December 7).

The game

Kitchen Raid (a working title) is a small top-down sneaking game. You are a mouse. It is night, the kitchen is full of cheese, and two cats are walking around the house. You win by bringing the big cheese wheel home without being caught.

For the final project we make a new game with the engine we built this semester, using our own Engine System and at least one Engine System made by a classmate. I wanted a game where both systems are needed for the main idea and aren't just added on the side. Sneaking only works if walls stop you and also hide you (collision and raycasts), and if the guards act differently when they see you and when they lose you (a state machine). It is also the game that Feiyang Yang and I sketched at the end of our joint Engine System presentation (https://fffeiya.github.io/game-essay/engine-system-presentation/), so now I get to find out whether that sketch really works.

One round

The cats

Each cat walks its own patrol route. A cat sees you if you are within 6 units, inside the 90° in front of it, and nothing solid is between you: walls, furniture and closed doors all block its view. When a cat sees you, it chases you, faster than it walks. If you break its line of sight (behind the table, or through a door), it runs to the spot where it last saw you and looks around for a few seconds before it goes back to its route. A small marker above each cat's head shows its state, so the player (and the people watching my presentation) can see what it is thinking.

Doors

The door between the kitchen and the dining room opens when the mouse is close and closes again after the mouse has left. Cats can't open doors, so a closed door both stops a chasing cat and hides you from it. The pantry door works the same way, except that it starts locked (and red) until all six crumbs are eaten.

A sketch of the level, from above
Figure 1. A sketch of the level, from above. Cat 1 can't see the mouse because its raycast hits the table first. Sizes and positions will change when I play-test it.

Controls (planned)

Arrow keys or WASD: move the mouse. Esc: quit. That is all: there is no jumping and nothing to aim.

What the game will do, and what it won't

It will

It won't

If I have time

How I will use my Engine System (collision)

My Engine System is a collision library (https://game6320-website.netlify.app/engine-system/). Objects get spheres and axis-aligned boxes that are described in Lua files, layers say which kinds of objects touch, solid objects stop each other, triggers only report, the game gets OnEnter, OnStay and OnExit events, and it can cast rays. In Kitchen Raid it does most of the game's rules:

What happens in the gameHow the collision system does it
Walls and furniture stop youstatic boxes in the wall layer; the mouse and the cats are solid spheres that get pushed back out, and their velocity into the wall is removed, so they slide along it
Eating a crumb, picking up the wheeltrigger spheres in the pickup layer; the mouse's OnEnter hides the crumb and disables its collider
Getting caughtthe mouse's OnEnter with a collider in the cat layer
Getting homea trigger box in the mouse hole; OnEnter wins the round if the mouse carries the wheel
Doorsa solid box that is disabled while the door is opening or open, and a bigger trigger box around it whose OnEnter and OnExit tell the door's state machine whether the mouse is near
Can a cat see the mouse?after a distance and angle check, a raycast from the cat to the mouse that can hit walls, furniture, doors and the mouse: the cat sees the mouse only if the mouse is the first thing that the ray hits

The layers file will be something like this (it may change while I build the game):

-- Content/Collision/game.layers (in the new game's folder)
return
{
	layers = { "wall", "door", "mouse", "cat", "pickup", "zone" },

	-- Pairs that touch; every other pair passes through without events
	interactions =
	{
		{ "mouse", "wall" }, { "mouse", "door" }, { "mouse", "cat" },
		{ "mouse", "pickup" }, { "mouse", "zone" },
		{ "cat", "wall" }, { "cat", "door" }, { "cat", "cat" },
	},
}

And the line of sight is the example from my own user guide, with a door layer added:

// Can this cat see the mouse? (after a distance and view angle check)
const auto toMouse = m_mouse.rigidBodyState.position - cat.rigidBodyState.position;
Collision::sRaycastHit hit;
const bool canSeePlayer = isInViewCone( cat, toMouse )
	&& Collision::Raycast( cat.rigidBodyState.position, toMouse, toMouse.GetLength(), hit,
		m_layerMask_wall | m_layerMask_door | m_layerMask_mouse )
	&& ( hit.collider == m_mouse.collider );

This will also be the first time that my collision system goes into a game I didn't write it for. I'll add it to the new game project by following my own README and user guide, and in the final write-up I'll say what was easy and what I would change. My demo already has a patroller that uses raycasts, but a door that is only sometimes solid, and trigger zones that turn into parameters for another system, will test parts of the interface that the demo hardly used.

Where I'm starting from: my Engine System demo (MyGame), a small platformer built on the same collision system
Figure 2. Where I'm starting from: my Engine System demo (MyGame), a small platformer built on the same collision system. The final game will be a new project.

The other Engine System: Feiyang Yang's AI state machine

I will use the AI state machine library made by Feiyang Yang. Its write-up is at https://fffeiya.github.io/game-essay/engine-system-write-up/, and I'll use the code ZIP from that page (https://fffeiya.github.io/files/EngineSystem_StateMachine.zip). Feiyang and I presented our Engine Systems together, so I already know how it works, and we found that the two systems fit together well.

With it, an AI is described in a Lua .fsm file: the initial state, the parameters that the game sets (floats, bools and triggers), the states, and the transitions between them. A transition fires when all of its conditions are true and, if it has one, its minimum time in the state has passed, and the "any state" transitions are checked first. StateMachineBuilder checks the file and builds it into a binary .fsmbin file during the asset build, the same way our MeshBuilder works, and a mistake in the file fails the build with the file and line. In the game, a cStateMachineDefinition is loaded once (it is reference counted, like a mesh) and every agent gets its own cStateMachine. The game looks up state and parameter handles by name once, then every simulation update it sets the parameters (SetBool(), SetFloat(), SetTrigger()) and calls Update(). At most one transition fires per update, and each state can have enter, update and exit callbacks: function pointers with a void* for user data, like the rest of the engine. In Debug builds every state change is written to the log together with the condition that caused it, which will help a lot when a cat does something strange.

What it will do in my game

The cat's state machine, written as data for Feiyang Yang's library
Figure 3. The cat's state machine, written as data for Feiyang Yang's library. canSeePlayer comes from a raycast and caughtPlayer from a collision event, both from my collision system.
The door's state machine: Feiyang Yang's door
Figure 4. The door's state machine: Feiyang Yang's door.fsm example. isPlayerNear comes from the door's trigger zone (OnEnter and OnExit), and the toggleLock trigger locks the pantry door at the start and unlocks it when the last crumb is eaten.
One simulation update
Figure 5. One simulation update. Orange is my game code, blue is my collision system, and green is Feiyang Yang's state machine library.

Why a state machine instead of a few if statements? Even three states with timers would turn into a tangle of bools in C++. In a data file I can tune when a cat gives up, or add the Asleep or Pounce state, without changing the code that moves the cats, and the debug log tells me exactly which condition fired.

Plan

WhenWhat
Nov 21 to 24Create the new game project and make it build in all four configurations. Add Feiyang's StateMachine library and StateMachineBuilder by following their README. Walls, floor, and the mouse moving with my collision system.
Nov 25 to 29The cats: patrol routes, raycast vision, cat.fsm with Chase and Search, getting caught. The crumbs, the cheese wheel and getting home.
Nov 30 to Dec 3Doors and door.fsm. Meshes in Maya (the mouse, a cat, cheese, furniture). The camera. Play-testing the speeds and how far the cats can see. Then the "if I have time" list.
Dec 4 to 6Release builds and the download ZIP, screenshots, and the final write-up (due December 6).
Dec 7The presentation in class.

What could go wrong

Credits