void SwipeDetection(SwipeControls.SwipeDirection direction) { switch (direction) { case SwipeControls.SwipeDirection.Up: MoveUp(); break; case SwipeControls.SwipeDirection.Down: MoveDown(); break; case SwipeControls.SwipeDirection.Left: MoveLeft(); break; case SwipeControls.SwipeDirection.Right: MoveRight(); break; } }
/* * FUNCITON: Detect swipes on screen * CALLED BY: Update() */ void SwipeMovementControl() { //check and execute two jump or duck commands simultaneously if (bDirectionQueueFlag) { if (!bInAir && directionQueue == SwipeControls.SwipeDirection.Jump) //queue JUMP { bJumpFlag = true; bDirectionQueueFlag = false; } //end of jump queue if (directionQueue == SwipeControls.SwipeDirection.Duck && !bInDuck) //queue SLIDE { duckPlayer(); bDirectionQueueFlag = false; } //end of duck queue } //end of direction queue //swipe controls SwipeControls.SwipeDirection direction = swipeLogic.getSwipeDirection(); //get the swipe direction if (direction != SwipeControls.SwipeDirection.Null) { bMouseReleased = false; //disallow taps on swipe if (direction == SwipeControls.SwipeDirection.Jump) //JUMP { if (!bInAir) { bJumpFlag = true; } if (bInAir) //queue the second jump if player swipes up in the middle of a jump { bDirectionQueueFlag = true; directionQueue = SwipeControls.SwipeDirection.Jump; } } //end of if direction is jump if (direction == SwipeControls.SwipeDirection.Right && swipeControlsEnabled == true) //RIGHT swipe { if (iLanePosition != 1) { iLastLanePosition = iLanePosition; iLanePosition++; strafePlayer(StrafeDirection.right); } //end of lane check if } //end of swipe direction if if (direction == SwipeControls.SwipeDirection.Left && swipeControlsEnabled == true) //LEFT swipe { if (iLanePosition != -1) { iLastLanePosition = iLanePosition; iLanePosition--; strafePlayer(StrafeDirection.left); } //end of lane check if } //end of swipe direction if if (direction == SwipeControls.SwipeDirection.Duck && bInDuck) //SLIDE: queue the second duck command if player is in the middle of slide animation { bDirectionQueueFlag = true; directionQueue = SwipeControls.SwipeDirection.Duck; } if (direction == SwipeControls.SwipeDirection.Duck && !bInAir && !bInDuck) //SLIDE: on ground { duckPlayer(); } if (direction == SwipeControls.SwipeDirection.Duck && bInAir && !bInDuck) //SLIDE/ DIVE: in air { bDiveFlag = true; //used by Set Transform() to make the character dive } //end of slide in air if //swipeLogic.iTouchStateFlag = 2; } //end of if if (Input.GetMouseButtonUp(0)) //allow taps on mouse/ tap release { bMouseReleased = true; } if (!isPlayingDuck() && bInDuck == true) //restore the size of the collider after slide ends { hSoundManager.playSound(SoundManager.CharacterSounds.Footsteps); tPlayerRotation.localEulerAngles = new Vector3(0, 0, 0); //rotation correction after DIVE tBlobShadowPlane.localPosition = new Vector3(0, 0, 0); //translation correction after DIVE (to fix mysterious S bug ) bInDuck = false; tFrontCollider.localScale = v3BNCDefaultScale; tPlayerSidesCollider.localScale = v3BFCDefaultScale; //restore far collider if (bDiveFlag) //do not resume run animation on Dive { return; } aPlayer.CrossFadeQueued("run", 0.5f, QueueMode.CompleteOthers); } //keyboard controls (DEBUG) if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow)) //Up/ jump { if (!bInAir) { bJumpFlag = true; } if (bInAir) { bDirectionQueueFlag = true; directionQueue = SwipeControls.SwipeDirection.Jump; } } else if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow)) //Right { if (iLanePosition != 1) { iLastLanePosition = iLanePosition; iLanePosition++; strafePlayer(StrafeDirection.right); } //end of lane check if } else if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow)) //Left { if (iLanePosition != -1) { iLastLanePosition = iLanePosition; iLanePosition--; strafePlayer(StrafeDirection.left); } //end of lane check if } else if ((Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow)) && bInDuck) { bDirectionQueueFlag = true; directionQueue = SwipeControls.SwipeDirection.Duck; } else if ((Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow)) && !bInAir && !bInDuck) { duckPlayer(); } else if ((Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow)) && bInAir && !bInDuck) { bDiveFlag = true; //used by Set Transform() to make the character dive } } //end of Movement Control function
void Start() { hMenuScript = GameObject.Find("MenuGroup").GetComponent <MenuScript>() as MenuScript; hPatchesRandomizer = this.GetComponent <PatchesRandomizer>() as PatchesRandomizer; hPlayerSidesColliderScript = GameObject.Find("PlayerSidesCollider").GetComponent <PlayerSidesColliderScript>() as PlayerSidesColliderScript; hPlayerFrontColliderScript = GameObject.Find("PlayerFrontCollider").GetComponent <PlayerFrontColliderScript>() as PlayerFrontColliderScript; hSoundManager = GameObject.Find("SoundManager").GetComponent <SoundManager>() as SoundManager; hInGameScript = this.GetComponent <InGameScript>() as InGameScript; hPitsMainController = this.GetComponent <PitsMainController>() as PitsMainController; hCheckPointsMain = this.GetComponent <CheckPointsMain>() as CheckPointsMain; hPowerupScript = this.GetComponent <PowerupsMainController>() as PowerupsMainController; hEnemyController = GameObject.Find("Enemy").GetComponent <EnemyController>() as EnemyController; hPowerupScript = this.GetComponent <PowerupsMainController>() as PowerupsMainController; hCameraController = Camera.main.gameObject.GetComponent <CameraController>() as CameraController; swipeLogic = transform.GetComponent <SwipeControls>() as SwipeControls; tPlayer = transform; tPlayerRotation = transform.Find("PlayerRotation"); playerRenderer = GameObject.Find("rend").GetComponent <SkinnedMeshRenderer>(); //get the animation component of the player character aPlayer = this.transform.Find("PlayerRotation/PlayerMesh/Prisoner").GetComponent <Animation>() as Animation; tBlobShadowPlane = transform.Find("BlobShadowPlane"); tPlayerSidesCollider = GameObject.Find("PlayerSidesCollider").transform; tFrontCollider = GameObject.Find("PlayerFrontCollider").transform; if (!PersistentManagerScript.Instance.obstacles) { tFrontCollider.GetComponent <BoxCollider>().enabled = false; tPlayerSidesCollider.GetComponent <BoxCollider>().enabled = false; } tHUDGroup = GameObject.Find("HUDMainGroup/HUDGroup").transform; tPauseButton = GameObject.Find("HUDMainGroup/HUDGroup/HUDPause").transform; tQuitButton = GameObject.Find("HUDMainGroup/HUDGroup/HUDQuit").transform; tQuitButton.gameObject.active = false; HUDCamera = GameObject.Find("HUDCamera").GetComponent <Camera>(); v3BNCDefaultScale = tFrontCollider.localScale; v3BFCDefaultScale = tPlayerSidesCollider.localScale; bInAir = false; fCurrentDistanceOnPath = 50.0f; //inital distance with respect to spline fCurrentDistance = 0.0f; fCurrentMileage = 0.0f; tCurrentAngle = 0.0f; fPitFallLerpValue = 0.0f; fPitFallForwardSpeed = 0.0f; fPitPositionX = 0.0f; iDeathAnimStartTime = 0; bGroundhit = false; bJumpFlag = false; bInJump = false; fCurrentUpwardVelocity = 0; fCurrentHeight = 0; bDirectionQueueFlag = false; directionQueue = SwipeControls.SwipeDirection.Null; iLanePosition = 0; //set current lane to mid fCurrentWalkSpeed = fStartingWalkSpeed; if (PlayerPrefs.HasKey("ControlsType")) { swipeControlsEnabled = PlayerPrefs.GetInt("ControlsType") == 1 ? true : false; } else { PlayerPrefs.SetInt("ControlsType", (swipeControlsEnabled == true ? 1 : 0)); } hSoundManager.stopSound(SoundManager.CharacterSounds.Footsteps); StartCoroutine("playIdleAnimations"); //start playing idle animations }