/// <summary> /// The players attack function, functions differently depending on possession status /// </summary> public void Attack() { //Loop through enemies foreach (Enemy e in enemies) { if (e.IsNearest) { if (possession == PossessionStatus.None) { e.possessed = true; target = e; switch (e.monsterType) { case MonsterType.Lantern: possession = PossessionStatus.Lantern; return; case MonsterType.Sushi: possession = PossessionStatus.Sushi; return; case MonsterType.Sandals: possession = PossessionStatus.Sandals; return; } } } } }
/// <summary> /// Resets the player to life. /// </summary> /// <param name="position">The position to come to life at.</param> public void Reset(Vector2 position) { possession = PossessionStatus.None; Position = position; Velocity = Vector2.Zero; isAlive = true; sprite.PlayAnimation(idleAnimation); }
/// <summary> /// Handles input, performs physics, and animates the player sprite. /// </summary> /// <remarks> /// We pass in all of the input states so that our game is only polling the hardware /// once per frame. We also pass the game's orientation because when using the accelerometer, /// we need to reverse our motion when the orientation is in the LandscapeRight orientation. /// </remarks> public void Update( GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation) { GetInput(keyboardState, gamePadState, touchState, accelState, orientation); ApplyPhysics(gameTime); //Find nearest monster and highlight HighlightEnemy(); if (IsAlive && IsOnGround) { if (Math.Abs(Velocity.X) - 0.02f > 0) { sprite.PlayAnimation(runAnimation); } else { sprite.PlayAnimation(idleAnimation); } } //If the player is attacking if (isAttacking) { this.Attack(); } //If the player is depossessing if (dePossess) { target.isDead = true; possession = PossessionStatus.None; } // Clear input. movement = 0.0f; isJumping = false; isAttacking = false; dePossess = false; //Update attackRange this.attackRange.Y = BoundingRectangle.Y; if (direction == -1) { this.attackRange.X = BoundingRectangle.X - attackWidth; } else { this.attackRange.X = BoundingRectangle.X; } }