/// <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> /// The actions on collision between the entity and the colliding object col are excecuted here /// </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); entity.forcedJump = true; if (this.Stage == 0) { RightTexture = ShellTexture; LeftTexture = ShellTexture; Stage = 1; Position.Y++; Columns = 4; } // KoopaShell shell = new KoopaShell(col.ObjectTexture, (int)Position.X, (int)Position.Y - 1); //level[(int)shell.Position.X, (int)shell.Position.Y] = shell; else { moving = !moving; //entity.DoIllegalStuff(null); } } else if (entity.BoundingBox.Left <= this.BoundingBox.Left) { if (Stage == 0 || moving) { if (entity.Stage == 0) { entity.Die(); entity.lostLife = true; entity.UpdatePosition(1, 20); } else { entity.Stage--; } } else { movementDirection = false; moving = true; } } else if (entity.BoundingBox.Right >= this.BoundingBox.Right) { if (Stage == 0 || moving) { if (entity.Stage == 0) { entity.Die(); entity.lostLife = true; entity.UpdatePosition(1, 20); } else { entity.Stage--; } } else { movementDirection = true; moving = true; } } } else if (entity is Koopa) { if (entity.Stage == 1 && entity.moving) { 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.MakeMeNull(); } else if (entity.BoundingBox.Left >= this.BoundingBox.Right - size) { entity.MakeMeNull(); } } 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; } } }