/// <summary> /// Initializes a new instance of the <see cref="PowerUp"/> class. /// </summary> /// <param name="physicsWorld">The physics world.</param> /// <param name="spriteBatch">The sprite batch to use for rendering.</param> /// <param name="contentManager">The game's content manager.</param> /// <param name="description">The entity description.</param> /// <param name="settings">The power up settings.</param> public PowerUp(ref World physicsWorld, SpriteBatch spriteBatch, ContentManager contentManager, InteractiveEntityDescription description, PowerUpSetting settings) : base(ref physicsWorld, description) { this.name = settings.Name; this.timeOfEffect = settings.TimeOfEffect; switch (this.name) { case EntityConstants.InvincibleName: this.type = PowerUpType.Invincibility; break; case EntityConstants.HealthName: this.type = PowerUpType.Health; break; case EntityConstants.JumpName: this.type = PowerUpType.Jump; break; case EntityConstants.SpeedName: this.type = PowerUpType.Speed; break; default: this.type = PowerUpType.None; break; } this.PhysicsBody.UserData = new InteractiveEntityUserData(InteractiveEntityType.PowerUp, this.timeOfEffect, this.type); this.InitializeAndLoad(spriteBatch, contentManager); }
/// <summary> /// Initializes a new instance of the <see cref="InteractiveEntity"/> class. /// </summary> /// <param name="physicsWorld">The physics world.</param> /// <param name="description">The description of the entity.</param> public InteractiveEntity(ref World physicsWorld, InteractiveEntityDescription description) { this.destroyed = false; this.Sound = null; this.Sprite = new Sprite(); this.SetUpPhysics(ref physicsWorld, description); }
/// <summary> /// Adds an interactive entity to the level. /// </summary> /// <param name="name">The name of the entity.</param> /// <param name="position">The position of the entity.</param> /// <param name="size">The size of the entity in display coordinates.</param> public void AddInteractiveEntity(string name, Vector2 position, Vector2 size) { InteractiveEntityDescription entityDescription = new InteractiveEntityDescription(); entityDescription.Position = position; entityDescription.Name = name; entityDescription.Dimensions = size; this.interactiveEntityDescriptions.Add(entityDescription); }
/// <summary> /// Initializes a new instance of the <see cref="BonusOrObstacle"/> class. /// </summary> /// <param name="physicsWorld">The physics world.</param> /// <param name="spriteBatch">The sprite batch to use for rendering.</param> /// <param name="contentManager">The game's content manager.</param> /// <param name="description">The entity description.</param> /// <param name="setting">The entity's settings.</param> public BonusOrObstacle(ref World physicsWorld, SpriteBatch spriteBatch, ContentManager contentManager, InteractiveEntityDescription description, ObstacleOrBonusSetting setting) : base(ref physicsWorld, description) { this.Type = setting.IsBonus ? InteractiveEntityType.Bonus : InteractiveEntityType.Obstacle; this.name = setting.Name; this.Value = setting.Value; this.PhysicsBody.UserData = new InteractiveEntityUserData(this.Type, this.Value); this.InitializeAndLoad(spriteBatch, contentManager); }
/// <summary> /// Draws an interactive entity. /// </summary> /// <param name="entityDescription">The entity's description.</param> private void DrawInteractiveEntity(InteractiveEntityDescription entityDescription) { switch (entityDescription.Name) { case EntityConstants.FireName: Camera2D.Draw(this.fireSprite, entityDescription.Position, 0.0f); break; case EntityConstants.SpikeName: Camera2D.Draw(this.spikeSprite, entityDescription.Position, 0.0f); break; case EntityConstants.RockName: Camera2D.Draw(this.rockSprite, entityDescription.Position, 0.0f); break; case EntityConstants.InvincibleName: Camera2D.Draw(this.invincibleSprite, entityDescription.Position, 0.0f); break; case EntityConstants.HealthName: Camera2D.Draw(this.healthSprite, entityDescription.Position, 0.0f); break; case EntityConstants.SpeedName: Camera2D.Draw(this.speedSprite, entityDescription.Position, 0.0f); break; case EntityConstants.JumpName: Camera2D.Draw(this.jumpSprite, entityDescription.Position, 0.0f); break; case EntityConstants.CoinName: Camera2D.Draw(this.coinSprite, entityDescription.Position, 0.0f); break; case EntityConstants.DiamondName: Camera2D.Draw(this.diamondSprite, entityDescription.Position, 0.0f); break; case EntityConstants.RubyName: Camera2D.Draw(this.rubySprite, entityDescription.Position, 0.0f); break; case EntityConstants.Switch: Camera2D.Draw(this.switchSprite, entityDescription.Position, 0.0f); break; case EntityConstants.CartBody: Camera2D.Draw(this.cartSprite, entityDescription.Position, 0.0f); break; default: break; } }
/// <summary> /// Adds a switch to the level. /// </summary> /// <param name="position">The position of the entity.</param> /// <param name="size">The size of the entity in display coordinates.</param> public void AddSwitch(Vector2 position, Vector2 size) { if (this.switchIndex == -1) { this.switchIndex = this.interactiveEntityDescriptions.Count; InteractiveEntityDescription entityDescription = new InteractiveEntityDescription(); entityDescription.Position = position; entityDescription.Name = EntityConstants.Switch; entityDescription.Dimensions = size; this.interactiveEntityDescriptions.Add(entityDescription); } else { this.interactiveEntityDescriptions[this.switchIndex].Position = position; this.interactiveEntityDescriptions[this.switchIndex].Dimensions = size; } }
/// <summary> /// Sets up the physics body for an interactive entity. /// </summary> /// <param name="physicsWorld">The physics world to create the body in.</param> /// <param name="description">The description of the interactive entity.</param> protected virtual void SetUpPhysics(ref World physicsWorld, InteractiveEntityDescription description) { this.PhysicsBody = BodyFactory.CreateRectangle(physicsWorld, ConvertUnits.ToSimUnits(description.Dimensions.X), ConvertUnits.ToSimUnits(description.Dimensions.Y), 3.0f, ConvertUnits.ToSimUnits(description.Position)); this.PhysicsBody.CollisionCategories = EntityConstants.InteractiveEntityCategory; }