C# Class ChaseAndEvade.ChaseAndEvadeGame

Sample showing how to implement simple chase, evade, and wander AI behaviors. The behaviors are based on the TurnToFace function, which was explained in AI Sample 1: Aiming.
Inheritance: Microsoft.Xna.Framework.Game
Show file Open project: Jorgemagic/MonoGame Class Usage Examples

Public Methods

Method Description
ChaseAndEvadeGame ( ) : System
ChaseAndEvadeGame ( Android.App.Activity activity ) : System

Protected Methods

Method Description
Draw ( GameTime gameTime ) : void

This is called when the game should draw itself. Nothing too fancy in here, we'll just call Begin on the SpriteBatch, and then draw the tank, cat, and mouse, and some overlay text. Once we're finished drawing, we'll call SpriteBatch.End.

Initialize ( ) : void

Overridden from the base Game.Initialize. Once the GraphicsDevice is setup, we'll use the viewport to initialize some values.

LoadContent ( ) : void

Load your graphics content.

Update ( GameTime gameTime ) : void

Allows the game to run logic.

Private Methods

Method Description
ClampToViewport ( Vector2 vector ) : Vector2

This function takes a Vector2 as input, and returns that vector "clamped" to the current graphics viewport. We use this function to make sure that no one can go off of the screen.

HandleInput ( ) : void

Handles input for quitting the game.

TurnToFace ( Vector2 position, Vector2 faceThis, float currentAngle, float turnSpeed ) : float

Calculates the angle that an object should face, given its position, its target's position, its current angle, and its maximum turning speed.

UpdateMouse ( ) : void

This function contains the code that controls the mouse. It decides what the mouse should do based on the position of the cat: if the cat is too close, it will attempt to flee. Otherwise, it will idly wander around the screen.

UpdateTank ( ) : void

UpdateTank runs the AI code that will update the tank's orientation and position. It is very similar to UpdateMouse, but is slightly more complicated: where mouse only has two states, idle and active, the Tank has three.

Wander ( Vector2 position, Vector2 &wanderDirection, float &orientation, float turnSpeed ) : void

Wander contains functionality that is shared between both the mouse and the tank, and does just what its name implies: makes them wander around the screen. The specifics of the function are described in more detail in the accompanying doc.

WrapAngle ( float radians ) : float

Returns the angle expressed in radians between -Pi and Pi. the angle to wrap, in radians. the input value expressed in radians from -Pi to Pi.

Method Details

ChaseAndEvadeGame() public method

public ChaseAndEvadeGame ( ) : System
return System

ChaseAndEvadeGame() public method

public ChaseAndEvadeGame ( Android.App.Activity activity ) : System
activity Android.App.Activity
return System

Draw() protected method

This is called when the game should draw itself. Nothing too fancy in here, we'll just call Begin on the SpriteBatch, and then draw the tank, cat, and mouse, and some overlay text. Once we're finished drawing, we'll call SpriteBatch.End.
protected Draw ( GameTime gameTime ) : void
gameTime Microsoft.Xna.Framework.GameTime
return void

Initialize() protected method

Overridden from the base Game.Initialize. Once the GraphicsDevice is setup, we'll use the viewport to initialize some values.
protected Initialize ( ) : void
return void

LoadContent() protected method

Load your graphics content.
protected LoadContent ( ) : void
return void

Update() protected method

Allows the game to run logic.
protected Update ( GameTime gameTime ) : void
gameTime Microsoft.Xna.Framework.GameTime
return void