/// <summary> /// Creates a new BombEntity. /// </summary> /// <param name="start"></param> public BombEntity() { CanCollide = true; Animation = new PlayerIdleAnimation(); Size = Animation.SpriteSheet.CellSize; Size = Size * 0.5F; Origin.X = (Size.X - 72) / 2; Origin.Y = (Size.Y - 55) / 2; CollisionBox = new RectangleF(Origin.X, Origin.Y, 72, 55); }
/// <summary> /// Creates a new FlameCreature. /// </summary> public FlameCreature() { // Animations IdleAnimation = new FlameMoveAnimation(); MoveAnimation = new FlameMoveAnimation(); Animation = IdleAnimation; // Size Size = Animation.SpriteSheet.CellSize; Origin.X = (Size.X - 72) / 2; Origin.Y = (Size.Y - 55) / 2 + 30F; CollisionBox = new RectangleF(Origin.X, Origin.Y, 72, 55); _WaitTime = 0F; _HurtWaitTime = 0F; Velocity.X = 120F; }
/// <summary> /// Creates a new TurtleCreature. /// </summary> public TurtleCreature() { // Animations IdleAnimation = new TurtleIdleAnimation(); SneezeAnimation = new TurtleSneezeAnimation(); Animation = IdleAnimation; // Size Size = Animation.SpriteSheet.CellSize; Origin.X = (Size.X - 72) / 2; Origin.Y = (Size.Y - 55) / 2 + 20; CollisionBox = new RectangleF(Origin.X, Origin.Y, 72, 55); // Start _SneezeTime = 0.0f; _IdleTime = 5.0f; }
/// <summary> /// Creates a new SparkyCreature. /// </summary> public SparkyCreature() { // Animations IdleAnimation = new SparkyIdleAnimation(); ElectrocuteAnimation = new SparkyElectrocuteAnimation(); Animation = IdleAnimation; // Size Size = Animation.SpriteSheet.CellSize; Origin.X = (Size.X - 72) / 2; Origin.Y = (Size.Y - 55) / 2; CollisionBox = new RectangleF(Origin.X, Origin.Y, 72, 55); _InitialY = 0F; _InitialYSet = false; _HurtWaitTime = 0F; Reset(); }
/// <summary> /// Gets a list of Entities that are colliding with this Entity. /// </summary> /// <param name="entities">The entities to check.</param> /// <param name="offset">The amount to offset the current position when checking collisions.</param> /// <param name="entityOffset">The amount to offset other entities when checking collisions.</param> /// <returns>A list of entities that intersect.</returns> public List<Entity> GetCollidingEntities(List<Entity> entities, Vector2 offset, Vector2 entityOffset) { RectangleF boundingBox = new RectangleF(GlobalCollisionBox.X + offset.X, GlobalCollisionBox.Y + offset.Y, GlobalCollisionBox.Width, GlobalCollisionBox.Height); List<Entity> result = new List<Entity>(); foreach (Entity entity in entities) { RectangleF entityBoundingBox = new RectangleF(entity.GlobalCollisionBox.X + entityOffset.X, entity.GlobalCollisionBox.Y + entityOffset.Y, entity.GlobalCollisionBox.Width, entity.GlobalCollisionBox.Height); if (entity != this && entity.CanCollide && boundingBox.Intersects(entityBoundingBox)) { // INTERSECTION! result.Add(entity); } } return result; }
/// <summary> /// Gets whether this RectangleF intersects with another RectangleF. /// </summary> /// <param name="rectangle">The rectangle to check.</param> /// <returns>Whether the rectangles intersect.</returns> public bool Intersects(RectangleF rectangle) { return !(rectangle.Left > Right || rectangle.Right < Left || rectangle.Top > Bottom || rectangle.Bottom < Top); }
/// <summary> /// Draws a texture on the screen. /// </summary> /// <param name="position">The position to draw the texture at.</param> /// <param name="rotation">How much to rotate the drawn texture.</param> /// <param name="size">The size of the texture.</param> /// <param name="texture">The texture to draw.</param> /// <param name="section">The part of the texture to draw.</param> /// <param name="tint">The tint to apply to the texture.</param> /// <param name="effects">Effects to apply to the texture.</param> public void DrawTexture(Vector2 position, float rotation, Vector2 size, Texture2D texture, RectangleF section = null, Color? tint = null, SpriteEffects effects = SpriteEffects.None) { // Draws using a Vector to avoid per-pixel movement. Calculates scale based on section size. if(section == null) { section = new RectangleF(0, 0, texture.Width, texture.Height); } _SpriteBatch.Draw(texture, position, section, tint ?? Color.White, rotation, Vector2.Zero, new Vector2(size.X / section.Width, size.Y / section.Height), effects, 0F); }