Beispiel #1
0
        /// <summary>
        /// Initialize the base class for Enemy
        /// </summary>
        /// <param name="position"> position of the enemy on the screen </param>
        /// <param name="texture"> texture to draw the enemy with </param>
        public Entity(Vector2 position, Texture2D texture) : base(position, texture.Width, texture.Height)
        {
            this.Color        = Color.White;
            this.tex          = texture;
            this.attackTarget = Vector2.Zero;
            this.speed        = 1;

            StandardMovementFactory mf = new StandardMovementFactory();

            this.movement = mf.CreateMovement(MovementFactory.MovementType.None, this);
        }
Beispiel #2
0
        /// <summary>
        /// Creates a new instance of a bullet using targeted movement
        /// </summary>
        /// <param name="position"></param>
        /// <param name="texture"></param>
        /// <param name="speed"></param>
        /// <param name="lifespan_seconds"></param>
        public Reward(Vector2 position, Texture2D texture, float speed, float lifespan_seconds) : base(position, texture.Width, texture.Height)
        {
            this.lifespanSeconds = lifespan_seconds;
            this.tex             = texture;
            this.body            = new Rectangle((int)position.X, (int)position.Y, texture.Width, texture.Height);
            this.Position        = position;
            this.col             = Color.Red;

            MovementFactory mf = new StandardMovementFactory();

            StandardEntityFactory entity = new StandardEntityFactory();

            entity.CreateEnemy(EntityFactory.EntitiyType.Boss1);

            this.movement = mf.CreateMovement(MovementFactory.MovementType.Bounce, entity.CreateEnemy(EntityFactory.EntitiyType.Boss1));
        }
Beispiel #3
0
        /// <summary>
        /// Parse an entity entry and add to the wave.
        /// </summary>
        /// <param name="ef"></param>
        /// <param name="sf"></param>
        /// <param name="wave"></param>
        private static void ParseEntity(XmlNode entity, ref SpriteWave wave)
        {
            // Spawners for this entity
            List <BulletSpawner> new_spawners = null;
            // Factories
            StandardEntityFactory   ef = new StandardEntityFactory();
            StandardMovementFactory mf = new StandardMovementFactory();
            // Default Values
            int     timesec = 0, lifespan = 0, speed = 0, health = 1;
            Vector2 pos = Vector2.Zero;

            EntityFactory.EntitiyType    etype = EntityFactory.EntitiyType.Grunt1;
            MovementFactory.MovementType mtype = MovementFactory.MovementType.None;
            // Sprites
            Entity e = null;

            foreach (XmlNode att in entity.ChildNodes)
            {
                switch (att.Name)
                {
                case "timeseconds":
                    timesec = TypeTable.Get(att.Name, att.InnerText);
                    LogConsole.Log("Parse: Wave time seconds: " + timesec.ToString());
                    break;

                case "movement":
                    mtype = TypeTable.Get(att.Name, att.InnerText);
                    LogConsole.Log("Parse: Movement type: " + mtype.ToString());
                    break;

                case "lifespan":
                    lifespan = TypeTable.Get(att.Name, att.InnerText);
                    LogConsole.Log("Parse: Lifespan seconds: " + lifespan.ToString());
                    break;

                case "speed":
                    speed = TypeTable.Get(att.Name, att.InnerText);
                    LogConsole.Log("Parse: Speed: " + speed.ToString());
                    break;

                case "health":
                    health = TypeTable.Get(att.Name, att.InnerText);
                    LogConsole.Log("Parse: Health: " + health.ToString());
                    break;

                case "position":
                    pos = TypeTable.Get(att.Name, att.InnerText);
                    LogConsole.Log("Parse: Initial position: " + pos.ToString());
                    break;

                case "type":
                    etype = TypeTable.Get(att.Name, att.InnerText);
                    LogConsole.Log("Parse: Entity type: " + etype.ToString());
                    break;

                default:
                    break;
                }
            }
            e                 = ef.CreateEnemy(etype);
            e.Speed           = (uint)speed;
            e.LifeSpan        = (uint)lifespan;
            e.Health          = health;
            e.Position        = pos;
            e.WaveTimeSeconds = timesec;
            e.Movement        = mf.CreateMovement(mtype, e);
            wave.AddEntitiy(e);

            foreach (XmlNode att in entity.ChildNodes)
            {
                if (att.Name == "spawners")
                {
                    new_spawners = ParseSpawners(att, e);
                    break;
                }
            }
            foreach (BulletSpawner s in new_spawners)
            {
                wave.AddSpawner(s);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Parse the spawners attribute of a wave
        /// </summary>
        /// <param name="spawners"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        private static List <BulletSpawner> ParseSpawners(XmlNode spawners, Entity e)
        {
            List <BulletSpawner>    new_spawners = new List <BulletSpawner>();
            StandardSpawnerFactory  sf           = new StandardSpawnerFactory();
            StandardMovementFactory mf           = new StandardMovementFactory();

            SpawnerFactory.SpawnerType   stype         = SpawnerFactory.SpawnerType.None;
            MovementFactory.MovementType spawner_mtype = MovementFactory.MovementType.Mirror;
            SpawnerFactory.BulletType    btype         = SpawnerFactory.BulletType.Green;
            Movement      spawnermovement = null;
            double        firerate        = 1.0d;
            double        bulletspeed     = 7.0f;
            double        bulletlifespan  = 10.0f;
            int           timesec         = e.WaveTimeSeconds;
            BulletSpawner s = null;

            foreach (XmlNode att in spawners.ChildNodes)
            {
                LogConsole.Log(Environment.NewLine);
                foreach (XmlNode snode in att.ChildNodes)
                {
                    switch (snode.Name)
                    {
                    case "timeseconds":
                        timesec = TypeTable.Get(snode.Name, snode.InnerText);
                        LogConsole.Log("    Parse:Spawner: Wave time seconds: " + timesec.ToString());
                        break;

                    case "spawnertype":
                        stype = TypeTable.Get(snode.Name, snode.InnerText);
                        LogConsole.Log("    Parse:Spawner: Spawner type: " + stype.ToString());
                        break;

                    case "firerate":
                        firerate = TypeTable.Get(snode.Name, snode.InnerText);
                        LogConsole.Log("    Parse:Spawner: Firerate: " + firerate.ToString());
                        break;

                    case "bullettype":
                        btype = TypeTable.Get(snode.Name, snode.InnerText);
                        LogConsole.Log("    Parse:Spawner: Bullet type: " + btype.ToString());
                        break;

                    case "spawnermovement":
                        spawner_mtype = TypeTable.Get(snode.Name, snode.InnerText);
                        LogConsole.Log("    Parse:Spawner: Spawner movement type: " + spawner_mtype.ToString());
                        break;

                    case "bulletspeed":
                        bulletspeed = TypeTable.Get(snode.Name, snode.InnerText);
                        LogConsole.Log("    Parse:Spawner: Spawner bullet speed: " + bulletspeed.ToString());
                        break;

                    case "bulletlifespan":
                        bulletlifespan = TypeTable.Get(snode.Name, snode.InnerText);
                        LogConsole.Log("    Parse:Spawner: Spawner bullet lifespan: " + bulletlifespan.ToString());
                        break;
                    }
                }
                if (stype != SpawnerFactory.SpawnerType.None)
                {
                    s = sf.CreateSpawner(stype, e, btype);
                    s.BulletLifeSpan           = (float)bulletlifespan;
                    s.FireRateSeconds          = firerate;
                    s.BulletSpeed              = (float)bulletspeed;
                    s.WaveTimeSeconds          = timesec;
                    spawnermovement            = mf.CreateMovement(spawner_mtype, e);
                    spawnermovement.ThisSprite = s;
                    s.Movement = spawnermovement;
                    new_spawners.Add(s);
                }
            }
            return(new_spawners);
        }