//----------------------------------------------------------------------------- // Animal.cs // // Microsoft XNA Community Game Platform // Copyright (C) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- using System; using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; namespace Flocking { public enum AnimalType { // no type Generic, // flies around and reacts Bird, // controled by teh thumbstick, birds flee from it Cat } /// /// base class for moveable, drawable critters onscreen /// public class Animal { /// /// texture drawn to represent this animal /// protected Texture2D texture; /// /// tint color to draw the texture with /// protected Color color = Color.White; /// /// center of the draw texture /// protected Vector2 textureCenter; /// /// movement speed in pixels/second /// protected float moveSpeed; /// /// All the behavior that this animal has /// protected Dictionary behaviors; /// /// The animal type /// public AnimalType AnimalType { get { return animaltype; } } protected AnimalType animaltype = AnimalType.Generic; /// /// Reaction distance /// public float ReactionDistance { get { return reactionDistance; } } protected float reactionDistance; /// /// Reaction location /// public Vector2 ReactionLocation { get { return reactionLocation; } } protected Vector2 reactionLocation; public bool Fleeing { get { return fleeing; } set { fleeing = value; } } protected bool fleeing = false; public int BoundryWidth { get { return boundryWidth; } } protected int boundryWidth; public int BoundryHeight { get { return boundryHeight; } } protected int boundryHeight; /// /// Direction the animal is moving in /// public Vector2 Direction { get { return direction; } } protected Vector2 direction; /// /// Location on screen /// public Vector2 Location { get { return location; } set { location = value; } } protected Vector2 location; /// /// Sets the boundries the animal can move in the texture used in Draw /// /// Texture to use /// Size of the sample screen public Animal(Texture2D tex, int screenWidth, int screenHeight) { if (tex != null) { texture = tex; textureCenter = new Vector2(texture.Width / 2, texture.Height / 2); } boundryWidth = screenWidth; boundryHeight = screenHeight; moveSpeed = 0.0f; behaviors = new Dictionary(); } /// /// Empty update function /// /// public virtual void Update(GameTime gameTime) { } /// /// Draw the Animal with the specified SpriteBatch /// /// /// public virtual void Draw(SpriteBatch spriteBatch, GameTime gameTime) { float rotation = (float)Math.Atan2(direction.Y, direction.X); spriteBatch.Draw(texture, location, null, color, rotation, textureCenter, 1.0f, SpriteEffects.None, 0.0f); } } }