Exemplo n.º 1
0
 protected void enemyEnter(EnemyEntity ent, float distance)
 {
     Rotation =
         MathHelper.directionFromPointToPoint(this.Location,
                                              ent.Location);
     if (distance <= this.ActiveWeapon.AttackRadius)
     {
         this.State = EntityState.ATTACKING;
     }
     else
     {
         this.Target = WumpusTarget.ENEMY;
         this.State  = EntityState.MOVING;
     }
 }
Exemplo n.º 2
0
            private static EnemyEntity pickClosestOne(Dictionary <EnemyEntity, float> friends)
            {
                EnemyEntity closest = null;

                foreach (EnemyEntity ent in friends.Keys)
                {
                    if (closest == null)
                    {
                        closest = ent;
                    }
                    if (friends[ent] < friends[closest])
                    {
                        closest = ent;
                    }
                }
                return(closest);
            }
Exemplo n.º 3
0
            public enum AlgorythmType { BOX, CIRCLE } // other types could be added

            public static void checkForCreatures(EnemyEntity caller, AlgorythmType algo)
            {
                var dynms = caller.ParentWorld.getAllEnemyEntities();

                Dictionary <EnemyEntity, float>   friends = new Dictionary <EnemyEntity, float>();
                Dictionary <DynamicEntity, float> enemies = new Dictionary <DynamicEntity, float>();

                lonely++;
                if (lonely >= 10)
                {
                    Console.WriteLine(caller.Type.ToString() + " is lonely! ");
                    caller.SightRadius += 25;
                }

                for (int i = dynms.Count - 1; i >= 0; i--)
                {
                    if (dynms[i] == caller)
                    {
                        continue;
                    }
                    if (dynms[i].State == EntityState.DEAD)
                    {
                        continue;
                    }

                    var dist = MathHelper.distanceFromPointToPoint(
                        caller.Location, dynms[i].Location);
                    if (dist <= caller.SightRadius)
                    {
                        if (caller.Type == dynms[i].Type)
                        {
                            friends.Add((EnemyEntity)dynms[i], dist);
                        }
                        else
                        {
                            enemies.Add(dynms[i], dist);
                        }
                    }
                }

                if (enemies.Count > 0)
                {
                    lonely = 0;
                    var enemy = pickClosestOne(enemies);
                    if (enemy.Class == EntityClass.PLAYER)
                    {
                        caller.playerEnter((PlayerEntity)enemy, MathHelper.distanceFromPointToPoint(
                                               caller.Location, enemy.Location));
                    }
                    else if (enemy.Class == EntityClass.WUMPUS)
                    {
                        caller.enemyEnter((EnemyEntity)enemy, MathHelper.distanceFromPointToPoint(
                                              caller.Location, enemy.Location));
                    }
                }
                else if (friends.Count > 0)
                {
                    var friend = pickClosestOne(friends);
                    caller.friendEnter(friend,
                                       MathHelper.distanceFromPointToPoint(
                                           caller.Location, friend.Location));
                }
            }