Пример #1
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            elapsed += gameTime.ElapsedGameTime.TotalSeconds;

            win.Draw(gameTime);
            win.Text = deadEnemyNumber.ToString() + " ennemis tués";
            winLife.Draw(gameTime);
            winLife.Text = hero.Life.ToString() + " points de vie";
            winTime.Text = (Math.Max((int)(30 - elapsed),0)).ToString() + " secondes restantes";
            winTime.Draw(gameTime);

            if (hero.IsDead() || elapsed > 60)
            {
                hero.Die();
                System.Console.WriteLine("FINI! nombre d'ennemis tués : {0}", deadEnemyNumber);
            }

            // Reapparition enemies
            int nb_a_rajouter = 0;
            foreach (Enemy enemy in enemies.ToList())
            {
                if (enemy.IsDead())
                {
                    deadEnemyNumber++;
                    enemies.Remove(enemy);
                    Game.Components.Remove(enemy.Skin);
                    Game.Components.Remove(enemy);
                    nb_a_rajouter++;
                }
            }
            GenericEnemy enem;
            for (; nb_a_rajouter > 0; nb_a_rajouter--)
            {
                enem = new GenericEnemy(LuxGame, this, 500, 10, 10, null);
                enem.Position = new Vector2(400, 100);
                Sprite enemySkin = new Sprite(enem, new List<Texture2D>() { enemyTexture }, null);
                enem.Skin = enemySkin;
                enem.Skin.SetAnimation(enemyTexture.Name);
                enemies.Add(enem);
                Game.Components.Add(enem);
                Game.Components.Add(enemySkin);
                foreach (ShootsHero shooter in shootsHeros)
                {
                    if (shooter.Enemy.IsDead())
                    {
                        shooter.Associate(enem);
                    }
                }
            }

            // Gestion Heros -- Balles ennemies
            if (!hero.IsInvincible())
            {
                foreach (Shot badShot in badShots)
                {
                    if (Vector2.Distance(badShot.Position, hero.Position) < badShot.Hitbox + hero.HurtBox && !hero.IsInvincible())
                    {
                        hero.Hurt(badShot.Damage);
                        hero.InvincibleTimeSec = badShot.InvincibleTimeSec;
                        System.Console.WriteLine("Tu t'es fait frapper. Il te reste {0} points de vie.", hero.Life);

                        //TODO : Changer ça peut-être?
                        badShot.Position = new Vector2(-40, -40);
                        badShot.Speed = new Vector2(0, 0);
                        badShot.Accel = new Vector2(0, 0);
                    }
                }
            }

            // Gestion Ennemis -- Balles du heros
            foreach (Enemy enemy in enemies.ToList<Enemy>())
            {
                enemy.Update(gameTime);
                foreach (Shot goodShot in goodShots)
                {
                    if (Vector2.Distance(goodShot.Position, enemy.Position) < goodShot.Hitbox + enemy.HurtBox)
                    {
                        // L'ennemi a mal.
                        enemy.Hurt(goodShot.Damage);

                        // La balle disparait.
                        // TODO : Changer ça! Implémenter une méthode qui fasse disparaitre la balle!
                        goodShot.Position = new Vector2(-150, -150);
                        goodShot.Speed = new Vector2(0, 0);
                        goodShot.Accel = new Vector2(0, 0);
                    }
                }
            }

            // Gestion Ennemis -- Heros
            foreach (Enemy enemy in enemies)
            {
                // TODO : Trouver une hitbox pour le héros? Comment faire?
                if (Vector2.Distance(hero.Position, enemy.Position) < enemy.HurtBox + hero.HurtBox - 10)
                {
                    hero.Collide(enemy.GivenDamageCollision);
                    enemy.Collide(hero.GivenDamageCollision);
                    System.Console.WriteLine("Collision");
                }
            }

            //if (elapsed % 1 < 0.1)
            //{
            //    if (elapsed > 5)
            //    {
            //        shots.Check();
            //        elapsed = 0;
            //    }
            //    shots.Shoot(1,1,1,1,1,1,false,false,false);
            //    shots.Print();
            //}

            // Système de débug
            if (elapsed > 1000)
            {
                elapsed = 0;
                System.Console.WriteLine(hero.Position);
                System.Console.WriteLine(badShots.Count);
                System.Console.WriteLine(goodShots.Count);
                System.Console.WriteLine(enemies.Count);
                foreach (Shot badShot in badShots)
                {
                    System.Console.WriteLine(badShot.Position);
                }
                foreach (Shot goodShot in goodShots)
                {
                    System.Console.WriteLine(goodShot.Position);
                }
                foreach (Enemy enemy in enemies)
                {
                    System.Console.WriteLine(enemy.Position);
                }
            }
        }
Пример #2
0
        public override void Initialize()
        {
            enemyTexture = this.Content.Load<Texture2D>("commonEnemy");

            base.Initialize();
            Texture2D bullet2Texture = this.Content.Load<Texture2D>("bullet002-1");
            hero = new Hero(this.LuxGame, this, 100, 1, 1, 5, 2, null);
            Sprite heroSprite = new Sprite(hero, new List<String>() { "hero" });
            hero.Skin = heroSprite;
            hero.Position = new Vector2(400, 400);

            win = new MenuWindow(this, new Vector2(10, 10), deadEnemyNumber.ToString());
            winLife = new MenuWindow(this, new Vector2(640, 10), hero.Life.ToString());
            winTime = new MenuWindow(this, new Vector2(250, 10), ((int)(30 - elapsed)).ToString());

            ListePosition.Add(new Vector2(100, 100));
            ListePosition.Add(new Vector2(700, 100));
            ListePosition.Add(new Vector2(400, 100));

            ShotPool shots = new ShotPool(LuxGame, this, false, 0.2, 150, 150, 8, 4, bullet2Texture, null);

            for (int i = 0; i < 3; i++)
            {
                ShootsHero shooter = new ShootsHero(this.LuxGame, this, shots, null);
                Game.Components.Add(shooter);
                shootsHeros.Add(shooter);
            }

            GenericEnemy enem;
            for (int i = 0; i < 3; i++)
            {
                enem = new GenericEnemy(LuxGame, this, 500, 10, 10, null);
                Sprite enemySkin = new Sprite(enem, new List<Texture2D>() { enemyTexture }, null);
                enem.Skin = enemySkin;
                enem.Skin.SetAnimation(enemyTexture.Name);
                enem.Position = new Vector2(400, 100);
                enemies.Add(enem);
                Game.Components.Add(enem);
                Game.Components.Add(enemySkin);
                shootsHeros[i].Associate(enem);
            }
            Game.Components.Add(shots);
            Game.Components.Add(hero);
            Game.Components.Add(heroSprite);

            // Phase de test
            shots = new ShotPool(LuxGame, this);
            Game.Components.Add(shots);

            heroSprite.SetAnimation("hero");
        }
        public override void Initialize()
        {
            enemyTexture = this.Content.Load<Texture2D>("commonEnemy");

            base.Initialize();
            Texture2D bullet2Texture = this.Content.Load<Texture2D>("bullet002-1");
            hero = new Hero(this.LuxGame, this, 200, 1, 1, 5, 2, null);
            Sprite heroSprite = new Sprite(hero, new List<String>() { "hero" });
            hero.Skin = heroSprite;
            hero.Position = new Vector2(400, 400);

            ListePosition.Add(new Vector2(100, 100));
            ListePosition.Add(new Vector2(700, 100));
            ListePosition.Add(new Vector2(400, 100));

            ShotPool shots = new ShotPool(LuxGame, this, false, 0.2, 150, 150, 8, 4, bullet2Texture, null);

            GenericEnemy enem;
            for (int i = 0; i < 3; i++)
            {
                enem = new GenericEnemy(LuxGame, this, 500, 10, 10, null);
                Sprite enemySkin = new Sprite(enem, new List<Texture2D>() { enemyTexture }, null);
                enem.Skin = enemySkin;
                enem.Skin.SetAnimation(enemyTexture.Name);
                enem.Position = new Vector2(400, 100);
                enemies.Add(enem);
                Game.Components.Add(enem);
                Game.Components.Add(enemySkin);
            }
            foreach (Enemy enemy in enemies.ToList<Enemy>())
            {
                Game.Components.Add(new ShootsHero(this.LuxGame, this, shots, enemy));
            }
            Game.Components.Add(shots);
            Game.Components.Add(hero);
            Game.Components.Add(heroSprite);

            // Phase de test
            shots = new ShotPool(LuxGame, this);
            Game.Components.Add(shots);

            heroSprite.SetAnimation("hero");
        }