Exemplo n.º 1
0
        public void createEnemy(Texture2D imageName, int left, int top, int health = 1)
        {
            EnemySprite enemy = new EnemySprite(imageName, this.game);

            enemy.Position = new Vector2(left, top);

            enemy.StartPosition = enemy.Position;
            enemy.Health        = health;
            this.enemies.Add(enemy);
            this.game.Components.Add(enemy);
        }
        private bool isPlayerStupid()
        {
            //TESTING AREA
            for (int i = 0; i < this.Game.EnemyConductor.enemyList.Count; ++i)
            {
                EnemySprite enemy = this.Game.EnemyConductor.enemyList[i];

                if (this.Game.Ship.Position.X > enemy.Position.X && this.Game.Ship.Position.X < (enemy.Position.X + enemy.Texture.Width))
                {
                    if (this.Game.Ship.Position.Y > enemy.Position.Y && this.Game.Ship.Position.Y < (enemy.Position.Y + enemy.Texture.Height))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
        private bool checkForBulletHit(bool friendBullet)
        {
            if (friendBullet)
            {
                for (int i = 0; i < this.Game.EnemyConductor.enemyList.Count; ++i)
                {
                    EnemySprite enemy = this.Game.EnemyConductor.enemyList[i];

                    if (this.Position.X > enemy.Position.X && this.Position.X < (enemy.Position.X + enemy.Texture.Width))
                    {
                        if (this.Position.Y > enemy.Position.Y && this.Position.Y < (enemy.Position.Y + enemy.Texture.Height))
                        {
                            //Take 1 health from enemy
                            this.Game.EnemyConductor.enemyList[i].Health -= 1;

                            //check if it is dead or not
                            if (this.Game.EnemyConductor.enemyList[i].Health == 0)
                            {
                                this.Game.EnemyConductor.enemyList.RemoveAt(i);
                                this.Game.Components.Remove(enemy);
                                return(true);
                            }
                            else if (this.Game.EnemyConductor.enemyList[i].Health != 0)
                            {
                                this.Game.Components.Remove(this);
                            }
                        }
                    }
                }
            }
            else
            {
                if (this.Position.X + length > this.Game.Ship.Position.X && this.Position.X < (this.Game.Ship.Position.X + this.Game.Ship.Texture.Width))
                {
                    if (this.Position.Y > this.Game.Ship.Position.Y && this.Position.Y < (this.Game.Ship.Position.Y + this.Game.Ship.Texture.Height))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }