Example #1
0
        public bool UpdateEnemy(Hero hero, WallSet wall)
        {
            if (CurrentState != EnemyState.Bunny)
            {
                DetectHero(hero);
                Vector2 toTarget     = TargetPosition - Center;
                float   distToTarget = toTarget.Length();
                toTarget.Normalize();

                if (CurrentState == EnemyState.Chaser)
                {
                    ChaserCount--;
                    if (UpdateEnemyChaseState(hero, distToTarget))
                    {
                        return(true);
                    }
                }

                else if (CurrentState == EnemyState.Patrol)
                {
                    UpdateEnemyPatrolState(wall);
                }

                if (ChaserCount == 0 && distToTarget > kDistToBeginChase)
                {
                    CurrentState = EnemyState.Patrol;
                    ChaserCount  = 500;
                }
            }

            if (lives > initialLives)
            {
                initialLives = lives;
            }
            health.Update(this.Center, lives, initialLives);

            return(false);
        }
Example #2
0
        public bool Update(Hero hero, Wand w)
        {
            heroHit = false;
            health.Update(new Vector2(this.Center.X, this.Center.Y + 1), healthRemaining, initialLives);

            if (current == wizardStatus.isAlive)
            {
                if (shieldCoolDown < 0 && !shielded)
                {
                    shielded       = true;
                    shieldCoolDown = 100;
                }
                else
                {
                    shieldCoolDown--;
                }

                if (shieldCoolDown < 0 && shielded)
                {
                    shielded       = false;
                    shieldCoolDown = 100;
                }


                if (shielded)
                {
                    Texture = "wizardShield";
                }
                else
                {
                    Texture = "wizardRight";
                    if (coolDown < 0)
                    {
                        coolDown = 40;
                        shoot(hero.Center);
                    }
                    else
                    {
                        coolDown--;
                    }
                }

                for (int i = 0; i < list.Count; i++)
                {
                    shot temp = list[i];
                    if (list[i].shotLife == 0)
                    {
                        list[i].bullet.RemoveFromAutoDrawSet();
                        list[i].emitter.RemoveFromAutoDrawSet();
                        list.Remove(list[i]);
                    }
                    else
                    {
                        temp.shotLife--;
                        if (hero.Collided(temp.bullet) && !temp.hit)
                        {
                            hero.Caught();
                            hero.Center = hero.HeroInitialPos;
                            temp.hit    = true;
                            heroHit     = true;
                        }
                        list[i] = temp;
                        list[i].emitter.Center = list[i].bullet.Center;
                    }
                }
                for (int i = 0; i < w.list.Count; i++)
                {
                    if (w.list[i].bullet.Collided(this))
                    {
                        if (!shielded)
                        {
                            healthRemaining--;
                        }
                        else
                        {
                            Random r = new Random();
                            if (r.Next(0, 100) < 10)
                            {
                                healthRemaining--;
                            }
                        }
                    }
                }

                if (healthRemaining <= 0)
                {
                    current = wizardStatus.isDead;
                    Texture = "Newteddybear";
                    XNACS1Base.PlayACue("Bear-Sound");

                    return(true);
                }

                if (this.Center.X - hero.Center.X > 0)
                {
                    Texture = shielded ? "wizardShieldLeft" : "wizardLeft";
                }
                else
                {
                    Texture = shielded ? "wizardShield" : "wizardRight";
                }
            }

            if (current == wizardStatus.isDead)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    list[i].bullet.RemoveFromAutoDrawSet();
                    list[i].emitter.RemoveFromAutoDrawSet();
                    list.Remove(list[i]);
                }
            }
            return(false);
        }