/// <summary> /// the specific actions tile performs on collision /// </summary> /// <param name="entity"></param> /// <param name="col"></param> public override void OnCollision(MovingGameObject entity, GameObject col) { if (entity is Mario) { if (entity.BoundingBox.Bottom <= this.BoundingBox.Top + size) { entity.SetOnGround(true); if (entity.Stage == 0) { //entity.BoundingBox.Top/16 werkt niet omdat de mario sprite niet uit 16*16 vakjes bestaat entity.UpdatePositionY(BoundingBox.Top / size - entity.ObjectTexture.Height / size); } else { entity.UpdatePositionY(BoundingBox.Top / size - entity.ObjectTexture.Height / size - 0.5f); } } else if (entity.BoundingBox.Right <= this.BoundingBox.Left + size) { if (entity.Stage == 0) { entity.UpdatePositionX(BoundingBox.Left / size - entity.ObjectTexture.Width / size); } else { entity.UpdatePositionX(BoundingBox.Left / size - (entity.ObjectTexture.Width - 16) / size); } } else if (entity.BoundingBox.Left >= this.BoundingBox.Right - size) { entity.UpdatePositionX(BoundingBox.Right / size); } else if (entity.BoundingBox.Top <= this.BoundingBox.Bottom - size) { entity.UpdatePositionY(BoundingBox.Bottom / size); } } else { if (entity.BoundingBox.Bottom <= this.BoundingBox.Top + size) { entity.SetOnGround(true); entity.UpdatePositionY(entity.BoundingBox.Top / 16); } else if (entity.BoundingBox.Right <= this.BoundingBox.Left + size) { entity.movementDirection = true; } else if (entity.BoundingBox.Left >= this.BoundingBox.Right - size) { entity.movementDirection = false; } } }
/// <summary> /// Decides what action should happen based on the form of the collision /// </summary> /// <param name="entity"></param> /// <param name="col"></param> /// <param name="level"></param> public override void OnCollision(MovingGameObject entity, GameObject col, GameObject[,] level) { if (entity is Mario) { if (entity.BoundingBox.Bottom <= this.BoundingBox.Top + size) { entity.SetOnGround(true); if (entity.Stage == 0) { entity.UpdatePositionY(BoundingBox.Top / size - entity.ObjectTexture.Height / size); } else { entity.UpdatePositionY(BoundingBox.Top / size - entity.ObjectTexture.Height / size - 0.5f); } } else if (entity.BoundingBox.Top > this.BoundingBox.Bottom - size) { entity.UpdatePositionY(BoundingBox.Bottom / size + 1); if (_enabled == true) { PowerUp item = new PowerUp(MushroomTexture, FlowerTexture, (int)Position.X, (int)Position.Y - 1, entity.Stage + 1); level[(int)item.Position.X - 1, (int)item.Position.Y - 1] = item; _enabled = false; ObjectTexture = usedMysteryBlocktexture; totalFrames = 0; Columns = 1; } } else if (entity.BoundingBox.Left <= this.BoundingBox.Left) { entity.UpdatePositionX(BoundingBox.Left / size - entity.ObjectTexture.Width / size); } else if (entity.BoundingBox.Right >= this.BoundingBox.Right) { entity.UpdatePositionX(BoundingBox.Right / size); } } else if (entity is PowerUp) { if (entity.BoundingBox.Bottom <= this.BoundingBox.Top + size) { entity.SetOnGround(true); entity.UpdatePositionY(entity.BoundingBox.Top / 16); } } else if (entity is Koopa) { if (entity.BoundingBox.Bottom <= this.BoundingBox.Top + size) { entity.SetOnGround(true); entity.UpdatePositionY(entity.BoundingBox.Top / 16); } else if (entity.BoundingBox.Right <= this.BoundingBox.Left + size) { entity.movementDirection = true; } else if (entity.BoundingBox.Left >= this.BoundingBox.Right - size) { entity.movementDirection = false; } } }