protected virtual void RefreshForNewWorld() { if (GetComponent <iTween>()) { ServiceLocator.GetDebugProvider().Log("remove itween"); Destroy(GetComponent <iTween>()); } Cell newCell = GridHolder.GetRandomWalkableCell(); newCell.walkable = false; pos.x = newCell.GetX(); pos.y = newCell.GetY(); this.transform.position = new Vector3(pos.x, 0, pos.y); }
private void ChangeMode(Modes newMode) { currentMode = newMode; flame.ChangeMode(currentMode); switch (currentMode) { case Modes.Search: animator.SetBool("FoundPlayer", false); animator.SetBool("Moving", true); newSearchPointTimer = ruleSet.MONSTER_SEARCH_TIMER.GetRandomValue(); searchCell = GridHolder.GetRandomWalkableCell(); timeBetweenSteps = ruleSet.MONSTER_MOVEMENT_TICK_SEARCH; break; case Modes.Hunt: animator.SetBool("FoundPlayer", true); animator.SetBool("Moving", true); ServiceLocator.GetAudioProvider().PlaySoundEvent("Inhale"); timeBetweenSteps = ruleSet.MONSTER_MOVEMENT_TICK_HUNT; timeSinceSpotted = 0; break; case Modes.Happy: animator.SetBool("FoundPlayer", true); animator.SetBool("Moving", false); timeBetweenSteps = int.MaxValue; happyTimer = ruleSet.MONSTER_WAIT_TIME; lastKnownCell = null; searchCell = null; break; case Modes.Dead: animator.SetBool("FoundPlayer", false); animator.SetBool("Moving", false); timeBetweenSteps = int.MaxValue; if (GetComponent <iTween>()) { ServiceLocator.GetDebugProvider().Log("remove itween"); Destroy(GetComponent <iTween>()); } Instantiate(Resources.Load <GameObject>("Prefabs/Poof/Poof"), this.transform.position, Quaternion.identity); this.transform.position = Vector3.one * 5000; break; } }
private void Start() { jump = GetComponentInChildren <Jump>(); animator = GetComponentInChildren <Animator>(); animator.SetTrigger("Idle"); prevPos = transform.position; curPos = prevPos; lightChecker = GetComponent <InLightChecker>(); InputManager.INSTANCE.DirectionInput += MoveAlongDirection; Cell randomStartPosition = GridHolder.GetRandomWalkableCell(); pos.x = randomStartPosition.pos.x; pos.y = randomStartPosition.pos.y; if (GameManager.INSTANCE.GetGameState() == GameManager.GameState.gameFinish) { //new pos this.transform.position = startPosition; } else { //new pos this.transform.position = new Vector3(pos.x, 0, pos.y); } hp = new Health(); hp.myUnit = this; hp.SetMaxHealth(ruleSet.PLAYER_HEALTH); hp.SetCurrentHealth(ruleSet.PLAYER_HEALTH); hp.IsDead += GameManager.INSTANCE.GameOver; hp.IsDead += SavePlayerPos; healthSlider = GameObject.FindWithTag("HealthSlider").GetComponent <Slider>(); healthSlider.maxValue = hp.GetMaxHealth(); healthSlider.minValue = 0; healthSlider.value = hp.GetCurrentHealth(); hp.HpChanged += UpdateHealthSlider; GameManager.INSTANCE.NewWorldCreated += RefreshForNewWorld; }
void Start() { animator = GetComponentInChildren <Animator>(); light = GetComponentInChildren <MonsterLight>(); flame = GetComponentInChildren <MonsterFlame>(); Cell randomStartPosition = GridHolder.GetRandomWalkableCell(); pos.x = randomStartPosition.pos.x; pos.y = randomStartPosition.pos.y; // pos.x = 5; // pos.y = 5; if (GameManager.INSTANCE.GetGameState() == GameManager.GameState.gameFinish) { //player previous pos monsterGrowth = ruleSet.MONSTER_GROWTH_FACTOR; this.transform.position = startPosition; } else { //new pos monsterGrowth = 0; this.transform.position = new Vector3(pos.x, 0, pos.y); } moveTimer = 3f; player = GameObject.FindWithTag("Player").GetComponent <Player>(); actionWait = ruleSet.MONSTER_MOVEMENT_TICK_SEARCH - monsterGrowth; hp = new Health(); hp.SetMaxHealth(ruleSet.MONSTER_HEALTH + monsterGrowth); hp.SetCurrentHealth(ruleSet.MONSTER_HEALTH + monsterGrowth); hp.IsDead += GameManager.INSTANCE.GameFinished; hp.IsDead += GetPlayerPosition; GridHolder.BranchSnap += TargetSteppedOnBranch; GameManager.INSTANCE.NewWorldCreated += RefreshForNewWorld; ChangeMode(Modes.Search); }
void Update() { if (GameManager.INSTANCE.GetGameState() == GameManager.GameState.pause) { return; } if (GameManager.INSTANCE.GetGameState() == GameManager.GameState.gameOver) { return; } if (GameManager.INSTANCE.GetGameState() == GameManager.GameState.gameFinish) { return; } if (currentMode == Modes.Dead) { return; } light.UpdateColor(hp.GetCurrentHealth(), hp.GetMaxHealth()); hp.TakeDamage(ruleSet.MONSTER_HEALTH_LOSS_RATE * Time.deltaTime); if (hp.GetCurrentHealth() <= 0 && currentMode != Modes.Dead) { ChangeMode(Modes.Dead); } if (currentMode == Modes.Dead) { return; } switch (currentMode) { case Modes.Search: if (LookForPlayer() != null) { ChangeMode(Modes.Hunt); moveTimer = 0.25f; return; } newSearchPointTimer -= Time.deltaTime; if (newSearchPointTimer <= 0) { newSearchPointTimer = ruleSet.MONSTER_SEARCH_TIMER.GetRandomValue(); searchCell = GridHolder.GetRandomWalkableCell(); } moveTimer -= Time.deltaTime; if (moveTimer <= 0) { moveTimer = timeBetweenSteps; Direction direction = Pathfinding.GetNextStepDirection(this.pos.GetAsVector3Int(), searchCell.pos.GetAsVector3Int()); if (direction != Direction.NONE) { MoveAlongDirection(direction, ruleSet.MONSTER_MOVEMENT_TICK_SEARCH); } } break; case Modes.Hunt: Cell prevCell = searchCell; Cell LookingAtCell = LookForPlayer(); if (LookingAtCell != null) { searchCell = LookingAtCell; timeSinceSpotted = 0; } if (prevCell == searchCell) { timeSinceSpotted += Time.deltaTime; if (timeSinceSpotted > 1) { ChangeMode(Modes.Search); } } moveTimer -= Time.deltaTime; if (moveTimer <= 0) { moveTimer = timeBetweenSteps; Direction direction = Pathfinding.GetNextStepDirection(this.pos.GetAsVector3Int(), searchCell.AsVector3Int()); if (direction != Direction.NONE) { MoveAlongDirection(direction, ruleSet.MONSTER_MOVEMENT_TICK_HUNT); } else { if (NextToPlayer()) { AttackPlayer(); ChangeMode(Modes.Happy); return; } } } break; case Modes.Happy: happyTimer -= Time.deltaTime; if (happyTimer <= 0) { ChangeMode(Modes.Search); } break; case Modes.Dead: break; default: break; } }