All pastes #739261 Raw Edit

Something

public text v1 · immutable
·published 2007-10-17 00:14 UTC
rendered paste body
using System;
using System.Collections.Generic;
using System.Text;

using FlatRedBall;
using FlatRedBall.Math;
using FlatRedBall.Math.Geometry;
using FlatRedBall.Graphics.Animation;
using FlatRedBall.Instructions;

using Microsoft.Xna.Framework;


namespace StanleyFrost
{
    public class Enemy : PositionedObject
    {
        public enum States
        {
            Attack_Player,
            Fear,
            Moving,
            No_Fires,
            Searching,
            StartingFire,       
        }

        protected States state;

        protected FireBehaviors fireBehavior;

        protected FireColor enemyColor;

        protected float health;
        protected float moveToX;
        protected float moveToY;

        protected Vector3[] playerPositions;

        protected Polygon bodyPolygon;
      
        public States State
        {
            get { return state; }
            set { state = value; }
        }

        public FireBehaviors FireBehavior
        {
            get { return fireBehavior; }
        }

        public FireColor EnemyColor
        {
            get { return enemyColor; }
        }

        public float Health
        {
            get { return health; }
        }

        public Polygon BodyPolygon
        {
            get { return bodyPolygon; }
        }

        public Enemy()
        {
            SpriteManager.AddPositionedObject(this);

            X = 10;
            Y = -12;
            Z = 1;

            Sprite testSprite = SpriteManager.AddSprite("Grfx/demun.bmp");
            testSprite.AttachTo(this, false);
            testSprite.ScaleX = 2.5f;
            testSprite.ScaleY = 2.5f;

            playerPositions = new Vector3[Game1.PlayerList().Count];

            //XVelocity = -5;

            SetEnemyParameters();
        }

        public virtual void Activity()
        {
            CheckState(FindClosestPlayer());
        }

        public virtual void CheckState(Vector3 player)
        {
            if (state == States.Searching)
            {

            }
            else if (state == States.Moving)
            {
                if (X == moveToX && Y == moveToY)
                {
                    state = States.StartingFire;
                }
            }
            else if (state == States.StartingFire)
            {

            }
            else if (state == States.No_Fires)
            {

            }
        }

        protected Vector3 FindClosestPlayer()
        {
            Vector3 closestPlayer=playerPositions[0];
            float closestDistance = (float)Math.Sqrt((double)((X - closestPlayer.X) * (X - closestPlayer.X)) + (double)((Y - closestPlayer.Y) * (Y - closestPlayer.Y)));
            float tempDistance;
            for (int i = 1; i < playerPositions.Length; i++)
            {
                tempDistance=(float)Math.Sqrt((double)((X - playerPositions[i].X) * (X - playerPositions[i].X)) + (double)((Y - playerPositions[i].Y) * (Y - playerPositions[i].Y)));
                if (closestDistance < tempDistance)
                {
                    closestPlayer = playerPositions[i];
                }
            }
            return closestPlayer;
        }

        public void GotoEmptySpaceAt(FlatRedBall.Math.Geometry.Point emptyPosition)
        {
            if (emptyPosition.X != X || emptyPosition.Y != Y)
            {
                Instructions.Clear();
                moveToX = (float)emptyPosition.X;
                moveToY = (float)emptyPosition.Y;
                float timeToTake = (float)Math.Sqrt((double)((X - moveToX) * (X - moveToX)) + (double)((Y - moveToY) * (Y - moveToY))) / 7;
                InstructionManager.MoveToAccurate(this, moveToX, moveToY, Z, timeToTake);
                state = States.Moving;
            }
            else
                state = States.No_Fires;
        }

        protected virtual void SetEnemyParameters()
        {
            enemyColor = FireColor.Red;
            fireBehavior = FireBehaviors.Single;
            state = States.Searching;
            health = 100;
        }

        public void UpdatePlayerPosition(int playerIndex, Vector3 position)
        {
            playerPositions[(int)playerIndex] = position;
        }
    }

}