Ejemplo n.º 1
0
 public EnemySpawn(LineBatch lineBatch, Level level, Player player)
 {
     this.lineBatch = lineBatch;
     this.level = level;
     this.player = player;
     this.random = new Random();
     this.timer = new Timer(this.random.Next(SPIDER_MAX_DELAY));
     spiders = new List<Spider>();
     zombies = new List<Zombie>();
 }
Ejemplo n.º 2
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(graphics.GraphicsDevice);
            lineBatch = new LineBatch(graphics.GraphicsDevice);

            arialFont = Content.Load<SpriteFont>("Arial");

            level1 = new Level(lineBatch, "Level1");

            currentLevel = level1;

            player = new Player(lineBatch, currentLevel, Player.PLAYER_START);
            enemySpawn = new EnemySpawn(lineBatch, currentLevel, player);
        }
Ejemplo n.º 3
0
        public Player(LineBatch lineBatch, Level level, Vector2 position)
        {
            this.lineBatch = lineBatch;
            this.level = level;
            this.position = position;

            this.bow = new Bow(this.lineBatch, position + leftHand);

            this.yVelocity = 0;
            this.moveValue = 0;

            this.health = MAX_HEALTH;

            this.jumpDelay = new Timer(JUMP_DELAY);
        }
Ejemplo n.º 4
0
 public void OnGameStart()
 {
     _level = new Level(_input, _textureManager, _gameData);
     _gameTime = _gameData.CurrentLevel.Time;
 }
Ejemplo n.º 5
0
        public Zombie(LineBatch lineBatch, Level level, Player player, Color color, float speed, bool rightSide)
        {
            this.lineBatch = lineBatch;
            this.level = level;
            this.player = player;
            this.color = color;
            this.speed = speed;
            this.position = Vector2.UnitY * lineBatch.getView().Top + Vector2.UnitX * (rightSide ? -level.offset.X + lineBatch.getView().Right : -level.offset.X);
            this.faceRight = !rightSide;

            this.rightHand = new Vector2(28, -56);

            this.moveValue = 0;
        }
Ejemplo n.º 6
0
        public Spider(LineBatch lineBatch, Level level, Player player, Color color, float speed, float scale, bool rightSide)
        {
            this.lineBatch = lineBatch;
            this.level = level;
            this.player = player;
            this.color = color;
            this.speed = speed;
            this.scale = scale;
            this.position = Vector2.UnitY * lineBatch.getView().Top + Vector2.UnitX * (rightSide ? -level.offset.X +  lineBatch.getView().Right : -level.offset.X);

            this.moveValue = 0;
        }
Ejemplo n.º 7
0
        private void LoadGameLevel(int level)
        {
            XmlDocument xml = new XmlDocument();
            xml.Load("D:\\VS 2010 Projects\\Shooter\\Shooter\\ShooterContent\\Levels\\" + level.ToString() + ".xml");
            XmlNode root = xml.FirstChild;
            XmlNode waveNode;
            XmlNode formationNode;
            XmlNode enemyNode;
            XmlAttributeCollection attributes;

            Level = new Level();				//level contains list of waves
            Wave nextWave;						//wave contains list of formations
            Formation nextFormation;			//formation contains list of enemies
            Enemy nextEnemy;					//enemies will die horrible deaths
            AttackPattern nextAttackPattern;	//attackPattern defines enemy movement between start and end positions
            ShotPattern nextShotPattern;		//defines enemy bullets per shot and how those bullets move
            Texture2D shotImage;				//duh

            float waveDuration = 0;
            float formationTrigger = 0;

            string attackPatternID = "";	//name identifier for AttackPattern
            string shotPatternID = "";		//name identifier for ShotPattern
            string enemyType = "";			//tells which texture will be drawn for enemy
            string enemyShot = "";			//tells which texture will be drawn for enemy shot
            float enemyHealth = 0;			//duh
            float startX = 0;				//Start and End positions the enemy ship will use
            float startY = 0;
            float endX = 0;
            float endY = 0;
            int fireCount = 0;				//number of times the enemy will fire it's shotPattern
            float fireRate = 0;				//how frequently the enemy will fire another shotPattern
            int shotSpeed = 0;				//how fast each shot will move

            List<ShotPattern> shotPatterns;	//list of shotPatterns that will be passed to enemy
            int count = 0;					//counter for adding ShotPatterns

            if (root.HasChildNodes)
            {
                for (int i = 0; i < root.ChildNodes.Count; i++)	//waves
                {
                    waveNode = root.ChildNodes[i];
                    attributes = waveNode.Attributes;
                    waveDuration = Convert.ToSingle(attributes.GetNamedItem("d").Value);
                    nextWave = new Wave(waveDuration);	//Create new wave

                    if (waveNode.HasChildNodes)
                    {
                        for (int j = 0; j < waveNode.ChildNodes.Count; j++)	//formations
                        {
                            formationNode = waveNode.ChildNodes[j];
                            attributes = formationNode.Attributes;
                            formationTrigger = Convert.ToSingle(attributes.GetNamedItem("d").Value);

                            nextFormation = new Formation(formationTrigger);
                            if (formationNode.HasChildNodes)
                            {
                                for (int k = 0; k < formationNode.ChildNodes.Count; k++)	//enemies
                                {
                                    enemyNode = formationNode.ChildNodes[k];
                                    attributes = enemyNode.Attributes;
                                    enemyType = attributes.GetNamedItem("type").Value;
                                    enemyShot = attributes.GetNamedItem("shot").Value;
                                    try
                                    {
                                        enemyHealth = Convert.ToInt32(attributes.GetNamedItem("health").Value);
                                    }
                                    catch (FormatException e)
                                    {
                                        Console.WriteLine("Enemy Health: Input string is not a sequence of digits.");
                                    }
                                    catch (OverflowException e)
                                    {
                                        Console.WriteLine("Enemy Health: The number cannot fit in an Int32.");
                                    }

                                    try
                                    {
                                        startX = Convert.ToInt32(attributes.GetNamedItem("startX").Value);
                                    }
                                    catch (FormatException e)
                                    {
                                        Console.WriteLine("Enemy Starting X: Input string is not a sequence of digits.");
                                    }
                                    catch (OverflowException e)
                                    {
                                        Console.WriteLine("Enemy Starting X: The number cannot fit in an Int32.");
                                    }

                                    try
                                    {
                                        startY = Convert.ToInt32(attributes.GetNamedItem("startY").Value);
                                    }
                                    catch (FormatException e)
                                    {
                                        Console.WriteLine("Enemy Starting Y: Input string is not a sequence of digits.");
                                    }
                                    catch (OverflowException e)
                                    {
                                        Console.WriteLine("Enemy Starting Y: The number cannot fit in an Int32.");
                                    }

                                    try
                                    {
                                        endX = Convert.ToInt32(attributes.GetNamedItem("endX").Value);
                                    }
                                    catch (FormatException e)
                                    {
                                        Console.WriteLine("Enemy Starting X: Input string is not a sequence of digits.");
                                    }
                                    catch (OverflowException e)
                                    {
                                        Console.WriteLine("Enemy Starting X: The number cannot fit in an Int32.");
                                    }

                                    try
                                    {
                                        endY = Convert.ToInt32(attributes.GetNamedItem("endY").Value);
                                    }
                                    catch (FormatException e)
                                    {
                                        Console.WriteLine("Enemy Starting Y: Input string is not a sequence of digits.");
                                    }
                                    catch (OverflowException e)
                                    {
                                        Console.WriteLine("Enemy Starting Y: The number cannot fit in an Int32.");
                                    }

                                    try
                                    {
                                        shotSpeed = Convert.ToInt32(attributes.GetNamedItem("shotSpeed").Value);
                                    }
                                    catch (FormatException e)
                                    {
                                        Console.WriteLine("Enemy Shot Speed: Input string is not a sequence of digits.");
                                    }
                                    catch (OverflowException e)
                                    {
                                        Console.WriteLine("Enemy Shot Speed: The number cannot fit in an Int32.");
                                    }

                                    try
                                    {
                                        fireCount = Convert.ToInt32(attributes.GetNamedItem("fireCount").Value);
                                    }
                                    catch (FormatException e)
                                    {
                                        Console.WriteLine("Enemy Shot Freqency: Input string is not a sequence of digits.");
                                    }
                                    catch (OverflowException e)
                                    {
                                        Console.WriteLine("Enemy Shot Freqency: The number cannot fit in an Int32.");
                                    }

                                    try
                                    {
                                        fireRate = Convert.ToSingle(attributes.GetNamedItem("fireRate").Value);
                                    }
                                    catch (FormatException e)
                                    {
                                        Console.WriteLine("Enemy Shot Freqency: Input string is not a sequence of digits.");
                                    }
                                    catch (OverflowException e)
                                    {
                                        Console.WriteLine("Enemy Shot Freqency: The number cannot fit in a float.");
                                    }

                                    //enemy attack pattern
                                    nextAttackPattern = new AttackPattern();
                                    attackPatternID = attributes.GetNamedItem("ap").Value;
                                    nextAttackPattern.SetID(attackPatternID);
                                    nextAttackPattern.SetEndPosition(endX, endY);
                                    nextAttackPattern.SetStartPosition(startX, startY);

                                    if ((nextAttackPattern = PopulateAttackPattern(nextAttackPattern)) == null)			//Load AttackPattern moveList
                                    {
                                        Console.WriteLine("Failed to load attack pattern " + attackPatternID.ToString());
                                    }

                                    //enemy shot pattern

                                    shotPatternID = attributes.GetNamedItem("sp").Value;
                                    shotPatterns = new List<ShotPattern>();		//only one shotPattern List per enemy, so new outside while loop
                                    count = 0;
                                    while (count < fireCount)
                                    {
                                        nextShotPattern = new ShotPattern(shotPatternID, shotSpeed);		//we potentially want multiple ShotPattern objects per enemy, so new in while loop
                                        shotImage = this.Content.Load<Texture2D>(enemyShot);

                                        //Create the appropriate number of shotPatterns for the enemy

                                        if ((nextShotPattern = PopulateShotPattern(nextShotPattern, shotImage)) == null)			//populate ShotPattern's shotList
                                        {
                                            Console.WriteLine("Failed to load shot pattern " + shotPatternID.ToString());
                                        }
                                        shotPatterns.Add(nextShotPattern);
                                        count++;
                                    }

                                    //ContentManager should only load textures if they aren't already cached
                                    nextEnemy = new Enemy(this.Content.Load<Texture2D>(enemyType), Convert.ToInt32(enemyHealth), nextAttackPattern, shotPatterns, fireCount, fireRate);
                                    LevelEnemies.Add(nextEnemy);
                                    nextFormation.AddEnemy(nextEnemy);
                                }

                                nextWave.AddFormation(nextFormation);
                            }
                            else
                            {
                                Console.WriteLine("Empty formation found");
                            }
                        }

                        Level.AddWave(nextWave);
                    }
                    else
                    {
                        Console.WriteLine("Empty wave found");
                    }
                }
            }
            else
            {
                Console.WriteLine("root node: no children found");
            }
        }
Ejemplo n.º 8
0
 void changeLevel(Level level)
 {
     currentLevel = level;
     player = new Player(lineBatch, currentLevel, Player.PLAYER_START);
     enemySpawn = new EnemySpawn(lineBatch, currentLevel, player);
 }