Ejemplo n.º 1
0
        private void CreateMonsters(int width, int height)
        {
            for (int i = 0; i < 10; i++)
            {   // orcs...
                Mob orc = new Mob("orc", new Vector(rand.Next(0, width), rand.Next(0, height)),
                                  animations["orcNone"], animations["orcMove"], animations["orcMelee"], null,
                                  MobType.Orc, new Vector(rand.Next(0, width), rand.Next(0, height)), 15, 10, 5, 3, 350);
                orc.MeleeCombatEnded += m_MeleeCombatEnded;
                orc.Died             += m_Died;
                Claw claw = new Claw("troll claw", new Vector(0, 0), null, 12);
                orc.Inventory.Add(claw);
                orc.EquippedWeapon = claw;
                monsters.Add(orc);
            }
            for (int i = 0; i < 10; i++)
            {   // 2-headed trolls...
                Mob troll = new Mob("troll", new Vector(rand.Next(0, width), rand.Next(0, height)),
                                    animations["trollNone"], animations["trollMove"], animations["trollMelee"], null,
                                    MobType.Troll, new Vector(rand.Next(0, width), rand.Next(0, height)), 25, 12, 8, 4, 250);
                troll.MeleeCombatEnded += m_MeleeCombatEnded;
                troll.Died             += m_Died;
                Claw claw = new Claw("troll claw", new Vector(0, 0), null, 12);
                troll.Inventory.Add(claw);
                troll.EquippedWeapon = claw;
                monsters.Add(troll);
            }

            for (int i = 0; i < 10; i++)
            {   // zombies...
                Mob zombie = new Mob("zombie" + i.ToString(), new Vector(rand.Next(0, width), rand.Next(0, height)),
                                     animations["zombieNone"], animations["zombieMove"], animations["zombieMelee"], null, MobType.Zombie,
                                     new Vector(rand.Next(0, width), rand.Next(0, height)), 10, 12, 4, 2, 150);
                zombie.MeleeCombatEnded += m_MeleeCombatEnded;
                zombie.Died             += m_Died;
                Claw claw = new Claw("zombie claw", new Vector(0, 0), null, 10);
                zombie.Inventory.Add(claw);
                zombie.EquippedWeapon = claw;
                monsters.Add(zombie);
            }
            for (int i = 0; i < 2; i++)
            {   // dragons...
                Projectile proj;
                Mob        dragon;
                if (i % 2 == 0)
                {
                    proj = new Projectile("fireball", new Vector(), animations["fire"],
                                          new Vector(), 2000, true, 100, null);
                    dragon = new Mob("redDragon", new Vector(rand.Next(0, width), rand.Next(0, height)),
                                     animations["dragonNone"], animations["dragonMove"], null, animations["dragonRanged"], MobType.Dragon,
                                     new Vector(rand.Next(0, width), rand.Next(0, height)),
                                     200, 25, 20, 4, 400);
                }
                else
                {
                    proj = new Projectile("iceball", new Vector(), animations["ice"],
                                          new Vector(), 2000, true, 100, null);
                    dragon = new Mob("greenDragon", new Vector(rand.Next(0, width), rand.Next(0, height)),
                                     animations["gDragonNone"], animations["gDragonMove"], null, animations["gDragonRanged"], MobType.Dragon,
                                     new Vector(rand.Next(0, width), rand.Next(0, height)),
                                     200, 25, 20, 6, 400);
                }
                BreathWeapon bw = new BreathWeapon("breath", new Vector(), null, 0, 0, 2000, 15, proj);
                dragon.Inventory.Add(bw);
                dragon.EquippedWeapon     = bw;
                dragon.RangedCombatEnded += mob_RangedCombatEnded;
                dragon.Died += m_Died;
                monsters.Add(dragon);
            }
        }
Ejemplo n.º 2
0
        public MobAction React(double time)
        {
            // only allow an Action if NOT currently committed to another action...
            if (action != MobAction.Melee && action != MobAction.Ranged &&
                action != MobAction.Spell)
            {
                Mob target = CheckForTarget();
                if (target != null && Type != MobType.Human)
                {
                    // we found an enemy, so see if we can attack from current position...
                    Vector pointing = target.Position - Position;
                    double dist     = pointing.Magnitude;
                    Weapon bestWpn  = FindBestWeapon(dist);
                    if (bestWpn != null)
                    {                           // found a weapon that can attack  immediately...
                        Vector unit = pointing.Unitized;
                        Velocity = 0.01 * unit; // make sure to face the enemy before attacking
                        if (bestWpn.Type == WeaponType.Melee)
                        {
                            Action = MobAction.Melee;
                        }
                        else if (bestWpn.Type == WeaponType.Ranged)
                        {
                            Action = MobAction.Ranged;
                        }
                        else
                        {
                            Action = MobAction.Spell;
                        }
                    }
                    else
                    {     // no current weapon, so move TOWARD enemy instead...
                        if (dist < 10)
                        { // we are next to enemy already, so stay put
                            Action = MobAction.None;
                        }
                        else
                        {   // move toward the enemy...
                            Goal = target.Position;
                            Vector unit = pointing.Unitized;
                            Velocity = Speed * unit;
                            Action   = MobAction.Move;
                        }
                    }
                }
                else
                {// NO target around us, so now what to do?
                    Vector pointing = Home - Position;
                    double dist     = pointing.Magnitude;
                    if (dist < 10)
                    {   // already at my Goal, so nothing to do...
                        Action = MobAction.None;
                    }
                    else
                    {   // NOT near my Goal, so head toward it now...
                        Vector unit = pointing.Unitized;
                        Velocity = Speed * unit;
                        Action   = MobAction.Move;
                    }
                }
            }

            if (action == MobAction.Move)
            {   // if we decide to Move, then call our Move() function now...
                Move(time);
            }
            return(action);
        }
Ejemplo n.º 3
0
 public abstract Projectile Launch(Vector pos, Vector vel, Mob originator);