Example #1
0
        // Update is called once per frame
        void Update()
        {
            if (boss_health_info.is_dead)
            {
                reward_manager.placeReward(transform.position);
                Destroy(gameObject);
            }

            if (boss_health_info.curr_health / boss_health_info.max_health <= 0.5f && phase == 1)
            {
                phase = 2;
                laser_reward_manager.placeReward();
            }

            state_controller.process_time();

            bool state_changed = false;

            state_changed = state_controller.process_state();

            //if state just changed
            if (state_changed)
            {
                //rotate if idle state was just entered from run attack state
                if (state_controller.curr_state == (int)Enemy1_State_Transition_Func.enemy1_state.idle &&
                    state_controller.prev_states[state_controller.prev_states.Count - 1] == (int)Enemy1_State_Transition_Func.enemy1_state.run_attack_right)
                {
                    transform.RotateAround(transform.position, Vector3.up, 180);
                }
                else if (state_controller.curr_state == (int)Enemy1_State_Transition_Func.enemy1_state.idle &&
                         state_controller.prev_states[state_controller.prev_states.Count - 1] == (int)Enemy1_State_Transition_Func.enemy1_state.run_attack_left)
                {
                    transform.RotateAround(transform.position, Vector3.up, 180);
                }
                //turn around if run attack collides with player
                if (state_controller.curr_state == (int)Enemy1_State_Transition_Func.enemy1_state.run_attack_left &&
                    state_controller.prev_states[state_controller.prev_states.Count - 1] == (int)Enemy1_State_Transition_Func.enemy1_state.run_attack_right)
                {
                    transform.RotateAround(transform.position, Vector3.up, 180);
                }
                else if (state_controller.curr_state == (int)Enemy1_State_Transition_Func.enemy1_state.run_attack_right &&
                         state_controller.prev_states[state_controller.prev_states.Count - 1] == (int)Enemy1_State_Transition_Func.enemy1_state.run_attack_left)
                {
                    transform.RotateAround(transform.position, Vector3.up, 180);
                }
                //determine stomp horizontal speed
                else if (state_controller.curr_state == (int)Enemy1_State_Transition_Func.enemy1_state.stomp_charge)
                {
                    stomp_charge_horizontal_speed = 1.5f + Random.value;
                }
                //call laser aim function if laser attack state is entered
                else if (state_controller.curr_state == (int)Enemy1_State_Transition_Func.enemy1_state.laser_charge)
                {
                    if (transform.right.x >= 0)
                    {
                        laser_manager.aim_laser(transform.position, new Vector3(transform.position.x + 10, transform.position.y, transform.position.z), 0.2f, 10f);
                    }
                    if (transform.right.x < 0)
                    {
                        laser_manager.aim_laser(transform.position, new Vector3(transform.position.x - 10, transform.position.y, transform.position.z), 0.2f, 10f);
                    }
                }
                //call laser function if laser attack state is entered
                else if (state_controller.curr_state == (int)Enemy1_State_Transition_Func.enemy1_state.laser_attack)
                {
                    if (transform.right.x >= 0)
                    {
                        laser_manager.fire_laser(transform.position, true, new Vector3(transform.position.x + 10, transform.position.y, transform.position.z), 0.2f, 10f);
                    }
                    if (transform.right.x < 0)
                    {
                        laser_manager.fire_laser(transform.position, true, new Vector3(transform.position.x - 10, transform.position.y, transform.position.z), 0.2f, 10f);
                    }
                }
                //call laser rain aim function of laser rain aim state is entered
                else if (state_controller.curr_state == (int)Enemy1_State_Transition_Func.enemy1_state.laser_rain_charge)
                {
                    float x = -5f;
                    for (int i = 0; i < 6; i++)
                    {
                        float rand_x = (x - 0.5f) + (Random.value);
                        laser_rain_positions[i]  = new Vector3(rand_x, 10, -0.558f);
                        laser_rain_directions[i] = new Vector3(rand_x, -2, -0.558f);
                        x += 2f;
                    }

                    laser_manager.laser_rain_aim(laser_rain_positions, laser_rain_directions);
                }
                //call laser rain attack function if laser rain aim state is entered
                else if (state_controller.curr_state == (int)Enemy1_State_Transition_Func.enemy1_state.laser_rain_attack)
                {
                    laser_manager.laser_rain_fire(laser_rain_positions, laser_rain_directions);
                }
                //call laser rapid aim function if laser rapid aim state is entered
                else if ((state_controller.curr_state == (int)Enemy1_State_Transition_Func.enemy1_state.laser_rapid_charge))
                {
                    float rand_x = (Random.value * 20) - 10;

                    laser_rapid_position  = new Vector3(rand_x, 10f, -0.558f);
                    laser_rapid_direction = player.transform.position;

                    laser_manager.aim_laser(laser_rapid_position, laser_rapid_direction, 0.5f, 30f);
                }
                //call laser rapid fire function if laser rapid fire state is entered
                else if ((state_controller.curr_state == (int)Enemy1_State_Transition_Func.enemy1_state.laser_rapid_attack))
                {
                    laser_manager.fire_laser(laser_rapid_position, true, laser_rapid_direction, 0.5f, 30f);
                }
            }

            string desc = Utility_methods.GetDescription <Enemy1_State_Transition_Func.enemy1_state>((Enemy1_State_Transition_Func.enemy1_state)state_controller.curr_state);

            if (desc != "")
            {
                enemy_animator.Play(desc);
            }
            else
            {
                enemy_animator.Play("idle");
            }


            if (state_controller.curr_state == (int)Enemy1_State_Transition_Func.enemy1_state.idle)
            {
                if (CheckPlayerBehind())
                {
                    transform.RotateAround(transform.position, Vector3.up, 180);
                }
            }
            else if (state_controller.curr_state == (int)Enemy1_State_Transition_Func.enemy1_state.run_windup)
            {
                transform.Translate(Time.deltaTime * -run_windup_speed, 0, 0);
            }
            //enemy is running to the right
            else if (state_controller.curr_state == (int)Enemy1_State_Transition_Func.enemy1_state.run_attack_right)
            {
                transform.Translate(Time.deltaTime * run_attack_speed, 0, 0);
                if (transform.position.x >= 4)
                {
                    transform.position = new Vector3(4f, transform.position.y, transform.position.z);
                }
            }
            //enemy is running to the left
            else if (state_controller.curr_state == (int)Enemy1_State_Transition_Func.enemy1_state.run_attack_left)
            {
                transform.Translate(Time.deltaTime * run_attack_speed, 0, 0);
                if (transform.position.x <= -4)
                {
                    transform.position = new Vector3(-4f, transform.position.y, transform.position.z);
                }
            }
            else if (state_controller.curr_state == (int)Enemy1_State_Transition_Func.enemy1_state.stomp_windup)
            {
                transform.Translate(Time.deltaTime * -stomp_windup_speed, 0, 0);
            }
            //enemy is charging stomp
            else if (state_controller.curr_state == (int)Enemy1_State_Transition_Func.enemy1_state.stomp_charge)
            {
                transform.Translate(Time.deltaTime * stomp_charge_horizontal_speed, Time.deltaTime * stomp_charge_vertical_speed, 0);
                if (transform.position.y >= 3f)
                {
                    transform.position = new Vector3(transform.position.x, 3f, transform.position.z);
                }
                if (transform.position.x >= 4.5f && transform.right.x > 0)
                {
                    transform.position = new Vector3(4.5f, transform.position.y, transform.position.z);
                }
                if (transform.position.x <= -4.5f && transform.right.x < 0)
                {
                    transform.position = new Vector3(-4.5f, transform.position.y, transform.position.z);
                }
            }
            //enemy is stomping
            else if (state_controller.curr_state == (int)Enemy1_State_Transition_Func.enemy1_state.stomp_attack)
            {
                transform.Translate(0, Time.deltaTime * -stomp_attack_speed, 0);
                if (transform.position.y <= 0.66f)
                {
                    transform.position = new Vector3(transform.position.x, 0.66f, transform.position.z);
                }
            }

            //LaunchAttack(hitboxes,(Enemy1_State_Transition_Func.enemy1_state)state_controller.curr_state);
        }
        // Update is called once per frame
        void Update()
        {
            if (!enable_control)
            {
                return;
            }

            float horizontal_input = Input.GetAxis("Horizontal");
            float vertical_input   = Input.GetAxis("Vertical");
            bool  pause_input      = Input.GetButtonDown("Pause");

            reload_scene_if_death();

            Player_Input.PlayerInput input = Player_controller_helper.getPlayerInput(ref combo_info, enable_attacks, enable_parry, enable_dodge, enable_laser);

            if (pause_manager.GetLaserPaused())
            {
                if (Input.GetButtonDown("Jump"))
                {
                    pause_manager.UnpauseLaser();
                    pause_manager.RemoveLaserTutorial();
                    pause_manager.PauseCombo();
                    pause_manager.ShowComboTutorial();
                }
            }

            else if (pause_manager.GetComboPaused())
            {
                if (Input.GetButtonDown("Jump"))
                {
                    pause_manager.UnpauseCombo();
                    pause_manager.RemoveComboTutorial();
                    Time.timeScale = 1f;
                }

                if (Input.GetButtonDown("Attack"))
                {
                    pause_manager.UnpauseCombo();
                    pause_manager.RemoveComboTutorial();
                    pause_manager.PauseLaser();
                    pause_manager.ShowLaserTutorial();
                }
            }

            pause_game(pause_input);

            if (pause_manager.GetPaused())
            {
                if (Input.GetButtonDown("Jump") && pause_visual)
                {
                    pause_manager.RemovePause();
                    pause_visual = false;
                }
                else if (Input.GetButtonDown("Jump") && !pause_visual)
                {
                    pause_manager.ShowPause();
                    pause_visual = true;
                }
                return;
            }

            //if parry_stop is active, check if it should be removed
            if (parry_stop)
            {
                Time.timeScale = 0f;
                if (Time.realtimeSinceStartup - parry_stop_initial > 0.3f)
                {
                    parry_stop     = false;
                    Time.timeScale = 1f;
                }
            }

            attack_controller.process_time();
            state_controller.process_time();

            bool state_changed = state_controller.process_state(input);

            process_attack_input(state_changed, input);
            if (attack_controller.curr_state != 0)
            {
                //attacking
                char_animator.Play(Utility_methods.GetDescription <Attack_State_Transition_Func.attack_state>((Attack_State_Transition_Func.attack_state)attack_controller.curr_state));
            }
            else
            {
                string desc = Utility_methods.GetDescription <Player_State_Transition_Func.player_state>((Player_State_Transition_Func.player_state)state_controller.curr_state);
                if (desc != "")
                {
                    char_animator.Play(desc);
                }
                //set animation to whatever else
            }

            process_parry(state_changed);

            setColour();

            apply_movement(horizontal_input, vertical_input);

            update_indicators();

            if (dodge_invuln_timer > 0)
            {
                dodge_invuln_timer -= Time.deltaTime;
            }

            if (knockback_timer > 0)
            {
                knockback_timer -= Time.deltaTime;
            }
        }