//执行跳的过程 void Raise() { //上升阶段 if (jumpInstantSpeed > 0) { float raiseDis = deltaTime * jumpInstantSpeed; raiseDis += raiseDis * jumpHigher; transform.position += Vector3.up * raiseDis; //上升速度递减 jumpInstantSpeed -= jumpAttenuation * deltaTime; if (jumpInstantSpeed < 0) { jumpInstantSpeed = 0; } } else { if (wantJump && jumpInstantSpeed == 0 && state == BoyState.Raising) { state = BoyState.Falling; wantJump = false; fallSpeed = 0; } } }
public void reset() { frame = 0; frameTime = 0; frameLength = 60; position = new Vector2(X, Y); Width = 38; Height = 58; state = BoyState.Idle; Animation = "stand"; direction = Direction.Right; actionBubble.Player = this; actionBubble.show(); teleportTo = new Vector2(); nearestChair = null; }
public void OnTakeChocolate(Chocolate chocolate) { _boyAnimation.StopMove(); if (chocolate.Type == ChocolateType.Chocolate || chocolate.Type == ChocolateType.Rafaello || chocolate.Type == ChocolateType.Truffele) { _currencyController.AddChocolate(chocolate); _boyState = BoyState.OnStartTakeChocolate; } else if (chocolate.Type == ChocolateType.Dirt || chocolate.Type == ChocolateType.Nails || chocolate.Type == ChocolateType.Glass || chocolate.Type == ChocolateType.Shit) { _currencyController.AddScum(chocolate); _boyState = BoyState.OnStartTakeScum; } }
public Boy(float X, float Y, ActionBubble actionBubble) { this.sheet = sheetMan.getSheet("boy"); frame = 0; frameTime = 0; frameLength = 60; position = new Vector2(X, Y); Width = 38; Height = 58; state = BoyState.Idle; Animation = "stand"; direction = Direction.Right; this.actionBubble = actionBubble; actionBubble.Player = this; actionBubble.show(); teleportTo = new Vector2(); drawLayer = DrawLayer.Player; }
public void Jump(float speed) { wantJump = true; state = BoyState.Raising; horizontalInputSpeed = speed; jumpInstantSpeed = jumpspeed; for (int i = 0; i < 100; i++) { //危险和安全机关算是collided,地形不算collided. if (isCollided) { break; } JumpSimulate(); } CheckSurvive(); }
void CheckOnGround() { //命中地面且距离为0,表示紧贴地面。否则表示在空中。在空中又分为上升、下落、跌落。 //设置是否在地面 if ((isFootHit && disToGround == 0) || (isFootHit1 && disToGround1 == 0) || (isFootHit2 && disToGround2 == 0)) { state = BoyState.Grounded; } else { //print("从高台跌落"); //在空中的情况下,如果当前状态是grounded,说明这一帧从高台跌落。 if (state == BoyState.Grounded) { state = BoyState.Falling; //跌落速度。高空跌落时,初始速度为0。当低空且贴近地面跌落时,初始下落速度设为较大值。 fallSpeed = 5; //fallSpeed = 0; } } }
private void OnStartTakeScum() { _boyAnimation.TakeScum(); _boyState = BoyState.OnTaking; }
public void SetState(BoyState state) { _boyState = state; }
public void StartMove() { _boyState = BoyState.OnMoving; }
private void Start() { _boyAnimation = GetComponent <BoyAnimation>(); _boyState = BoyState.Ilde; }
private void OnStartMove() { _boyAnimation.StartMove(); _boyState = BoyState.OnMoving; }
private void OnStopMove() { _boyState = BoyState.Ilde; }
private void OnStartTakeChocolate() { _boyAnimation.TakeChocolate(); _boyState = BoyState.OnTaking; }
private void OnStopTakeChocolate() { _boyState = BoyState.Ilde; }
private void OnStopTakeScum() { _boyState = BoyState.Ilde; }
// Update is called once per frame void Update() { if (!Dead) { if (GameObject.Find("GameController").GetComponent <Usables>().Bush.Count <= 0) { BoyState = BoyState.Idle; } if (GameObject.Find("GameController").GetComponent <Usables>().Tree.Count <= 0) { BoyState = BoyState.Idle; } if (GameObject.Find("GameController").GetComponent <Usables>().House.Count <= 0) { BoyState = BoyState.Idle; } switch (BoyState) { case BoyState.Idle: NavMeshAgent.SetDestination(RandomNavmeshLocation(6f)); //anim.Play("ArmsWalking"); break; case BoyState.FindingFood: //anim.Play("ArmsFeed"); BoyState = BoyState.WalkingToObjectif; break; case BoyState.WalkingToObjectif: if (destinationToObjectif != null) { if (Vector3.Distance(destinationToObjectif.transform.position, this.transform.position) > 2) { NavMeshAgent.SetDestination(destinationToObjectif.transform.position); } else { BoyState = BoyState.StandingStill; } } break; case BoyState.StandingStill: //anim.Play("ArmsNotMoving"); break; case BoyState.RunAway: //find a random spot 30 min max away if (!RunAwayFromFire) { RunAwayFromFire = true; GameObject newPosGameObject = new GameObject(); newPosGameObject.transform.position = RandomNavmeshLocation(30); destinationToRunAwayFromFireTo = newPosGameObject; } destinationToObjectif = destinationToRunAwayFromFireTo; //anim.Play("Arms"); if (destinationToObjectif != null) { if (Vector3.Distance(destinationToObjectif.transform.position, this.transform.position) > 2) { NavMeshAgent.SetDestination(destinationToObjectif.transform.position); } else { RunAwayFromFire = false; } } break; default: break; } } else { NavMeshAgent.isStopped = true; } }
private void checkInput(GameController control) { if (state != BoyState.Die) { if ((control.keyState.IsKeyDown(Keys.Space) || control.padState.IsButtonDown(Buttons.A))) { if ((((state == BoyState.Walk || state == BoyState.Idle) && control.keyState.IsKeyUp(Keys.Right) && control.keyState.IsKeyUp(Keys.Left) && control.padState.IsButtonUp(Buttons.LeftThumbstickRight) && control.padState.IsButtonUp(Buttons.LeftThumbstickLeft)) || state == BoyState.PushWalk) && null != interactor) { interactor.Interact(); } } else if ((state == BoyState.PushingStill ||state == BoyState.PushWalk) && interactor != null) { state = BoyState.Idle; } if (control.keyState.IsKeyDown(Keys.LeftControl) || control.padState.IsButtonDown(Buttons.RightTrigger)) { if (nearestChair != null) { state = BoyState.ControllingChair; nearestChair.state = Chairs.ChairsState.Moving; } } else { if (nearestChair != null && nearestChair.state == Chairs.ChairsState.Moving) { nearestChair.state = Chairs.ChairsState.Falling; state = BoyState.Idle; } } if (control.keyState.IsKeyUp(Keys.Left) && control.keyState.IsKeyUp(Keys.Right) && control.padState.IsButtonUp(Buttons.LeftThumbstickLeft) && control.padState.IsButtonUp(Buttons.LeftThumbstickRight) && state != BoyState.Teleport && state != BoyState.TimeTravel) { if (state != BoyState.ControllingChair) { if (direction == Direction.Right) { if (state != BoyState.StairsRight && state != BoyState.StairsLeft) { if ((state == BoyState.PushWalk || state == BoyState.PushingStill) && interactor != null) state = BoyState.PushingStill; else state = BoyState.Idle; } } else { if (state != BoyState.StairsRight && state != BoyState.StairsLeft) { if ((state == BoyState.PushWalk || state == BoyState.PushingStill) && interactor != null) state = BoyState.PushingStill; else state = BoyState.Idle; } } } } else { if (state != BoyState.ControllingChair) { if (control.keyState.IsKeyDown(Keys.Right) || control.padState.IsButtonDown(Buttons.LeftThumbstickRight)) { if ((state != BoyState.PushWalk && state != BoyState.PushingStill) || (interactor != null && ((Wardrobe)interactor).X > X)) direction = Direction.Right; if (state == BoyState.Idle) state = BoyState.Walk; if (state == BoyState.PushingStill && direction == Direction.Right && interactor != null) state = BoyState.PushWalk; } else if (control.keyState.IsKeyDown(Keys.Left) || control.padState.IsButtonDown(Buttons.LeftThumbstickLeft)) { if ((state != BoyState.PushWalk && state != BoyState.PushingStill) || (interactor != null && ((Wardrobe)interactor).X < X)) direction = Direction.Left; if (state == BoyState.Idle) state = BoyState.Walk; if (state == BoyState.PushingStill && direction == Direction.Left && interactor != null) state = BoyState.PushWalk; } } } if (state == BoyState.ControllingChair) { if (nearestChair != null && nearestChair.state == Chairs.ChairsState.Moving) { if (control.keyState.IsKeyDown(Keys.Right) || control.padState.IsButtonDown(Buttons.LeftThumbstickRight)) { nearestChair.move(Direction.Right); } else if (control.keyState.IsKeyDown(Keys.Left) || control.padState.IsButtonDown(Buttons.LeftThumbstickLeft)) { nearestChair.move(Direction.Left); } if (control.keyState.IsKeyDown(Keys.Up) || control.padState.IsButtonDown(Buttons.LeftThumbstickUp)) { nearestChair.move(Direction.Up); } else if (control.keyState.IsKeyDown(Keys.Down) || control.padState.IsButtonDown(Buttons.LeftThumbstickDown)) { nearestChair.move(Direction.Down); } } else { state = BoyState.Idle; } } } }
public void update(GameTime time) { int elapsed = time.ElapsedGameTime.Milliseconds; frameTime += elapsed; checkInput(control); drawLayer = DrawLayer.Player; switch (state) { case BoyState.Idle: if (Animation == "pushstill" || Animation == "startpush" || Animation == "push") { Animation = "endpush"; if (soundCue != null) { soundCue.Stop(AudioStopOptions.Immediate); } } if (Animation == "control") { Animation = "controlend"; } if ((Animation == "endpush" || Animation == "controlend") && frame == 2 || Animation == "walk") { Animation = "stand"; } moveSpeedX = 0; moveSpeedY = 0; break; case BoyState.Walk: Animation = "walk"; moveSpeedX = 3; moveSpeedY = 0; control.hideDialogue(); break; case BoyState.StairsLeft: Animation = "walk"; moveSpeedX = 3; moveSpeedY = 2; drawLayer = DrawLayer.PlayerBehindStairs; break; case BoyState.StairsRight: Animation = "walk"; moveSpeedX = 3; moveSpeedY = -2; drawLayer = DrawLayer.PlayerBehindStairs; break; case BoyState.PushingStill: if (soundCue != null) { soundCue.Stop(AudioStopOptions.Immediate); } moveSpeedX = 0; moveSpeedY = 0; if (Animation == "walk" || Animation == "stand") Animation = "startpush"; if (Animation == "startpush" && frame == 3 || Animation == "push") Animation = "pushstill"; break; case BoyState.PushWalk: moveSpeedY = 0; if (Animation == "walk" || Animation == "stand") { moveSpeedX = 0; Animation = "startpush"; } if (Animation == "startpush" && frame == 3 || Animation == "pushstill") { Animation = "push"; pushSoundTimer = 201; } if (Animation == "push") moveSpeedX = 3; break; case BoyState.Teleport: moveSpeedX = 0; moveSpeedY = 0; if (Animation == "walk" || Animation == "stand") { Animation = "enterwardrobe"; Wardrobe targetWR = ((Wardrobe)interactor).getLinkedWR(); if (targetWR != null) { Rectangle target = targetWR.getBounds(); teleportTo = new Vector2(target.X + 16, target.Y + 24); interactor = null; } } if (Animation == "enterwardrobe" && frame == 6) { position = new Vector2(teleportTo.X, teleportTo.Y); Animation = "leavewardrobe"; } if (Animation == "leavewardrobe" && frame == 7) { Animation = "stand"; state = BoyState.Idle; } break; case BoyState.TimeTravel: moveSpeedX = 0; moveSpeedY = 0; if (Animation == "walk" || Animation == "stand") { Portrait p = (Portrait)interactor; if (p.wasMoved) teleportTo = p.movedPos; else teleportTo = new Vector2(); Animation = "enterportrait"; if (control.timePeriod == TimePeriod.Present) timeTravelTo = ((Portrait)interactor).sendTime; interactor = null; } if (Animation == "enterportrait" && frame == 7) { if (control.timePeriod != TimePeriod.Present) control.timePeriod = TimePeriod.Present; else control.timePeriod = timeTravelTo; Animation = "leaveportrait"; if (teleportTo.X != 0 && teleportTo.Y != 0) { X = teleportTo.X; Y = teleportTo.Y; } } if (Animation == "leaveportrait" && frame == 7) { Animation = "stand"; state = BoyState.Idle; } break; case BoyState.ControllingChair: moveSpeedX = 0; moveSpeedY = 0; if (Animation != "control") { Animation = "controlstart"; } if (Animation == "controlstart" && frame == 2) Animation = "control"; break; case BoyState.Die: moveSpeedX = 0; moveSpeedY = 0; Animation = "disappear"; if (frame == 7) { reset(); control.resetLevel(); } break; } if (frameTime >= frameLength) { int flip = 1; if (direction == Direction.Left) flip = -1; X += moveSpeedX * flip; if (state == BoyState.PushWalk && Animation == "push" && interactor != null) { pushSoundTimer += elapsed; Wardrobe w = (Wardrobe)interactor; if (!control.collidingWithSolid(w.pushBox, false)) { w.X += (int)(moveSpeedX * flip); if (pushSoundTimer > 200 && GameTitle.toggleSound) { soundCue = soundMan.playSound("Pushing Wardrobe", 0); pushSoundTimer = 0; } } else X -= moveSpeedX * flip; } if (moveSpeedY == 0) { moveSpeedY = 1; flip = 1; } Y += moveSpeedY * flip; frameTime = 0; frame = (frame + 1) % animFrames.Count; } }