playerStates prevState; //this records the state the player had on the previous state #endregion #region Constructors public Player() { pState = playerStates.Stand; dirRight = true; drawnTex = new Rectangle(0, 0, 66, 66); hitbox = new Rectangle(drawnTex.X + (drawnTex.Width / 4), drawnTex.Y + (int)(drawnTex.Height * (7 / 8)), drawnTex.Width / 2, (drawnTex.Height / 8)); jumpHeight = 0; position = new Vector2(hitbox.X, hitbox.Y); //acceleration stuff speed = 1; //initial speed of the player maxSpeed = 10; //maximum speed of the player accTimer = 0; //how long since last increment of speed timeToNextAcc = 0.1; //how long it takes to increment speed timeToNextDec = 0.05; //how long it takes to decrement speed //controls stuff //animation stuff allAnims = new Dictionary <string, AnimationHelper>(); allAnims.Add("run", new AnimationHelper(5, 10)); allAnims.Add("jump", new AnimationHelper(12, 10)); }
void StateBell() { if (state == playerStates.BELLSTATE ) { anim.SetBool("BellPressed",true); exitTimeBell += Time.deltaTime; bellPressed = true; if (!source.isPlaying) { source.clip = (BellSound); source.Play(); } } if(exitTimeBell >= 1) { exitTimeBell = 0; source.Stop(); anim.SetBool("BellPressed",false); bellPressed =false; state = playerStates.IDLE; anim.SetBool ("isStriking", false); } }
/// <summary> /// Does the dash taking a dash object /// </summary> /// <param name="direction"></param> void DoDash(Dash dash) { dashed = true; meteor = null; currentDash = dash; // Debug.Log("Dash"); numDashes--; dashTimer = dashCooldown; rb.velocity = new Vector2(0, 0); //if ((rb.velocity.x<0 && direction.x >0) || (rb.velocity.x > 0 && direction.x < 0)) //{ // rb.velocity = new Vector2(0, rb.velocity.y); //} //if ((rb.velocity.y < 0 && direction.y > 0) || (rb.velocity.y > 0 && direction.y < 0)) //{ // rb.velocity = new Vector2(rb.velocity.x,0); //} rb.angularVelocity = 0; if (state != playerStates.hooked) { rb.AddRelativeForce(currentDash.direction.normalized * maxSpeed, ForceMode2D.Impulse); } else { rb.AddRelativeForce(currentDash.direction.normalized * maxSpeed, ForceMode2D.Impulse); rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * bonusSPEED); hookLine.GetComponent <MoveTrail>().takeBack(); } state = playerStates.dashing; Invoke("ResetDash", dashDuration); }
private void Update() { switch (state) { case playerStates.idle: { state = playerIdle.Action(); break; } case playerStates.walking: { state = playerWalking.Action(); break; } case playerStates.jumping: { state = playerJumping.Action(); break; } case playerStates.crouching: { state = playerCrouching.Action(); break; } } if (Input.GetKeyDown(KeyCode.Escape)) { Cursor.lockState = CursorLockMode.None; } }
// Switch to a given targetState for a specific amount of time, then switch back to a given returnState (public) public IEnumerator SwitchStateCycle(playerStates targetState, playerStates returnState, float duration) { playerState = targetState; // Set the playerState to the given targetState yield return(new WaitForSeconds(duration)); // Wait for a specific amount of time playerState = returnState; // Switch the playerState back to a given returnState }
void StopBoost() { if (currentPlayerState == playerStates.BoostEnding) { currentPlayerState = playerStates.Resting; SetPlayerStateParams(); } }
//Tag: Determine results when a player tags another void OnTriggerEnter(Collider other) { if(other.gameObject.CompareTag("Enemy")) { print("YOLO"); state = playerStates.Caught; playerDeath = true; } }
// Start is called before the first frame update void Start() { // Sets the initial state of the player to Alive m_currentPlayerState = playerStates.alive; // Sets the player's velocity to 0, 1 so that they move up the screen from the start m_playerVelocity = m_directionalVelocities[m_currentVelocityIndex]; }
public void getTouchButtonForBell() { if ( state == playerStates.IDLE ) { state = playerStates.BELLSTATE; } }
public void getTouchButtonForDig() { if (state == playerStates.IDLE || state == playerStates.WALKING) { state = playerStates.DIGGING; } }
void Jump() //跳跃函数 { if (currState != playerStates.falling) { if (Input.GetKeyDown(KeyCode.W)) { currState = playerStates.jump; } } }
public void getTouchButtonForBat() { if (state == playerStates.IDLE || state == playerStates.WALKING) { state = playerStates.BAT; } }
void OnCollisionEnter2D(Collision2D coll) { //if player collides with enemy , ie left or right white bar . if (coll.gameObject.tag == "Enemy"){ currentState = playerStates.dead;//changing state to dead, so the camera will also track the ball falldown iTween.PunchPosition(gameObject,iTween.Hash("amount",new Vector3(0.4f,0.0f,0),"time",0.6f,"easetype",iTween.EaseType.easeInOutBounce)); if(PlayerDead != null) PlayerDead(null,null);//to say every script that player is dead.those who every register to this event will fire their statements ,for ex uicontroller or Admanager SoundController.Static.PlayGameOver(); //to play sound } }
public void OnBeginDrag() { grabbedScreenPosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, transform.position.z); //offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, transform.position.z)); if (currentPlayerState == playerStates.Resting || currentPlayerState == playerStates.BoostEnding) { currentPlayerState = playerStates.MonitorPull; SetPlayerStateParams(); } }
/*void MoveGrab(){ //used to move the spz under the player's finger or mouse click position * Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, transform.position.z); * Vector3 curPosition = Camera.main.ScreenToWorldPoint (curScreenPoint) + offset; * curPosition.Set(TrimGrabbedX(curPosition.x), TrimTargetVectorY(transform.position.y), transform.position.z); * transform.position = curPosition; * }*/ void MonitorXBoostStart() { float pullDistance = grabbedScreenPosition.x - Input.mousePosition.x; if ((pullDistance > 0) && (Mathf.Abs(pullDistance) > pullThreshold)) { currentPlayerState = playerStates.BoostOnEndDrag; SetPlayerStateParams(); } }
public void enterDeathState( ) { gameObject.GetComponent <SpriteRenderer>().enabled = false; m_hudCanvas.SetActive(false); m_corpseController.createCorpse(m_xpManager.m_totalXP, m_xpManager.m_currentLevel, transform); m_currentPlayerState = playerStates.dead; }
private IEnumerator waitToFade() { yield return(new WaitForSecondsRealtime(5)); m_hudCanvas.SetActive(true); m_blackoutScreen.m_fadingOut = true; m_currentPlayerState = playerStates.alive; }
//使用卡牌,同时从自己的list里面删除卡牌 public void UseCardSkill(CardData card, CardData nCard) { if (card != null && nCard != null) { myCardList[myCardList.IndexOf(card)] = nCard; this.states = playerStates.move; speakImage.GetComponent <SpriteRenderer>().sprite = SD.getSpeak(); StartCoroutine(Speak()); } return; }
// Start is called before the first frame update void Start() { //Gets player states p = GetComponent <playerStates>(); leftFace = GameObject.Find("LeftFacing"); rightFace = GameObject.Find("RightFacing"); p.lookingLeft = false; player = GameObject.Find("Player"); powerups = player.GetComponent <Powerups>(); }
// Update is called once per frame void Update() { if (playerHealth <= 0.0f && playerState == playerStates.Alive) { // Dead GameObject newDeathEffect = Instantiate(deathEffect, gameObject.transform.position, Quaternion.identity) as GameObject; playerState = playerStates.Dead; // Talk to playerManager? gameObject.SetActive(false); } }
public AI(ContentManager content) { _Position = new Point(15, 0); _Alive = true; _State = playerStates.Idle; _MAX_HP = 10; _CURRENT_HP = 10; _ATTACK = 2; _DEFENCE = 0; LoadContent(content); }
void BoostEnding() { if (currentPlayerState == playerStates.BoostStarted) { currentPlayerState = playerStates.BoostEnding; SetCurrentCollisionState(playerCollisionStates.Vulnerable); avatar.SetBool("Boost", false); avatar.speed = 1.0f; tail.SetActive(true); speedManager.SpeedModifier = 1.0f; Invoke("StopBoost", 0.8f); } }
float speed = 5; //走路速度 // Use this for initialization void Start() { SD = GameObject.Find("players").GetComponent <SpeakData>(); player = this.gameObject; //PD = new PlayerData (); //skipsTimes = 0; //score = 0; //money = 0; states = playerStates.move; SP1 = GameObject.Find("SceneDirector").GetComponent <Sound_Play>(); loadsrc(); ScreenSetting(); }
void OnCollisionEnter2D(Collision2D coll) { //if player collides with enemy , ie left or right white bar . if (coll.gameObject.tag == "Enemy") { currentState = playerStates.dead; //changing state to dead, so the camera will also track the ball falldown iTween.PunchPosition(gameObject, iTween.Hash("amount", new Vector3(0.4f, 0.0f, 0), "time", 0.6f, "easetype", iTween.EaseType.easeInOutBounce)); if (PlayerDead != null) { PlayerDead(null, null); //to say every script that player is dead.those who every register to this event will fire their statements ,for ex uicontroller or Admanager } SoundController.Static.PlayGameOver(); //to play sound } }
void Start () { gameManager = GameObject.FindWithTag ("GameController"); if (GetComponent<NetworkView>().isMine) { Object1 = GameObject.FindWithTag ("MainCamera").transform; Object1.parent = transform; Object1.transform.position = transform.localPosition + new Vector3 (0f, 15f, -5f); playerInRange = false; state = playerStates.Search; } }
// Start is called before the first frame update void Start() { if (instance == null) { instance = this; } else { Destroy(gameObject); } state = playerStates.moving; estadoAtual = livre; }
// Update is called once per frame void Update() { //if player is not dead and is not idle state we will jump into gameplay . alive state if (Input.GetKeyDown(KeyCode.Mouse0) && currentState != playerStates.dead && currentState != playerStates.idle) { //when user taps ,add force to the ball GetComponent <Rigidbody2D>().AddForce(new Vector2(0, playerUpwardsForce * 100)); //to give punch scale effect iTween.PunchScale(gameObject, iTween.Hash("amount", new Vector3(0.06f, 0.06f, 0), "time", 1.7f, "easetype", iTween.EaseType.linear)); currentState = playerStates.alive; //changing ball/player state to alive SoundController.Static.PlayBallUp(); //to play ball tap sound. } thisTrans.position = new Vector2(0, thisTrans.position.y); // ball x position is constant at zero. }
public Player(ContentManager content) { _Position = new Point(5, 3); _Alive = true; _State = playerStates.Idle; //Characteristics initialization _MAX_HP = 10; _CURRENT_HP = 10; _ATTACK = 2; _DEFENCE = 0; _MA = new mAttack(content); LoadContent(content); }
// Update is called once per frame void Update() { //if player is not dead and is not idle state we will jump into gameplay . alive state if( Input.GetKeyDown(KeyCode.Mouse0) && currentState != playerStates.dead && currentState != playerStates.idle) { //when user taps ,add force to the ball GetComponent<Rigidbody2D>().AddForce(new Vector2(0,playerUpwardsForce* 100)); //to give punch scale effect iTween.PunchScale(gameObject,iTween.Hash("amount",new Vector3(0.06f,0.06f,0),"time",1.7f,"easetype",iTween.EaseType.linear)); currentState=playerStates.alive; //changing ball/player state to alive SoundController.Static.PlayBallUp(); //to play ball tap sound. } thisTrans.position =new Vector2(0,thisTrans.position.y); // ball x position is constant at zero. }
void States() { if ( state == playerStates.IDLE ) { if (Input.GetKeyDown (KeyCode.B)) { state = playerStates.BELLSTATE; } if (Input.GetKeyDown (KeyCode.S)) { state = playerStates.BAT; } } }
void TemporizeDoubleClick() { //Debug.Log("Before IF tempo dbclicktimer : " + doubleClickTimer + " " + doPlayerStateStuff.GetInvocationList().Length); if (doubleClickTimer < doubleClickThreshold) { doubleClickTimer += Time.deltaTime; } else { //Debug.Log("into the else"); currentPlayerState = playerStates.BoostStarted; particleSys.SetActive(false); SetPlayerStateParams(); } }
public void jumpOn(Transform meteor) { this.meteor = meteor; // remove the hook hookLine.GetComponent <MoveTrail>().takeBack(); // teleport to the rock? state = playerStates.onMeteor; rb.velocity = Vector2.zero; numDashes = 2; if (currentDash != null) { ignoreCounter++; currentDash = null; dashTimer = 0; } }
// Use this for initialization void Start() { myBody = gameObject.GetComponent <Rigidbody>(); spawnPosY = gameObject.transform.position.y; originalPos = gameObject.transform.position; currentState = playerStates.normal; som = gameObject.GetComponent <AudioSource>(); som2 = gameObject.GetComponent <AudioSource>(); gameObject.SetActive(true); }
GameObject oldPlayer; //The previous GameObject before it is deleted. void Update() { if (Input.GetButtonDown("Transform") && playerState == playerStates.Bag) { currentLocation = player.transform.GetChild(0).transform; oldPlayer = player; player = Instantiate(playerBallPrefab, currentLocation.position, Quaternion.identity) as GameObject; Destroy(oldPlayer); playerState = playerStates.Ball; } else if (Input.GetButtonDown("Transform") && playerState == playerStates.Ball) { currentLocation = player.transform.GetChild(0).transform; oldPlayer = player; player = Instantiate(playerBagPrefab, currentLocation.position, Quaternion.identity) as GameObject; Destroy(oldPlayer); playerState = playerStates.Bag; } }
void Run() { if (currState == playerStates.landing) { if (DoubleClick(KeyCode.D) || DoubleClick(KeyCode.A)) { speed = baseSpeed * 2; currState = playerStates.running; Debug.Log(currState); } } else if (currState == playerStates.running) { if (Input.GetKeyUp(KeyCode.D) || Input.GetKeyUp(KeyCode.A)) { currState = playerStates.landing; speed = baseSpeed; } } }
void PlayerMove() { if (myPositionList.Count > 0) //给参数才会走,防止出现溢出 { float step = speed * Time.deltaTime; // 速度 player.transform.position = Vector3.MoveTowards(player.transform.position, myPositionList[0], step); // 移动 if (player.transform.position == myPositionList[0]) { myPositionList.RemoveAt(0); SP1.SoundPlay(10); //SP1.SoundPlay(2); } if (myPositionList.Count == 0) { MoveOver(this); //if (gameController != null) // gameController.OnMoveOver(); states = playerStates.skill; } } }
void batState() { if (state == playerStates.BAT) { if (exitTimeBat == 0) { anim.SetBool("isStriking", true); } exitTimeBat += Time.deltaTime; if (exitTimeBat >= 0.35) { } if (exitTimeBat >= 0.5) { exitTimeBat = 0; anim.SetBool("isStriking", false); state = playerStates.IDLE; } } }
public void OnEndDrag() { avatar.SetBool("Grabbed", false); targetY = transform.position.y; ClickSetTargetVector(); if (currentPlayerState == playerStates.BoostOnEndDrag && lunch.Count > 1)// && if hasEnoughBoost { currentPlayerState = playerStates.InBoost; gameVars.PlayerDefaultX = gameVars.PlayerRestingPosition; GameObject tempBacDeath = lunch[lunch.Count - 1]; lunch.RemoveAt(lunch.Count - 1); tempBacDeath.GetComponent <BacDeath>().Consumed(); Invoke("GoToPlayerBoostPosition", 0.15f); } else if (currentPlayerState != playerStates.InBoost && currentPlayerState != playerStates.BoostStarted) { currentPlayerState = playerStates.Resting; //Debug.Log("resting called from OnEndDrag"); } SetPlayerStateParams(); }
private void Update() { staminaBar.transform.localScale = new Vector3(stamina / 100, staminaBar.transform.localScale.y, staminaBar.transform.localScale.z); hungerBar.transform.localScale = new Vector3(hunger / 100, hungerBar.transform.localScale.y, hungerBar.transform.localScale.z); starvationBar.transform.localScale = new Vector3(starvationTimer / 50, starvationBar.transform.localScale.y, starvationBar.transform.localScale.z); if (!gameOverScreen.activeInHierarchy) { highscoreTimer += Time.deltaTime; } highscore.text = highscoreTimer.ToString("F2"); if (hunger > 25) { staminaHungerRelation = 100 / hunger; State = playerStates.NORMAL; } else { staminaHungerRelation = 4; State = playerStates.STARVING; } if (hunger > 0) { hunger -= hungerModifier * Time.deltaTime; } else { hunger = 0; } if (hunger > 100) { hunger = 100; } if (stamina > 0) { stamina -= Time.deltaTime * staminaHungerRelation * staminaModifier; } else { stamina = 0; Debug.Log("End of Day"); } if (starvationTimer >= 50) { starvationTimer = 50; Debug.Log("GAME OVER"); gameOverScreen.SetActive(true); } if (starvationTimer <= 0) { starvationTimer = 0; } switch (State) { case playerStates.STARVING: if (starvationTimer < 50) { starvationTimer += Time.deltaTime * starvationGainModifier; if (!tutorialStarvation) { tutorialStarvation = true; } } break; case playerStates.NORMAL: if (starvationTimer > 0) { starvationTimer -= Time.deltaTime * starvationReductionModifier; } break; } }
/////////////////////////////////////////////// void FixedUpdate() { if(!player_can_move)return; last_velocity = GetComponent<Rigidbody>().velocity; if(boost_pointer) { if(current_mode!=playerStates.Boosting) { Destroy(boost_pointer.gameObject); } } if(current_mode==playerStates.Hit && !AniisPlaying()) { current_mode=playerStates.Idle; play_animation(animation_idle); } if(current_mode==playerStates.Jumping|| current_mode==playerStates.Falling || current_mode==playerStates.Gliding || current_mode==playerStates.WallSlide || current_mode==playerStates.Climbing || current_mode==playerStates.Hit) // in some cases, we can't use our movement code return; if((current_mode==playerStates.Walking) || (current_mode==playerStates.Running) || (current_mode==playerStates.Boosting)) // check the direction we are moving { if(return_real_axis().x!=0.0f) { if(Mathf.Sign(return_real_axis().x)!=movement_direction) // we changed the direction while walking, let's stop { current_mode=playerStates.Stopping; play_animation(animation_stop); } if(Mathf.Abs(Mathf.Sign(return_real_axis().x) - 1.0f) <= 0.1f){ movement_direction = 1; }else{ movement_direction = -1; } // movement_direction = Mathf.Sign(return_real_axis().x); // -1 = left; 1 = right; if(current_mode!=playerStates.Jumping && current_mode!=playerStates.Falling) player_graphic_pointer.eulerAngles = new Vector3(player_graphic_pointer.eulerAngles.x,90*movement_direction,player_graphic_pointer.eulerAngles.z); } } if((Mathf.Abs(return_real_axis().x)<0.01f || !player_can_move) && current_mode!=playerStates.Idle && current_mode!=playerStates.Stopping && current_mode!=playerStates.Sliding) // no joystick input? then idle { current_mode=playerStates.Idle; play_animation(animation_idle); last_max_speed=0; } if(current_mode==playerStates.Stopping) // we are stopping { if(Mathf.Sign(return_real_axis().x)==movement_direction && player_can_move) // we are still trying to get in the stopping direction { current_speed = Mathf.Max(0,current_speed-(stopping_lose_move_speed*Time.deltaTime)); } else // if not then stop the stopping { current_mode=playerStates.Idle; play_animation(animation_idle); movement_direction = movement_direction*-1; } if(current_speed==0){current_mode=playerStates.Idle;play_animation(animation_idle);} GetComponent<Rigidbody>().velocity= new Vector3(current_speed*movement_direction*-1,GetComponent<Rigidbody>().velocity.y,GetComponent<Rigidbody>().velocity.z); return; } if(current_mode==playerStates.Sliding) // we slow down { if(current_speed<0.1f) { current_mode=playerStates.Idle; play_animation(animation_idle); } max_speed = current_speed; } if(current_mode==playerStates.Idle) // if we idle, the max speed is the maximun, so we can decrease { if(current_speed>0.1f) { current_mode=playerStates.Sliding; if(current_speed<max_running_speed) play_animation(animation_slide); else play_animation(animation_runslide); } max_speed = current_speed; } if(player_can_move) { if(current_mode==playerStates.Walking) max_speed = max_walking_speed*Mathf.Abs(return_real_axis().x); if(current_mode==playerStates.Running) { max_speed = max_running_speed*Mathf.Abs(return_real_axis().x); if(current_speed==max_running_speed)boost_count_down-=Time.deltaTime; else boost_count_down = time_till_boost; if(boost_count_down<0 && can_extra_boost) { current_mode=playerStates.Boosting; play_animation(animation_boost); if(boost_graphic) { boost_pointer = Instantiate (boost_graphic, player_graphic_pointer.transform.position, Quaternion.identity) as Transform; boost_pointer.transform.parent = transform; boost_pointer.transform.position-= Vector3.forward/2; boost_pointer.transform.eulerAngles = player_graphic_pointer.transform.eulerAngles; } } if(hold_button_to_run && !return_real_run()) { current_mode=playerStates.Walking; play_animation(animation_walk); } } if(current_mode==playerStates.Boosting) { max_speed = max_boost_speed*Mathf.Abs(return_real_axis().x); } } if(max_speed < last_max_speed) { max_speed = last_max_speed - lose_move_speed*Time.deltaTime; } else { last_max_speed = max_speed; } if(Mathf.Abs(return_real_axis().x)>0.01f && player_can_move && (current_mode==playerStates.Idle || current_mode==playerStates.Sliding)) { // max_speed=0; last_max_speed=0; current_mode=playerStates.Walking; play_animation(animation_walk); } if(wall_left && movement_direction==-1) { current_speed =0; } if(wall_right && movement_direction==1) { current_speed = 0; } if(current_mode!=playerStates.Stopping) { if(Mathf.Abs(return_real_axis().x)>0.02f) current_speed = Mathf.Clamp(current_speed+(gain_move_speed*Time.deltaTime),max_speed*-1,max_speed); else { current_speed = Mathf.Clamp(current_speed-(lose_move_speed*Time.deltaTime),0,max_speed); } // GetComponent<Rigidbody>().velocity.x = current_speed*movement_direction; GetComponent<Rigidbody>().velocity = new Vector3(current_speed*movement_direction,GetComponent<Rigidbody>().velocity.y,GetComponent<Rigidbody>().velocity.z); } if((current_speed<=max_running_speed && current_mode == playerStates.Boosting)) { play_animation(animation_run); current_mode=playerStates.Running; } if((current_speed<=max_walking_speed && current_mode == playerStates.Running)) { play_animation(animation_walk); current_mode=playerStates.Walking; } if((current_speed>=max_walking_speed && current_mode == playerStates.Walking && !hold_button_to_run) || (hold_button_to_run && return_real_run() && current_mode == playerStates.Walking && current_speed>=max_walking_speed)) { current_mode=playerStates.Running; play_animation(animation_run); boost_count_down = time_till_boost; // reset the countdown } if(current_mode!=playerStates.Idle) last_max_speed = max_speed; }
public void Update(GameTime gameTime, List <PlatformSprite> platforms, List <EnemySprite> enemySprites, List <PlatformSpriteRotate> rotate) { KeyboardState keyboardState = Keyboard.GetState(); //Movement if (!jumpIsPressed && currentState == playerStates.idle && (keyboardState.IsKeyDown(Keys.W))) { jumpIsPressed = true; currentState = playerStates.jumping; spriteVelocity.Y -= jumpSpeed; jumpSound.Play(); } else if (jumpIsPressed && currentState != playerStates.jumping && currentState != playerStates.falling && !(keyboardState.IsKeyDown(Keys.W))) { jumpIsPressed = false; } else if (currentState == playerStates.walking && keyboardState.IsKeyDown(Keys.W)) { jumpIsPressed = true; currentState = playerStates.falling; spriteVelocity.Y += jumpSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; } if ((keyboardState.IsKeyDown(Keys.A) || keyboardState.IsKeyDown(Keys.Left)) && currentState != playerStates.kiBlast && currentState != playerStates.kicking) { currentState = playerStates.walking; spriteVelocity.X = -walkSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; flipped = true; } else if ((keyboardState.IsKeyDown(Keys.D) || keyboardState.IsKeyDown(Keys.Right)) && currentState != playerStates.kiBlast && currentState != playerStates.kicking) { currentState = playerStates.walking; spriteVelocity.X = walkSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; flipped = false; } else if (currentState == playerStates.walking && keyboardState.IsKeyDown(Keys.W)) { jumpIsPressed = true; currentState = playerStates.falling; spriteVelocity.Y += jumpSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; } else { if (currentState == playerStates.walking) { currentState = playerStates.idle; } spriteVelocity.X = 0; } if (jumpIsPressed && currentState == playerStates.walking) { spriteVelocity.Y += jumpSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; } else if (!jumpIsPressed && currentState == playerStates.walking) { spriteVelocity.Y += jumpSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; } if (currentState == playerStates.idle && spriteVelocity.Y >= 1f) { spriteVelocity.Y += jumpSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; } if (spritePos.Y > 810 && dead == false) { dead = true; hitSound.Play(); } //Attacks //Blast if (!blastIsPressed && keyboardState.IsKeyDown(Keys.Space)) { currentState = playerStates.kiBlast; spriteVelocity.X = 0; blastIsPressed = true; } else if (blastIsPressed && !keyboardState.IsKeyDown(Keys.Space)) { blastIsPressed = false; } //Kick if (!kickIsPressed && keyboardState.IsKeyDown(Keys.Q)) { currentState = playerStates.kicking; kickIsPressed = true; } else if (kickIsPressed && !keyboardState.IsKeyDown(Keys.Q)) { kickIsPressed = false; } //Punch if (!punchIsPressed && keyboardState.IsKeyDown(Keys.F)) { currentState = playerStates.punching; punchIsPressed = true; } else if (punchIsPressed && !keyboardState.IsKeyDown(Keys.F)) { punchIsPressed = false; } //Checking for collision on the platforms sprites bool hasCollided = false; foreach (PlatformSprite platform in platforms) { if (checkCollisionBelow(platform)) { hasCollided = true; while (checkCollision(platform)) { spritePos.Y--; } spriteVelocity.Y = 0; if (currentState == playerStates.jumping || currentState == playerStates.falling) { currentState = playerStates.idle; } } else if (checkCollisionAbove(platform)) { hasCollided = true; while (checkCollision(platform)) { spritePos.Y++; } spriteVelocity.Y = 0; currentState = playerStates.falling; } if (checkCollisionLeft(platform)) { hasCollided = true; while (checkCollision(platform)) { spritePos.X--; } spriteVelocity.X = 0; } else if (checkCollisionRight(platform)) { hasCollided = true; while (checkCollision(platform)) { spritePos.X++; } spriteVelocity.X = 0; } } //Checking for collision on the rotated platform sprites foreach (PlatformSpriteRotate walls in rotate) { if (checkCollisionLeft(walls)) { hasCollided = true; while (checkCollision(walls)) { spritePos.Y++; spritePos.X--; } if (currentState == playerStates.jumping || currentState == playerStates.falling) { currentState = playerStates.idle; } } if (checkCollisionRight(walls)) { hasCollided = true; while (checkCollision(walls)) { spritePos.X++; } if (currentState == playerStates.jumping || currentState == playerStates.falling) { currentState = playerStates.idle; } } if (checkCollisionAbove(walls)) { hasCollided = true; while (checkCollision(walls)) { spritePos.X++; } if (currentState == playerStates.jumping || currentState == playerStates.falling) { currentState = playerStates.idle; } } if (checkCollisionBelow(walls)) { hasCollided = true; while (checkCollision(walls)) { spritePos.X++; } if (currentState == playerStates.jumping || currentState == playerStates.falling) { currentState = playerStates.idle; } } } //Checking collision on the enemy sprites foreach (EnemySprite enemySprite in enemySprites) { if (!enemySprite.dead && checkCollision(enemySprite)) { if (currentState == playerStates.kicking || currentState == playerStates.punching) { enemySprite.dead = true; if (spritePos.Y < 200f) { enemySprite.levelAdvance = true; } } else { hasCollided = true; dead = true; spriteVelocity.X = 0; hitSound.Play(); } } } //Allowing the Animation not to continue to switch inbetween each other if (currentState == playerStates.idle || currentState == playerStates.walking || currentState == playerStates.punching || currentState == playerStates.kicking) { spritePos.Y += 5f; foreach (PlatformSprite platform in platforms) { if (checkCollisionBelow(platform)) { hasCollided = true; } } spritePos.Y -= 5f; } //Declairing the player as falling if in the air if (!hasCollided && currentState != playerStates.falling && currentState != playerStates.kiBlast) { currentState = playerStates.falling; } if (currentState == playerStates.jumping && spriteVelocity.Y > 0) { currentState = playerStates.falling; } //Allowing the player to fall back to the platforms if ((currentState == playerStates.falling || currentState == playerStates.jumping || currentState == playerStates.kiBlast || currentState == playerStates.punching || currentState == playerStates.kicking || currentState == playerStates.walking) && spriteVelocity.Y < 500f) { spriteVelocity.Y += 5f * (float)gameTime.ElapsedGameTime.TotalSeconds; } spritePos += spriteVelocity; //Allowing the player to move //Controlling which animation is being used switch (currentState) { case playerStates.walking: setAnim(2); break; case playerStates.jumping: setAnim(3); break; case playerStates.falling: setAnim(3); break; case playerStates.kiBlast: setAnim(1); break; case playerStates.punching: setAnim(5); break; case playerStates.kicking: setAnim(4); break; case playerStates.idle: setAnim(0); break; default: setAnim(0); break; } //Restting the animation to idle if (currentState == playerStates.punching || currentState == playerStates.kiBlast || currentState == playerStates.kicking) { if (currentFrame >= animations[currentAnim].Count - 1) { currentState = playerStates.idle; } } }
void Start() { playerInRange = false; state = playerStates.Search; }
//to handle the player ControllerColliderHit information void OnControllerColliderHit(ControllerColliderHit incoming) { if (presentPlayerState != playerStates.Alive) { return; } //for player hit zombies when shield is off if (incoming.collider.name.Contains("Zombie") && !ShieldIcon) { SoundController.Static.PlayDeadSound(); //for player dead sound presentPlayerState = playerStates.dead; //to take player is which state GameController.Static.isplayerDaed = true; incoming.collider.isTrigger = true; Ace_IngameUiControl.Static.GameEnd(); //to calling gameEnd function sword.SetActive(false); //to sword deactive when player is dead GameObject obj = Instantiate(PlayerDeadEffect, thisTrans.position, Quaternion.identity) as GameObject; //to player dead effect Destroy(obj, 0.5f); //for destroy zombie after some time Destroy(incoming.collider.gameObject.GetComponent <Collider> ()); //for destroy zombie collider GameObject.Find("Main Camera").GetComponent <CameraShake> ().enabled = true; //for camera shaking } //for player hit Obsticles when shield is off else if (incoming.collider.tag.Contains("Obstacles") && !ShieldIcon) { presentPlayerState = playerStates.dead; //to take player is which state GameController.Static.isplayerDaed = true; SoundController.Static.PlayDeadSound(); //for player dead sound Ace_IngameUiControl.Static.GameEnd(); //to calling gameEnd function GameObject obj1 = Instantiate(PlayerDeadEffect, thisTrans.position, Quaternion.identity) as GameObject; //to player dead effect Destroy(obj1, 0.3f); //for destroy zombie after some time Destroy(incoming.collider.GetComponent <GameObject> ()); //for destroy zombie collider sword.SetActive(false); //to sword deactive when player is dead GameObject.Find("Main Camera").GetComponent <CameraShake> ().enabled = true; //for camera shaking } //for player hit Rock when shield is off else if (incoming.collider.name.Contains("Rock") && !ShieldIcon) { presentPlayerState = playerStates.dead; //to take player is which state GameController.Static.isplayerDaed = true; SoundController.Static.PlayDeadSound(); //for player dead sound Ace_IngameUiControl.Static.GameEnd(); //to calling gameEnd function GameObject obj2 = Instantiate(PlayerDeadEffect, thisTrans.position, Quaternion.identity) as GameObject; //to player dead effect Destroy(obj2, 0.3f); //for destroy zombie after some time Destroy(incoming.collider.gameObject.GetComponent <Collider> ()); //for destroy zombie collider sword.SetActive(false); //to sword deactive when player is dead GameObject.Find("Main Camera").GetComponent <CameraShake> ().enabled = true; //for camera shaking } //for player hit zombies when shield is on if (incoming.collider.name.Contains("Zombie") && (ShieldIcon || !isPlayerOnTheGround)) { ZombieController zombieScript = incoming.collider.GetComponent <ZombieController> (); zombieScript.DeathState(); Ace_IngameUiControl.Static.inGameScoreCount++; } //for player hit Obsticles when shield is on else if (incoming.collider.tag.Contains("Obsticles") && ShieldIcon) { Destroy(incoming.collider.gameObject); } //for player hit Rock when shield is off else if (incoming.collider.name.Contains("Rock") && ShieldIcon) { Destroy(incoming.collider.transform.parent.gameObject); } else if (incoming.collider.name.Contains("broken_pot") || incoming.collider.name.Contains("broken_pot") && ShieldIcon) { incoming.gameObject.GetComponent <Collider> ().isTrigger = true; } }
public void hookedOn() { Debug.Log("pulling"); state = playerStates.hooked; }
void digState() { if (state == playerStates.DIGGING) { if (exitTimeDig == 0) { anim.SetBool("isDigging", true); } exitTimeDig += Time.deltaTime; if (exitTimeDig >= 0.5) { anim.SetBool("isDigging", false); } if (exitTimeDig >= 1) { exitTimeDig = 0; state = playerStates.IDLE; } } }