public override void CollideWithObject(GameObject obj, Room room, BBox collision) { base.CollideWithObject(obj, room, collision); // ink blobs should smash into each other, but avoid awkward behavior with ink blobs // coming out of the same generator if (obj is InkBlob && !(obj is WaterBlob) && (obj.Color != Color)) room.Add(new InkBlob(Position, Vector2.Lerp(Velocity, obj.Velocity, 0.5f), Color.Combine(obj.Color), Vector2.Lerp(Size, obj.Size, 0.5f), shouldBounce)); room.Remove(this); }
public override void Update(Room room, GameTime gameTime) { lastPosition = Position; base.Update(room, gameTime); //Position = new Vector2(Position.X, maxHeightPos + (maxHeight - size.Y)); Move(room, Velocity); if ((Velocity.Y > 1 || Math.Abs(Vector2.Distance(lastPosition, Position)) < Math.Abs(Velocity.X / 2)) && !curAnimation.IsCalled("Disappear")) ChangeAnimation("Disappear"); if (curAnimation.IsCalled("Disappear") && curAnimation.IsDonePlaying()) room.Remove(this); }
public override void CollideWithWall(Room room) { ChangeAnimation(EXPLODE); Vector2 splatPosition = Position.ShoveToSide(size, velocity); if (!(this is WaterBlob)) // room.Splat(splatPosition, size, color, velocity); base.CollideWithWall(room); if (shouldBounce) { velocity *= -1; velocity = velocity.PushBack(BOUNCE_FRICTION * Vector2.One); size = size.PushBack(BOUNCE_SIZE_REDUCTION * Vector2.One); if (size == Vector2.Zero) room.Remove(this); } else room.Remove(this); }
public override void Update(Room room, GameTime gameTime) { if (curAnimation.IsCalled("Appear") && curAnimation.IsDonePlaying()) ChangeAnimation("Main"); else if (curAnimation.IsCalled("Main") && curAnimation.IsDonePlaying()) ChangeAnimation("Disappear"); else if (curAnimation.IsCalled("Disappear") && curAnimation.IsDonePlaying()) room.Remove(this); Move(room, Vector2.Zero); if (direction.X < 0) box = new BBox((int)(Position.X - SIZE_Y / 8 + 40), (int)(Position.Y - SIZE_X / 2), (int)SIZE_Y - 40, (int)SIZE_X); if (direction.X > 0) { box = new BBox((int)(Position.X - 50), (int)Position.Y, (int)SIZE_Y - 140, (int)SIZE_X); } base.Update(room, gameTime); }
private void ChangeYPosition(Room room) { bool shouldCollideWithGround = false; bool shouldCollideWithCeiling = false; // check for colliding against a wall if (Box.Position.Y + velocity.Y < minPosition.Y) shouldCollideWithCeiling = true; else if (Box.Position.Y + velocity.Y > maxPosition.Y) { // if we're falling off-stage, die if (maxPosition.Y + Box.Height*2 >= room.Height) { room.Remove(this); return; } // handle the ground collision after we've moved, to prevent weirdness when player is moving too fast shouldCollideWithGround = true; } Position = new Vector2(Position.X, MathHelper.Clamp(Box.Position.Y + velocity.Y, minPosition.Y, maxPosition.Y) + BoxOffset.Y); if (shouldCollideWithGround) { hasCollidedWithGround = true; CollideWithWall(room); CollideWithGround(room); } if (shouldCollideWithCeiling) { hasCollidedWithCeiling = true; CollideWithWall(room); CollideWithCeiling(room); } }