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
Afficher le fichier Open project: Jorgemagic/MonoGame Class Usage Examples

Méthodes publiques

Méthode Description
ChaseAndEvadeGame ( ) : System
ChaseAndEvadeGame ( Android.App.Activity activity ) : System

Méthodes protégées

Méthode 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

Méthode 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 méthode

public ChaseAndEvadeGame ( ) : System
Résultat System

ChaseAndEvadeGame() public méthode

public ChaseAndEvadeGame ( Android.App.Activity activity ) : System
activity Android.App.Activity
Résultat System

Draw() protected méthode

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
Résultat void

Initialize() protected méthode

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

LoadContent() protected méthode

Load your graphics content.
protected LoadContent ( ) : void
Résultat void

Update() protected méthode

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