Exemple #1
0
        private void Update()
        {
            if (TheGame.IsGamePaused())
            {
                return;
            }

            if (dead)
            {
                return;
            }

            Vector3 dir = current_rot_target - transform.position;

            dir.z = 0f;
            Debug.DrawRay(transform.position, dir);

            //Side
            if (Mathf.Abs(dir.x) > 0.1f)
            {
                float side = (dir.x < 0f) ? -1f : 1f;
                transform.localScale = new Vector3(Mathf.Abs(start_scale.x) * side, start_scale.y, start_scale.z);
            }

            //Vision angle
            if (dir.magnitude > 0.1f)
            {
                float      angle  = Mathf.Atan2(dir.y, dir.x * GetSide()) * Mathf.Rad2Deg;
                Quaternion target = Quaternion.AngleAxis(angle, Vector3.forward);
                face_rot    = Quaternion.RotateTowards(face_rot, target, rotate_speed * current_rot_mult * Time.deltaTime);
                face_vect   = face_rot * Vector3.right;
                face_vect.x = face_vect.x * GetSide();
                face_vect.Normalize();
            }
        }
Exemple #2
0
        private void FixedUpdate()
        {
            if (TheGame.IsGamePaused())
            {
                return;
            }

            if (dead)
            {
                return;
            }

            Vector2 dist_vect = (current_target - rigid.position);

            move_vect = dist_vect.normalized * move_speed * current_mult * Mathf.Min(dist_vect.magnitude, 1f);

            bool grounded = DetectObstacle(Vector3.down);

            if (fall_speed > 0.1f && !flying)
            {
                if (grounded)
                {
                    fall_value = 0f;
                }
                else
                {
                    fall_value += fall_accel * Time.deltaTime;
                }
                fall_value  = Mathf.Clamp(fall_value, 0f, fall_speed);
                move_vect.y = -fall_value;
            }

            rigid.velocity = move_vect;
        }
        void Update()
        {
            if (TheGame.Get().IsPaused())
            {
                return;
            }

            //Anims
            animator.SetBool("Jumping", character.IsJumping());
            animator.SetBool("InAir", !character.IsGrounded());
            animator.SetBool("Crouching", character.IsCrouching());
            animator.SetFloat("Speed", character.GetMove().magnitude);
            animator.SetBool("Climb", character.IsClimbing());
            if (character_item != null)
            {
                animator.SetBool("Hold", character_item.GetHeldItem() != null);
            }

            //Hit flashing
            render.color = new Color(render.color.r, render.color.g, render.color.b, 1f);
            if (flash_fx_timer > 0f)
            {
                flash_fx_timer -= Time.deltaTime;
                float alpha = Mathf.Abs(Mathf.Sin(flash_fx_timer * Mathf.PI * 4f));
                render.color = new Color(render.color.r, render.color.g, render.color.b, alpha);
            }
        }
Exemple #4
0
 public void OnClickSave()
 {
     if (TheGame.Get())
     {
         TheGame.Get().Save();
     }
 }
        //Handle render and controls
        void Update()
        {
            if (TheGame.IsGamePaused())
            {
                return;
            }

            hit_timer   += Time.deltaTime;
            state_timer += Time.deltaTime;
            //grounded_timer += Time.deltaTime;

            //Controls
            PlayerControls controls = PlayerControls.Get(player_id);

            if (state == PlayerCharacterState.Normal)
            {
                if (controls.GetJumpDown())
                {
                    Jump();
                }

                Ladder ladder = Ladder.GetOverlapLadder(gameObject);
                if (ladder && controls.GetMove().y > 0.1f && state_timer > 0.7f)
                {
                    Climb();
                }
            }

            if (state == PlayerCharacterState.Climb)
            {
                Ladder ladder = Ladder.GetOverlapLadder(gameObject);
                if (ladder == null)
                {
                    state       = PlayerCharacterState.Normal;
                    state_timer = 0f;
                }

                if (controls.GetJumpDown())
                {
                    Jump(true);
                }
            }

            //Reset when fall
            if (!IsDead() && transform.position.y < fall_pos_y - GetSize().y)
            {
                TakeDamage(fall_damage);
                if (reset_when_fall)
                {
                    Teleport(last_ground_pos);
                }
            }
        }
        //Handle physics
        void FixedUpdate()
        {
            if (TheGame.IsGamePaused())
            {
                return;
            }

            PlayerControls controls = PlayerControls.Get(player_id);

            //Movement velocity
            Vector3 move_input   = controls.GetMove();
            float   desiredSpeed = Mathf.Abs(move_input.x) > 0.1f ? move_input.x * move_max : 0f;
            float   acceleration = Mathf.Abs(move_input.x) > 0.1f ? move_accel : move_deccel;

            acceleration = !is_grounded ? jump_move_percent * acceleration : acceleration;
            move.x       = Mathf.MoveTowards(move.x, desiredSpeed, acceleration * Time.fixedDeltaTime);

            was_grounded = is_grounded;
            is_grounded  = DetectObstacle(Vector3.down);
            is_ceiled    = DetectObstacle(Vector3.up);
            is_fronted   = IsFronted();

            if (state == PlayerCharacterState.Normal)
            {
                UpdateFacing();
                UpdateJump();
                UpdateCrouch();

                //Move
                move.x         = is_fronted ? 0f : move.x;
                rigid.velocity = move;

                CheckForFloorTrigger();
            }

            if (state == PlayerCharacterState.Climb)
            {
                move           = controls.GetMove() * climb_speed;
                rigid.velocity = move;
            }

            if (state == PlayerCharacterState.Dead)
            {
                move.x = 0f;
                UpdateJump(); //Keep falling
                rigid.velocity = move;
            }
        }
Exemple #7
0
        void Update()
        {
            if (TheGame.IsGamePaused())
            {
                return;
            }

            if (target == null)
            {
                return;
            }

            Vector3 targ     = target.transform.position;
            Vector3 dir_vect = targ - transform.position;

            if (dir_vect.magnitude < follow_range)
            {
                enemy.MoveTo(targ, speed_mult);
                enemy.FaceToward(enemy.GetMoveTarget(), 2f);
            }
        }
Exemple #8
0
        void Update()
        {
            if (TheGame.IsGamePaused())
            {
                return;
            }

            wait_timer += Time.deltaTime;

            move_dir = Vector3.right * Mathf.Sign(transform.localScale.x);

            //If still in starting path
            if (!waiting && !HasFallen() && path_list.Count > 0)
            {
                //Move
                Vector3 targ = path_list[current_path];
                enemy.MoveTo(targ, speed_mult);
                enemy.FaceToward(targ);
                move_dir = Vector3.right * Mathf.Sign((targ - transform.position).x);

                //Check if reached target
                Vector3 dist_vect = (targ - transform.position);
                dist_vect.z = 0f;
                if (dist_vect.magnitude < 0.1f)
                {
                    waiting    = true;
                    wait_timer = 0f;
                }

                //Check if obstacle ahead
                bool fronted = enemy.CheckFronted(dist_vect.normalized);
                if (fronted && wait_timer > 2f)
                {
                    RewindPath();
                    wait_timer = 0f;
                }
            }

            //If can't reach starting path anymore
            if (!waiting && HasFallen())
            {
                //Move
                Vector3 mdir = Vector3.right * (path_rewind ? -2f : 2f);
                Vector3 targ = transform.position + mdir;
                enemy.MoveTo(targ, speed_mult);
                enemy.FaceToward(targ);
                move_dir = Vector3.right * Mathf.Sign((targ - transform.position).x);

                //Check if obstacle ahead
                Vector3 dist_vect = (targ - transform.position);
                bool    fronted   = enemy.CheckFronted(dist_vect.normalized);
                if (fronted && wait_timer > 2f)
                {
                    path_rewind = !path_rewind;
                    wait_timer  = 0f;
                }
            }

            if (waiting)
            {
                //Wait a bit
                if (wait_timer > wait_time)
                {
                    GoToNextPath();
                    waiting    = false;
                    wait_timer = 0f;
                }
            }
        }
Exemple #9
0
 public void Save()
 {
     PlayerData.Get().current_checkpoint = unique_id;
     TheGame.Get().Save();
 }
Exemple #10
0
 void Awake()
 {
     _instance = this;
     PlayerData.Load();
 }
Exemple #11
0
 private void Start()
 {
     TheGame.Get().onPause += (bool paused) => { animator.Rebind(); };
 }