// Update is called once per frame void Update() { if (currentPoints < Global.score) { currentPoints += 20; if (currentPoints >= Global.score) { currentPoints -= Global.score - currentPoints; if (noDead) { NoDeadText.Activate(2.5f); activateStar(currentRate); currentRate++; } } gain_points.text = gainTitle + "\n" + (currentPoints / 10).ToString(); for (int i = 0; i < trashold.Length; i++) { if (currentPoints > trashold[i] && i == currentRate) { activateStar(i); currentRate++; } } } }
// Use this for initialization void Start () { Characters[Global.selectedCharacter].SetActive(true); CurrentCharacterIcon.sprite = CharacterIcons[Global.selectedCharacter]; req_direction = -1; pac_direction = 1; dead = false; anim = gameObject.GetComponent<Animator> (); anim.SetInteger("direction", pac_direction); ghost_combo = 50; ghost_combo_countdown = 0; ammo_obj = ammo.gameObject; //add dropping cards extras if (Global.ac > -1) { if (Global.own_cards [Global.ac] == 0) max_fire_shield = 50; else if (Global.own_cards [Global.ac] == 5) max_fire_shield = 100; else if (Global.own_cards [Global.ac] == 10) max_fire_shield = 150; if (Global.own_cards [Global.ac] == 4) speed *= 1.1f; else if (Global.own_cards [Global.ac] == 9) speed *= 1.15f; else if (Global.own_cards [Global.ac] == 14) speed *= 1.2f; } Global.Ammo.Quantity = 0; Global.Mine.Quantity = 0; mine_text.text = "X " + Global.Mine.Quantity.ToString(); ammo_text.text = "X " + Global.Ammo.Quantity.ToString(); ReadyToGo.Activate(2.0f); prev_pos_x = -1; prev_pos_y = -1; setCamera(); }
void new_life() { if (life > 0) { life--; life_text.text = "X " + life.ToString (); Global.pause_game = true; Global.enemy_rise = 3.5f; if (life == 0) { GameOverTxt.Activate(2.0f); return; } if (!Global.classic && transform.position.y * 2 > Global.level_height - 10) { CompleteTxt.Activate(2.0f); return; } pac_direction = 1; anim.SetInteger("direction", pac_direction); int j = ((int)camera.transform.position.y) * 2, k; if (j < 0) j = 0; if (Global.classic) respawn_player(Global.startcoord_x / 2.0f, Global.startcoord_y / 2.0f); else { for (k = 0; k < 17 && Global.levelmatrix[j, k] == -1; k++) ; respawn_player(k / 2.0f, j / 2.0f); } ReadyToGo.Activate(2.0f); dead = false; anim.SetBool("dead", false); foreach (var enemy in Global.enemies) Destroy(enemy.gameObject); Global.enemies.Clear(); if (Global.classic) { Global.followEnemyAlive = false; Global.blockenemyAlive = false; } } }
// Update is called once per frame void Update() { if (!Global.PauseEnemy.IsActive() && !Global.pause_game && !eating) { if (isSpawned) { roundedPosX = Mathf.Round(transform.position.x * 2.0f) / 2.0f; roundedPosY = Mathf.Round(transform.position.y * 2.0f) / 2.0f; if ((roundedPosX * 2 != matrix_x || roundedPosY * 2 != matrix_y) && ((direction == 0 && transform.position.x < roundedPosX) || (direction == 1 && transform.position.x > roundedPosX) || (direction == 2 && transform.position.y > roundedPosY) || (direction == 3 && transform.position.y < roundedPosY))) { //get level matrix coordinates matrix_x = Mathf.RoundToInt(roundedPosX * 2.0f); matrix_y = Mathf.RoundToInt(roundedPosY * 2.0f); //get enemy pos from coordinates enemy_pos = Global.levelmatrix [matrix_y, matrix_x]; if (enemy_pos > 1) { transform.position = new Vector3(roundedPosX, roundedPosY, 0); } //fix enemy position when go out of playground if (enemy_pos == -1) { fix_enemy_pos(matrix_x, matrix_y); } //fix direction if (enemy_pos == 0 && (direction == 2 || direction == 3)) { direction = 0; if (animation_type == 1) { transform.localEulerAngles = new Vector3(0, 0, 90); } } else if (enemy_pos == 1 && (direction == 0 || direction == 1)) { direction = 2; if (animation_type == 1) { transform.localEulerAngles = new Vector3(0, 0, 0); } } //move back if the enemy go out of camera view if (transform.position.y > camera.transform.position.y + Global.view_range_top && enemy_pos != 0 && enemy_pos != 2 && enemy_pos != 3 && enemy_pos != 7 && enemy_pos != 11) { direction = 3; if (animation_type == 1) { transform.localEulerAngles = new Vector3(0, 0, 180); } } else if (isAlly && transform.position.y < camera.transform.position.y + Global.view_range_bottom + 1.0f && enemy_pos != 0 && enemy_pos != 6 && enemy_pos != 4 && enemy_pos != 5 && enemy_pos != 11) { direction = 2; if (animation_type == 1) { transform.localEulerAngles = new Vector3(0, 0, 0); } } //determine enemy's moving direction else { if (enemy_pos > 1) { if (Global.classic && ( enemy_type < 2 || enemy_type == 2 && Vector3.Distance(transform.position, pock_man.position) > 2.85f || enemy_type == 3 && Vector3.Distance(transform.position, pock_man.position) > 5.55f) || (enemy_type == 5 && Vector3.Distance(transform.position, new Vector3(camera.position.x, camera.position.y + 2.5f, camera.position.z)) > 3.55f)) { switch (enemy_type) { case 0: searchAI.search(matrix_x, matrix_y, (Math.Abs(pac_script.back_x - pock_man.position.x * 2) < Math.Abs(pac_script.front_x - pock_man.position.x * 2) ? pac_script.back_x : pac_script.front_x), ((Math.Abs(pac_script.back_y - pock_man.position.y * 2) < Math.Abs(pac_script.front_y - pock_man.position.y * 2) ? pac_script.back_y : pac_script.front_y))); break; case 1: searchAI.search(matrix_x, matrix_y, pac_script.front_x, pac_script.front_y); break; case 2: searchAI.search(matrix_x, matrix_y, pac_script.front_x, pac_script.front_y, 4); break; case 3: searchAI.search(matrix_x, matrix_y, 4, pac_script.front_y, 8); break; case 5: searchAI.search(matrix_x, matrix_y, (int)(camera.position.x * 2.0f), (int)(camera.position.y * 2.0f) + 5, 5); break; } if (searchAI.NextWayX() > matrix_x) { direction = 1; } else if (searchAI.NextWayX() < matrix_x) { direction = 0; } else if (searchAI.NextWayY() > matrix_y) { direction = 2; } else if (searchAI.NextWayY() < matrix_y) { direction = 3; } else { if (direction < 2) { if ((int)(pock_man.position.y * 2.0f) > matrix_y) { direction = 2; } else if ((int)(pock_man.position.y * 2.0f) < matrix_y) { direction = 3; } } else { if ((int)(pock_man.position.x * 2.0f) > matrix_x) { direction = 1; } else if ((int)(pock_man.position.x * 2.0f) < matrix_x) { direction = 0; } } } setRotation(); } else { determine_direction(); } } } //change enemy's sprite if (!Global.Invertibility.IsActive()) { if (animation_type == 0) { current_sprite.sprite = sprites [direction + ally_sprite]; } } //deactivate enemy at top of level if (!Global.classic && matrix_y > Global.level_height - 8) { Global.enemies.Remove(this); Destroy(gameObject); } } if (Global.controll_type == 0 && !isAlly && !Global.Invertibility.IsActive() && Vector3.Distance(transform.position, pock_man.position) < 2.0f) { if (matrix_y == (int)(pock_man.position.y * 2.0f)) { if ((pac_script.getDirection == 0 && transform.position.x > pock_man.position.x) || (pac_script.getDirection == 1 && transform.position.x < pock_man.position.x)) { pac_script.setBehindEnemy = true; Debug.Log("Enemy behind horizontal"); } } else if (matrix_x == (int)(pock_man.position.x * 2.0f)) { if ((pac_script.getDirection == 2 && transform.position.y < pock_man.position.y) || (pac_script.getDirection == 3 && transform.position.y > pock_man.position.y)) { pac_script.setBehindEnemy = true; Debug.Log("Enemy behind vertical"); } } } //invertibility time section if (Global.Invertibility.IsActive()) { if (!invertibility) { invertibility = true; invTime = 100; } //enemy sprite will be blue if invertibility is active and change lower speed if (Global.Invertibility.TimeRemaining > 2.0f) { if (animation_type == 0) { current_sprite.sprite = sprites [direction + 4]; } else { current_sprite.sprite = sprites [1]; } speed = 0.8f; } else { if (invTime / 20 % 2 == 0) { if (animation_type == 0) { current_sprite.sprite = sprites [direction + 4]; } else { current_sprite.sprite = sprites [1]; } } else { if (animation_type == 0) { current_sprite.sprite = sprites [direction + 8]; } else { current_sprite.sprite = sprites [2]; } } invTime--; } } else if (invertibility) { speed = (Global.classic ? Global.enemy_speed : Global.enemy_speed * 0.8f); if (animation_type < 5) { current_sprite.sprite = sprites [ally_sprite]; } invertibility = false; } //ally activation section if (isAlly) { if (Time.timeSinceLevelLoad - allyTime > 10.0f) //end of ally { deconvertFromAlly(); } else if (Time.timeSinceLevelLoad - allyTime > 7.0f) { if (allyAnim / 20 % 2 == 0) { setAllySprite(true); } else { setAllySprite(false); } allyAnim--; } } //die enemy in case of going out of camera view (in rush mode only) if (!Global.classic && transform.position.y < camera.transform.position.y + Global.view_range_bottom) { Global.enemies.Remove(this); Destroy(gameObject); } //move of enemy if (animation_type == 0 || animation_type == 2) { if (direction == 0) { transform.Translate(-speed * Time.deltaTime, 0, 0); } else if (direction == 1) { transform.Translate(speed * Time.deltaTime, 0, 0); } else if (direction == 2) { transform.Translate(0, speed * Time.deltaTime, 0); } else if (direction == 3) { transform.Translate(0, -speed * Time.deltaTime, 0); } } else { transform.Translate(0, speed * Time.deltaTime, 0); } //collision of enemy if (!isAlly && !Global.PauseEnemy.IsActive() && !pac_script.dead && isSpawned && Vector2.Distance(transform.position, pock_man.position) < 0.25f) { //enemy kills the player if (!Global.Invertibility.IsActive()) { pac_script.anim.SetBool("dead", true); pac_script.dead = true; Global.pause_game = true; //invertibility enabled } else { Global.score += pac_script.ghost_combo; //show total ghost combo if (pac_script.ghost_combo == 250) { pock_man.GetComponentInChildren <manage_pickups>().activate_rate_text("Total ghost combo!"); } //set and show ghost combo title GhostComboPopup.Activate(3.0f); GhostComboPopup.SetText("+" + pac_script.ghost_combo.ToString()); Transform new_dead = (Transform)Instantiate(enemy_dead, transform.position, Quaternion.identity); new_dead.position = transform.position; new_dead.gameObject.SetActive(true); pac_script.ghost_combo += 50; Global.enemies.Remove(this); Destroy(gameObject); if (Global.classic) { killSpecialEnemy(); } } } } else { if (Time.timeSinceLevelLoad - spawnTime > 2.0f) { isSpawned = true; } count_down--; //animatoin of enemy respawning if (animation_type == 0) { current_sprite.sprite = sprites[12 + (count_down / 5 % 4)]; } else { current_sprite.sprite = sprites[3 + (count_down / 5 % 4)]; } //deactivation at end of level /*if (count_down < -8) { * count_down = 0; * Global.enemies.Remove(gameObject); * Destroy(gameObject); * }*/ if (isSpawned) { if (animation_type == 0) { current_sprite.sprite = sprites[direction]; } else { current_sprite.sprite = sprites[0]; } } } } if (eating && Time.timeSinceLevelLoad - eatTime > 1.5f) { eating = false; } }
// Update is called once per frame void Update() { if (!Global.pause_game) { //level completed if (!Global.classic && (int)(pac_man.position.x * 2) == Global.endcoord_x && (int)(pac_man.position.y * 2) == Global.endcoord_y || Global.classic && Global.remaining < 1) { Global.pause_game = true; CompleteTxt.Activate(2.0f); } //vertical moving of camera if (!Global.classic) { float relative_pos = (pac_man.position.y - transform.position.y) / 10.0f; camera_speed = (base_camera_speed + relative_pos) * camera_speed_decreaser; if (!Global.LevelRewind.IsActive() && !Global.LevelPause.IsActive()) { transform.Translate(0, camera_speed * Time.deltaTime, 0); } else if (Global.LevelRewind.IsActive()) { transform.Translate(0, -1.0f * Time.deltaTime, 0); } } //spawn enemy if ((Global.classic && Global.enemies.Count < Global.max_enemy && Time.timeSinceLevelLoad > nextEnemyTime) || ((transform.position.y + 10.0f) * 2.0f < Global.level_height && Time.timeSinceLevelLoad > nextEnemyTime)) { enemy_movement new_enemy; if (Global.classic && !Global.followEnemyAlive && Global.enemies.Count > 1) { Global.followEnemyAlive = true; new_enemy = (enemy_movement)Instantiate(enemy[0], spawn_enemy(), Quaternion.identity); } else if (Global.classic && !Global.blockenemyAlive && Global.enemies.Count > 3) { Global.blockenemyAlive = true; new_enemy = (enemy_movement)Instantiate(enemy[1], spawn_enemy(), Quaternion.identity); } else { new_enemy = (enemy_movement)Instantiate(enemy[(int)Random.Range(2.0f, 4.9f)], spawn_enemy(), Quaternion.identity); } new_enemy.gameObject.SetActive(true); Global.enemies.Add(new_enemy); nextEnemyTime += Global.enemy_rise * respawn_delay; if (!Global.classic && Global.enemy_rise > 1.25f) { Global.enemy_rise -= 0.05f; } } if (Global.LevelRewind.IsEnd() || Global.LevelPause.IsEnd()) { nextEnemyTime += 3.0f; } if (!double_score_signal.activeInHierarchy && Global.DoubleScore.IsActive()) { double_score_signal.SetActive(true); } else if (Global.DoubleScore.IsEnd()) { double_score_signal.SetActive(false); } } if (Global.pause_game && Time.timeSinceLevelLoad > nextEnemyTime) { nextEnemyTime += Global.enemy_rise; } }
//appearing rate text public void activate_rate_text(string title) { RateText.SetText(title); RateText.Activate(3.0f); }