public void Update(GameTime gameTime) { //position += velocity; if(!isDead) inputUpdate(); bulletTimer++; for (int i = 0; i < 100; i++) { if (bullet[i] != null) bullet[i].Update(gameTime); } switch (playerState) { case 0: idleTimer += 1; myAnimatedSprite = defaultAnim; // make idle timer zero after any input if (idleTimer > 300) { myAnimatedSprite = smokingAnim; } else { myAnimatedSprite = breathingAnim; } break; case 1: myAnimatedSprite = walkingAnim; myAnimatedSprite.animComplete = true; break; case 2: myAnimatedSprite = meleeWeaponStandAnim[meleeWeaponType]; break; case 3: myAnimatedSprite = meleeWeaponStandAnim[meleeWeaponType]; break; case 4: myAnimatedSprite = rangeWeaponStandAnim[rangeWeaponType]; break; case 5: myAnimatedSprite = rangeWeaponWalkAnim[rangeWeaponType]; break; case 6: myAnimatedSprite = playerStompAnim; break; case 7: myAnimatedSprite = playerCrouchAnim; break; case 8: myAnimatedSprite = playerHandcuffAnim; break; case 9: myAnimatedSprite = playerDeathAnim; break; } if(playerState==2) { usingPipe = true; } else { usingPipe = false; } if (playerState == 9 || playerState == 7) { myAnimatedSprite.loopable = false; } else { myAnimatedSprite.loopable = true; } if (isDead) { playerState = 9; } if (position.Y + defaultTexture.Height >= 720) { hasJumped = false; } if (hasJumped == false) { velocity.Y = 0f; } myAnimatedSprite.Update(); }
void inputUpdate() { //if (meleeBlocked) //{ // meleeTimer++; // if (meleeTimer > 100) // { // meleeBlocked = false; // } //} KeyboardState newState = Keyboard.GetState(); MouseState mouseState = Mouse.GetState(); if (newState.Equals(new KeyboardState())) { //No keys are pressed. if(playerState != 9) playerState = 0; if (previousState != playerState) { myAnimatedSprite.currentFrame = 0; myAnimatedSprite.animComplete = false; previousState = playerState; } if (hasJumped) { float i = 1; velocity.Y += 0.15f * i; position.Y += velocity.Y; } oldAnimatedSprite = myAnimatedSprite; } if (newState.IsKeyDown(Keys.Right) || newState.IsKeyDown(Keys.D)) { idleTimer = 0; direction = 1; if (newState.IsKeyDown(Keys.X)) { meleeTimer = 0; meleeBlocked = true; playerState = 3; position.X += 30; if (previousState != playerState) { myAnimatedSprite.currentFrame = 0; myAnimatedSprite.animComplete = false; previousState = playerState; } oldAnimatedSprite = myAnimatedSprite; } else if ( (newState.IsKeyDown(Keys.C) || mouseState.RightButton == ButtonState.Pressed ) && ammoLeft > 0) { playerState = 5; if (previousState != playerState) { myAnimatedSprite.currentFrame = 0; myAnimatedSprite.animComplete = false; previousState = playerState; } shootBullet(); if (position.X < 6415) //Extend Level { velocity.X = speed; position += velocity; } oldAnimatedSprite = myAnimatedSprite; } else { playerState = 1; if (previousState != playerState) { myAnimatedSprite.currentFrame = 0; myAnimatedSprite.animComplete = false; previousState = playerState; } if (position.X < 6800 ) //Extend Level { velocity.X = speed; position += velocity; } oldAnimatedSprite = myAnimatedSprite; } } else if (newState.IsKeyDown(Keys.Left) || newState.IsKeyDown(Keys.A)) { idleTimer = 0; direction = -1; if (newState.IsKeyDown(Keys.X) || mouseState.LeftButton == ButtonState.Pressed ) { meleeTimer = 0; meleeBlocked = true; playerState = 3; if (previousState != playerState) { myAnimatedSprite.currentFrame = 0; myAnimatedSprite.animComplete = false; previousState = playerState; } position.X -= 30; oldAnimatedSprite = myAnimatedSprite; } else if (newState.IsKeyDown(Keys.C) && ammoLeft > 0) { playerState = 5; if (previousState != playerState) { myAnimatedSprite.currentFrame = 0; myAnimatedSprite.animComplete = false; previousState = playerState; } shootBullet(); if (position.X > -630 ) { velocity.X = -speed; position += velocity; } oldAnimatedSprite = myAnimatedSprite; } else { playerState = 1; if (previousState != playerState) { myAnimatedSprite.currentFrame = 0; myAnimatedSprite.animComplete = false; previousState = playerState; } if (position.X > -630 ) { velocity.X = -speed; position += velocity; } oldAnimatedSprite = myAnimatedSprite; } } else if(newState.IsKeyDown(Keys.Down) || newState.IsKeyDown(Keys.S)) { playerState = 7; if (previousState != playerState) { myAnimatedSprite.currentFrame = 0; myAnimatedSprite.animComplete = false; previousState = playerState; } oldAnimatedSprite = myAnimatedSprite; } else if (newState.IsKeyDown(Keys.E)) { playerState = 8; if (previousState != playerState) { myAnimatedSprite.currentFrame = 0; myAnimatedSprite.animComplete = false; previousState = playerState; } for (int i = 0; i < 100; i++) { if (myGame1.enemyRectangle[i].Intersects(myGame1.charRectangle)) { if (myGame1.AIPool[i].isFallen) { myGame1.AIPool[i].isCuffed = true; myGame1.AIPool[i].isFallen = false; myGame1.enemyRectangle[i].X = 20000; myGame1.enemyRectangle[i].Y = 20000; if (myGame1.AIPool[i].myAiOrientation == AI.aiOrientation.Bad) { myGame1.Score += 100; myGame1.numbersBad = true; } if (myGame1.AIPool[i].myAiOrientation == AI.aiOrientation.Good) { myGame1.Score -= 200; myGame1.numbersGood = true; } } } } oldAnimatedSprite = myAnimatedSprite; } else if (newState.IsKeyDown(Keys.Space)) { if (hitTimer > 60) { sndHit.Play(); //#sound hitTimer = 0; } playerState = 6; if (previousState != playerState) { myAnimatedSprite.currentFrame = 0; myAnimatedSprite.animComplete = false; previousState = playerState; } for (int i = 0; i < 100; i++) { if (myGame1.enemyRectangle[i].Intersects(myGame1.charRectangle)) { if (myGame1.AIPool[i].isFallen) { myGame1.AIPool[i].isDead = true; myGame1.AIPool[i].isFallen = false; myGame1.brutality = true; myGame1.enemyRectangle[i].X = 20000; myGame1.enemyRectangle[i].Y = 20000; } } } oldAnimatedSprite = myAnimatedSprite; } else { velocity.X = 0; if (newState.IsKeyDown(Keys.X)) { meleeTimer = 0; meleeBlocked = true; playerState = 2; if (previousState != playerState) { myAnimatedSprite.currentFrame = 0; myAnimatedSprite.animComplete = false; previousState = playerState; } if (direction == -1) { position.X -= 30; } else { position.X += 30; } idleTimer = 0; oldAnimatedSprite = myAnimatedSprite; } else if (newState.IsKeyDown(Keys.C) && ammoLeft > 0) { playerState = 4; if (previousState != playerState) { myAnimatedSprite.currentFrame = 0; myAnimatedSprite.animComplete = false; previousState = playerState; } shootBullet(); idleTimer = 0; oldAnimatedSprite = myAnimatedSprite; } } hitTimer++; /*if ((newState.IsKeyDown(Keys.Up) || newState.IsKeyDown(Keys.Space)) && hasJumped == false) { position.Y -= 10f; velocity.Y = -5f; hasJumped = true; idleTimer = 0; }*/ }
public Character(Texture2D newTexture, Vector2 newPosition) { defaultTexture = newTexture; position = newPosition; hasJumped = true; playerState = 0; previousState = 0; defaultAnim = new AnimatedSprite(defaultTexture, 1, 1, .1f); myAnimatedSprite = defaultAnim; oldAnimatedSprite = defaultAnim; ammoLeft = 10; meleeWeaponType = 0; rangeWeaponType = 0; }