/// <summary> /// Collision event handler for the crouching representation of the stick man's body. /// </summary> /// <param name="fixtureOne">The first colliding fixture.</param> /// <param name="fixtureTwo">The second colliding fixture.</param> /// <param name="contact">The contact object.</param> /// <returns>Whether the collision was accepted or not.</returns> private bool CollisionHandlerSmallBody(Fixture fixtureOne, Fixture fixtureTwo, Contact contact) { bool collided = true; if (fixtureTwo.CollisionCategories == EntityConstants.ScrollingDeathCategory) { collided = true; if (this.state != PlayerState.dead) { this.health = this.minimumHealth; this.state = PlayerState.dead; AudioManager.PlayEffect(this.dieSound); } } else if (this.state != PlayerState.crouching) { collided = false; } else { switch (fixtureTwo.CollisionCategories) { case EntityConstants.InteractiveEntityCategory: InteractiveEntityUserData entityData = (InteractiveEntityUserData)fixtureTwo.Body.UserData; if (entityData.IsActive) { collided = this.CollideWithInteractiveEntity(entityData); entityData.IsActive = false; fixtureTwo.Body.UserData = entityData; } else { collided = false; } break; case EntityConstants.MineCartCategory: collided = false; break; case EntityConstants.ExitCategory: fixtureTwo.Body.UserData = true; collided = false; break; default: collided = true; break; } } return(collided); }
/// <summary> /// Performs collision response with an interactive entity. /// </summary> /// <param name="entityData">The interactive entity's user data.</param> /// <returns>A value indicating whether the collision response should be computed by the physics engine or not.</returns> private bool CollideWithInteractiveEntity(InteractiveEntityUserData entityData) { bool collided = true; switch (entityData.EntityType) { case InteractiveEntityType.Obstacle: if (this.activePowerUp == PowerUpType.Invincibility || this.state == PlayerState.dead) { collided = false; } else { this.health -= (int)entityData.Value; if (this.health <= this.minimumHealth) { this.state = PlayerState.dead; AudioManager.PlayEffect(this.dieSound); } this.fullBody.ApplyForce(new Vector2(-70.0f, 0.0f)); collided = false; } break; case InteractiveEntityType.PowerUp: this.ResetPowerUpModifiers(); if (entityData.PowerUpType == PowerUpType.Jump) { this.jumpImpulse *= StickMan.JumpPowerModifier; } this.activePowerUp = entityData.PowerUpType; this.powerUpTimer = 0.0f; this.powerUpLength = entityData.Value; collided = false; break; case InteractiveEntityType.Bonus: this.Score += (int)entityData.Value; collided = false; break; default: break; } return(collided); }
/// <summary> /// Collision event handler for the stick man's wheel. /// </summary> /// <param name="fixtureOne">The first colliding fixture.</param> /// <param name="fixtureTwo">The second colliding fixture.</param> /// <param name="contact">The contact object.</param> /// <returns>Whether the collision was accepted or not.</returns> private bool CollisionHandlerWheel(Fixture fixtureOne, Fixture fixtureTwo, Contact contact) { bool collided = true; if (fixtureTwo.CollisionCategories == EntityConstants.ScrollingDeathCategory) { collided = true; if (this.state != PlayerState.dead) { this.health = this.minimumHealth; this.state = PlayerState.dead; AudioManager.PlayEffect(this.dieSound); } } else if (this.InCart) { collided = false; } else { switch (fixtureTwo.CollisionCategories) { case EntityConstants.PlatformCategory: collided = false; if (this.wheelCollisionDisabled != true && this.state != PlayerState.jumping && fixtureOne.Body.Position.Y < fixtureTwo.Body.Position.Y) { this.Land(); this.maximumHorizontalVelocity = this.standardHorizontalVelocity; this.onFloor = false; collided = true; } break; case EntityConstants.FloorCategory: this.Land(); this.maximumHorizontalVelocity = this.floorHorizontalVelocity; this.onFloor = true; collided = true; break; case EntityConstants.InteractiveEntityCategory: InteractiveEntityUserData entityData = (InteractiveEntityUserData)fixtureTwo.Body.UserData; if (entityData.IsActive) { collided = this.CollideWithInteractiveEntity(entityData); entityData.IsActive = false; fixtureTwo.Body.UserData = entityData; } else { collided = false; } break; case EntityConstants.MineCartCategory: if (!this.InCart && this.state != PlayerState.jumping) { this.LandInCart(fixtureTwo.Body); } collided = false; break; case EntityConstants.SwitchCategory: fixtureTwo.Body.UserData = true; collided = false; break; case EntityConstants.ExitCategory: fixtureTwo.Body.UserData = true; collided = false; break; default: collided = true; break; } } return(collided); }