Ejemplo n.º 1
0
 // get all map info to spawn monster and human
 public void SpawnCreatures()
 {
     for (int i = 0; i < GameSettings.GetInstance().MAP_TILE_ROW_COUNT; ++i)
     {
         for (int j = 0; j < GameSettings.GetInstance().MAP_TILE_COLUMN_COUNT; ++j)
         {
             if (collision_map_[i, j] == NodeType.mountain)
             {
                 if (GameSettings.GetInstance().MONSTER_SPAWN_CHANCE >= Random.Range(0, 100))
                 {
                     GameActor monster = GameActor.Create("Entity_Monster");
                     scene_game_.AddEntity(monster);
                     NavigationMap.GetInstance().RegisterActor(monster);
                     monster.transform.localPosition = new Vector3(GameSettings.GetInstance().TILE_SIZE *j, GameSettings.GetInstance().TILE_SIZE *i);
                     monster.transform.localScale    = new Vector3(1, 1, 1);
                 }
             }
             else if (collision_map_[i, j] == NodeType.grass)
             {
                 if (GameSettings.GetInstance().HUMAN_SPAWN_CHANCE >= Random.Range(0, 100))
                 {
                     GameActor human = GameActor.Create(GameSettings.GetInstance().HUMAN_PREFAB_NAME);
                     scene_game_.AddEntity(human);
                     NavigationMap.GetInstance().RegisterActor(human);
                     human.transform.localPosition = new Vector3(GameSettings.GetInstance().TILE_SIZE *j, GameSettings.GetInstance().TILE_SIZE *i);
                     human.transform.localScale    = new Vector3(1, 1, 1);
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
    protected override void _Updater(float deltaTime)
    {
        if (is_game_ended_)
        {
            return;
        }

        NavigationMap.GetInstance().OnUpdate();

        if (!navigation_map_inited_)
        {
            // get all map info to spawn monster and human
            NavigationMap.GetInstance().SpawnCreatures();
            navigation_map_inited_ = true;
        }

        base._Updater(deltaTime);

        if (IsAllActionDone())
        {
            wait_time_ = GameSettings.GetInstance().ACTION_INTERVAL;
//			DamageCharacterInWater ();
            NextTurn();
        }

        if (game_end_count_down_ > 0)
        {
            game_end_count_down_ -= deltaTime;
            if (game_end_count_down_ <= 0)
            {
                is_game_ended_ = true;
                switch (game_end_reason_)
                {
                case GameEndReason.human_rulz:

                    result_human_win.active = true;

                    break;

                case GameEndReason.monster_rulz:

                    result_monster_win.active = true;

                    break;

                case GameEndReason.time_out:
                    break;
                }
                audio_win_.Play();
                game_end_text_.text = "Score : " + CalculateScore();
                return;
            }
        }
        else
        {
            CheckIfGameEnd();
        }

        if (wait_time_ > 0)
        {
            wait_time_ -= Time.deltaTime;
        }
        else
        {
            NavigationMap.GetInstance().RefreshAll();
            // human first
            HumanDoAction();
            MonsterDoAction();
            wait_time_ = GameSettings.GetInstance().ACTION_INTERVAL;

            if (is_dino_die_sound_play_)
            {
                if (!audio_dino_die_.isPlaying)
                {
                    audio_dino_die_.Play();
                }
            }
            else if (is_human_die_sound_play_)
            {
                if (!audio_human_die_.isPlaying)
                {
                    audio_human_die_.Play();
                }
            }
            is_dino_die_sound_play_  = false;
            is_human_die_sound_play_ = false;
        }

        ActorSpawner target_spawner = null;

        for (int i = 0; i < actor_spawners_.Count; ++i)
        {
            target_spawner = actor_spawners_[i];

            GameActor actor;
            if (target_spawner.type == ActorType.human)
            {
                actor = GameActor.Create(GameSettings.GetInstance().HUMAN_PREFAB_NAME);
                ++GameStatics.human_spawned;
            }
            else
            {
                actor = GameActor.Create(GameSettings.GetInstance().MONSTER_PREFAB_NAME);
                ++GameStatics.monster_spawned;
            }
            AddEntity(actor);
            actor.transform.localPosition = new Vector3(target_spawner.column * GameSettings.GetInstance().TILE_SIZE,
                                                        target_spawner.row * GameSettings.GetInstance().TILE_SIZE,
                                                        0);
            NavigationMap.GetInstance().RegisterActor(actor);
        }
        actor_spawners_.Clear();
    }