public static void ColideBloco(Geral x1, Geral x2, bool ajustarZindex) { catX = (x1.x + (x1.width / 2)) - (x2.x + (x2.width / 2)); catY = (x1.y + (x1.height / 2)) - (x2.y + (x2.height / 2)); sumHalfWidth = (x1.width / 2) + (x2.width / 2); sumHalfHeight = (x1.height / 2) + (x2.height / 2); if (Math.Abs(catX) <= sumHalfWidth && Math.Abs(catY) <= sumHalfHeight) { overlapX = sumHalfWidth - Math.Abs(catX); overlapY = sumHalfHeight - Math.Abs(catY); if (x2.GetType().Name == "Bullet" && V.bullets.IndexOf((Bullet)x2) != -1 && x2 != null) { x1.Interagir(x2); } else if (x2.GetType().Name == "Enemy" && x1.GetType().Name == "Player") { x1.vidas = x2.vidas = 0; } else if (x2.GetType().Name == "Bonus") { x2.Interagir(x1); } if (overlapX >= overlapY) { x1.y = (catY > 0) ? x2.y + x2.height : x1.y = x2.y - x1.height; } else { x1.x = (catX > 0 && x1.x + (x1.width / 2) >= x2.x) ? x2.x + x2.width : x2.x - x1.width; } } }
public static void ColideBloco(Geral x1, Geral x2, bool ajustarZindex) { catX = (x1.x + (x1.width / 2)) - (x2.x + (x2.width / 2)); catY = (x1.y + (x1.height / 2)) - (x2.y + (x2.height / 2)); sumHalfWidth = (x1.width / 2) + (x2.width / 2); sumHalfHeight = (x1.height / 2) + (x2.height / 2); if (Math.Abs(catX) <= sumHalfWidth && Math.Abs(catY) <= sumHalfHeight && !x1.pausado) { overlapX = sumHalfWidth - Math.Abs(catX); overlapY = sumHalfHeight - Math.Abs(catY); x2.Interagir(0); if (overlapX >= overlapY) { if (catY > 0) { x1.y = x2.y + x2.height; if (x == Configuracoes.controle && x1.direcao == 1 && F.Key("x") && !F.TeclaDesativada("x")) { x2.Interagir(1); F.DesativarTecla("x", 500); } } else { x1.y = x2.y - x1.height; if (x == Configuracoes.controle && x1.direcao == 0 && F.Key("x") && !F.TeclaDesativada("x")) { x2.Interagir(1); F.DesativarTecla("x", 500); } } } else { if (catX > 0 && x1.x + (x1.width / 2) >= x2.x) { x1.x = x2.x + x2.width; if (x == Configuracoes.controle && x1.direcao == 3 && F.Key("x") && !F.TeclaDesativada("x")) { x2.Interagir(1); F.DesativarTecla("x", 500); } } else { x1.x = x2.x - x1.width; if (x == Configuracoes.controle && x1.direcao == 2 && F.Key("x") && !F.TeclaDesativada("x")) { x2.Interagir(1); F.DesativarTecla("x", 500); } } } } if (ajustarZindex) { catX = ((x1.x + x1.adcX) + (x1.imgWidth / 2)) - ((x2.x + x2.adcX - 140) + ((280 + x2.imgWidth) / 2)); catY = ((x1.y + x1.height - x1.imgHeight) + (x1.imgHeight / 2)) - ((x2.y + x2.height) + 70); sumHalfWidth = (x1.imgWidth / 2) + ((280 + x2.imgWidth) / 2); sumHalfHeight = (x1.imgHeight / 2) + 70; if (Math.Abs(catX) < sumHalfWidth && Math.Abs(catY) < sumHalfHeight) { x1.zindex = x2.zindex + 1; x1.qtdObj++; } } }