Exemplo n.º 1
0
        void act(Enemy monster, actionDecision action)
        {
            switch (action)
            {
            case actionDecision.FLEE:
                flee(monster);
                break;

            case actionDecision.ALIGN:
                align(monster);
                break;

            case actionDecision.ADVANCE:
                advance(monster);
                break;

            case actionDecision.EVADE:
                evade(monster);
                break;

            case actionDecision.FIRE:
                fire(monster);
                break;

            case actionDecision.IDLE:
                idle(monster);
                break;
            }
        }
        public void Update(int elapsed_time) // detect if explosion needs to be drawn, determine what the monster needs to do, handle dead monsters
        {
            for (int i = 0; i < monsters.Count(); ++i)
            {
                Enemy monster      = monsters.ElementAt(i);
                bool  mons_removed = false;

                if (monster.getHealth() <= 0)
                {
                    game_state.monster_engine.Remove(monster);
                    mons_removed = true;
                    game_state.fx_engine.RequestExplosion(explosionType.SMALL, monster.getX() + (monster.getWidth() / 2), monster.getY() + (monster.getHeight() / 2));
                    game_state.fx_engine.RequestSound(soundType.ENEMY_DIE);
                }
                if (mons_removed == false)
                {
                    if (IsVisible(monster))
                    {
                        move_towards_target(monster);

                        if (monster.next_think_time >= 2000) //TIME DELAY
                        {
                            actionDecision action = think(monster);
                            act(monster, action);
                            monster.next_think_time = 0;
                        }
                        else
                        {
                            monster.next_think_time += elapsed_time;
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        //Two basic functions for the Monster engine
        actionDecision think(Enemy monster)
        {
            float[] ratings = new float[(int)actionDecision.NUM_ACTIONS];
            int     dist_x  = game_state.local_player.getX() - monster.getX();
            int     dist_y  = game_state.local_player.getY() - monster.getY();

            int Dp  = GetRating(Math.Sqrt(Math.Pow(dist_x, 2) + Math.Pow(dist_y, 2)), 800.0f);
            int Db  = 0; //Bullet system not in yet
            int Alg = 0;

            if (Math.Abs(dist_x) < Math.Abs(dist_y))
            {
                Alg = GetRating(Math.Abs(dist_x), 400);
            }
            else
            {
                Alg = GetRating(Math.Abs(dist_y), 240);
            }

            int Hlt = GetRating(monster.getHealth(), monster.getMaxHealth());

            actionDecision retval    = actionDecision.FLEE;
            float          max_value = 0;

            for (int i = 0; i < (int)actionDecision.NUM_ACTIONS; ++i)
            {
                ratings[i] =
                    decision_matrix[(int)monster.getType(), i, (int)actionFactor.DP] * Dp +
                    decision_matrix[(int)monster.getType(), i, (int)actionFactor.DB] * Db +
                    decision_matrix[(int)monster.getType(), i, (int)actionFactor.AL] * Alg +
                    decision_matrix[(int)monster.getType(), i, (int)actionFactor.HL] * Hlt;

                if (ratings[i] > max_value)
                {
                    retval    = (actionDecision)i;
                    max_value = ratings[i];
                }
            }

            if (max_value < 5)
            {
                return(actionDecision.IDLE);
            }
            return(retval);
        }
Exemplo n.º 4
0
        public void Update(int elapsed_time)
        {
            for (int i = 0; i < monsters.Count(); ++i)
            {
                Enemy monster      = monsters.ElementAt(i);
                bool  mons_removed = false;

                /*
                 * if (monster.col_tok.HasCollisions())//&& monster.col_tok.GetHitType() == ColType.BULLET)
                 * {
                 *
                 *  List<ColToken> cols = monster.col_tok.GetCollisions();
                 *  for (int j = 0; j < cols.Count(); ++j)
                 *  {
                 *      if (cols.ElementAt(j).GetLocalType() == ColType.BULLET )
                 *      {
                 *          //MAGIC NUMBER
                 *          Bullet bull = (Bullet)cols.ElementAt(j).GetParent();
                 *          int damage = 0;
                 *          switch (bull.type)
                 *          {
                 *              case bulletType.SMALL:
                 *                  damage = 5;
                 *                  break;
                 *              case bulletType.SWORD:
                 *                  damage = 10;
                 *                  break;
                 *
                 *          }
                 *          monster.setHealth(monster.getHealth() - (game_state.local_player.getAttackBonus()+damage));
                 *          //dmg_sound.Play();
                 *          if (monster.getHealth() <= 0)
                 *          {
                 *              game_state.monster_engine.Remove(monster);
                 *              mons_removed = true;
                 *              game_state.fx_engine.RequestExplosion(explosionType.SMALL, monster.getX()+(monster.getWidth()/2), monster.getY()+(monster.getHeight()/2));
                 *          }
                 *          game_state.fx_engine.RequestSound(soundType.HURT);
                 *      }
                 *      else if (cols.ElementAt(j).GetLocalType() == ColType.MAP)
                 *      {
                 *          //monster.revertX();
                 *          //monster.revertY();
                 *      }
                 *  }
                 *
                 *  monster.col_tok.ResetCollisions();
                 * }
                 * */
                if (monster.getHealth() <= 0)
                {
                    game_state.monster_engine.Remove(monster);
                    mons_removed = true;
                    game_state.fx_engine.RequestExplosion(explosionType.SMALL, monster.getX() + (monster.getWidth() / 2), monster.getY() + (monster.getHeight() / 2));
                }
                if (mons_removed == false)
                {
                    if (IsVisible(monster))
                    {
                        move_towards_target(monster);

                        if (monster.next_think_time >= 2000) //TIME DELAY
                        {
                            actionDecision action = think(monster);
                            act(monster, action);
                            monster.next_think_time = 0;
                        }
                        else
                        {
                            monster.next_think_time += elapsed_time;
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        void act(Enemy monster, actionDecision action)
        {
            switch (action)
            {
                case actionDecision.FLEE:
                    flee(monster);
                    break;
                case actionDecision.ALIGN:
                    align(monster);
                    break;
                case actionDecision.ADVANCE:
                    advance(monster);
                    break;
                case actionDecision.EVADE:
                    evade(monster);
                    break;
                case actionDecision.FIRE:
                    fire(monster);
                    break;
                case actionDecision.IDLE:
                    idle(monster);
                    break;

            }
        }