/// <summary> /// Determines the animation appropriate for the currentAction. Uses a switch as a crude state manager. /// </summary> void DetermineAnimation() { switch (CurrentAction) { case Action.idle: if (b_IsHooker) { CurrentAnimation = pIdle; } else { CurrentAnimation = Idle; } break; case Action.walk: CurrentAnimation = Walk; //keep moving until hit edge of screen if ((v2_Position.X > 64) && (v2_Position.X < 1920 - 64)) { if (b_FlipImage) { v2_Position.X--; } else { v2_Position.X++; } } else //if hit edge of screen, turn around b_FlipImage = (b_FlipImage) ? false : true; break; case Action.run: CurrentAnimation = Run; //keep moving until hit edge of screen if ((v2_Position.X > 64) && (v2_Position.X < 1920 - 64)) { if (b_FlipImage) { v2_Position.X -= 2; } else { v2_Position.X += 2; } } else //if hit edge of screen, turn around b_FlipImage = (b_FlipImage) ? false : true; break; case Action.crouch: CurrentAnimation = Crouch; break; case Action.sneak: CurrentAnimation = Sneak; break; case Action.punch: CurrentAnimation = Punch; //when to stop punching? after 1 punch? break; case Action.shiv: CurrentAnimation = Shiv; //when to stop shivving? ater 1 shiv? break; case Action.jump: CurrentAnimation = Jumping; //has to actually jump up //has to swap to jumpland after how long? when Y = floor level? break; case Action.jumpland: CurrentAnimation = JumpLand; break; case Action.block: CurrentAnimation = Block; break; case Action.talk: if (b_IsHooker) { CurrentAnimation = pTalk; } else CurrentAnimation = Idle; //non-prostitute AI has no talk animation, so will just stand still break; case Action.fall: if (b_IsHooker) { CurrentAnimation = pFall; if (PlayState.player.Position.X < Position.X) { v2_Position.X++; } else { v2_Position.X--; } } else CurrentAnimation = Block; break; case Action.fallen: if (b_IsHooker) { CurrentAnimation = pFallen; b_KnockingOut = true; if(!b_KnockedOut) { PlayerDisposition = 0; b_KnockedOut = true; } } break; default: if (b_IsHooker) { CurrentAnimation = pIdle; } else { CurrentAnimation = Idle; } break; } //Update the current animation. if the animation is different from the last animation, change the animation if(LastAction != CurrentAction) { SetAnimationStartPoint(CurrentAnimation.Start,CurrentAnimation.Frames,CurrentAnimation.TimeForCompletion); } }
/// <summary> /// Update the player class. /// </summary> /// <param name='Elapsed'> /// Elapsed time since last frame /// </param> /// public override void Update(float Elapsed) { if (b_PrisonOutfit) { tex_Image = Prison; } else { tex_Image = Casual; } // CurrentAction - Work it out based on input if (InputHandler.switchPressed && ShivFound && !wasSwap) { if (ShivEquipped) ShivEquipped = false; else ShivEquipped = true; wasSwap = true; } wasSwap = InputHandler.switchPressed; LastAction = CurrentAction; if (InputHandler.upPressed && !isJumping) { AudioManager.PlaySound ("Audio\\jump.wav"); isJumping = true; isPunching = false; GroundWhileJumping = v2_Position.Y; velocity.Y = -8; v2_Position.Y -= 5; CurrentAction = Action.jumpland; } else if (isJumping) { float time = (float)Elapsed; Vector2 Acceleration; Acceleration = ((velocity) / Mass + gravity); //velocity+= gravity*time; velocity += Acceleration * Elapsed; v2_Position.Y += velocity.Y;//*time; CurrentAction = Action.jump; if (InputHandler.rightPressed) { b_FlipImage = false; if (InputHandler.sprintPressed) { v2_Position.X += RunSpeed * Elapsed; } else { v2_Position.X += WalkSpeed * Elapsed; } } else if (InputHandler.leftPressed) { b_FlipImage = true; if (InputHandler.sprintPressed) { v2_Position.X -= RunSpeed * Elapsed; } else { v2_Position.X -= WalkSpeed * Elapsed; } } if (v2_Position.Y >= GroundWhileJumping - 5) { v2_Position.Y = GroundWhileJumping; velocity = Vector2.Zero; isJumping = false; CurrentAction = Action.jumpland; } } else if (isPunching) { PunchTiming -= Elapsed; if (PunchTiming <= 0) { isPunching = false; } } else if (InputHandler.punchPressed && !isPunching) { AudioManager.PlaySound ("Audio\\punch.wav"); if (InputHandler.downPressed) CurrentAction = Action.block; else if (ShivEquipped) { CurrentAction = Action.shiv; CurrentAnimation = Shiv; isPunching = true; } else { CurrentAction = Action.punch; CurrentAnimation = Punch; isPunching = true; } PunchTiming = CurrentAnimation.TimeForCompletion; } else if (InputHandler.downPressed) { CurrentAction = Action.crouch; if (InputHandler.punchPressed) { CurrentAction = Action.block; } else if (InputHandler.leftPressed || InputHandler.rightPressed) { CurrentAction = Action.sneak; if (InputHandler.rightPressed) { b_FlipImage = false; v2_Position.X += 5 * Elapsed; } else if (InputHandler.leftPressed) { b_FlipImage = true; v2_Position.X -= 5 * Elapsed; } } } //determine facing, as well as whether running or not. else if (InputHandler.leftPressed || InputHandler.rightPressed) { CurrentAction = Action.walk; if (InputHandler.sprintPressed) { CurrentAction = Action.run; } if (InputHandler.rightPressed) { b_FlipImage = false; if (CurrentAction == Action.run) { v2_Position.X += RunSpeed * Elapsed; } else { v2_Position.X += WalkSpeed * Elapsed; } } else if (InputHandler.leftPressed) { b_FlipImage = true; if (CurrentAction == Action.run) { v2_Position.X -= RunSpeed * Elapsed; } else { v2_Position.X -= WalkSpeed * Elapsed; } } } /*//Work out if jumping //Also need to work out if grounded else if() { //if right key or left key is also down, move in that direction midair }*/ else { CurrentAction = Action.idle; } switch (CurrentAction) { case Action.idle: CurrentAnimation = Idle; break; case Action.walk: CurrentAnimation = Walk; break; case Action.run: CurrentAnimation = Run; break; case Action.crouch: CurrentAnimation = Crouch; break; case Action.sneak: CurrentAnimation = Sneak; break; case Action.punch: CurrentAnimation = Punch; break; case Action.shiv: CurrentAnimation = Shiv; break; case Action.jump: CurrentAnimation = Jumping; break; case Action.jumpland: CurrentAnimation = JumpLand; break; case Action.block: CurrentAnimation = Block; break; default: CurrentAnimation = Idle; break; } //Update the current animation. if the animation is different from the last animation, change the animation if (LastAction != CurrentAction) { SetAnimationStartPoint (CurrentAnimation.Start, CurrentAnimation.Frames, CurrentAnimation.TimeForCompletion); } if (v2_Position.X <= 0) { v2_Position.X = 0; } if (v2_Position.X >= 1920 - 128) { v2_Position.X = 1920-128; } base.Update(Elapsed); }