Ver Mensaje Individual
  #3  
Antiguo 30-12-2008
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is offline
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - Espańa
Posts: 19.438
Reputación: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
Una posible rtuina de colisiones podría ser algo así:

Código Delphi [-]
// Calcular colisión entre dos objetos
function TForm1._CalculateColision(sh1, sh2:TShape): boolean;
var
  r1, r2, b1, b2:Integer;
begin

  Result := False;

  r1 := (sh1.Left + sh1.Width);
  r2 := (sh2.Left + sh2.Width);
  b1 := (sh1.Top + sh1.Height);
  b2 := (sh2.Top + sh2.Height);

  // COLISION?
  if (((sh1.Left < sh2.Left) and (r1 > sh2.Left)) and
      ((sh1.Top < sh2.Top) and (b1 > sh2.Top))) or

     (((sh2.Left < sh1.Left) and (r2 > sh1.Left)) and
      ((sh2.Top < sh1.Top) and (b2 > sh1.Top))) or

     (((sh1.Left < sh2.Left) and (r1 > sh2.Left)) and
      ((sh2.Top < sh1.Top) and (b2 > sh1.Top))) or

     (((sh2.Left < sh1.Left) and (r2 > sh1.Left)) and
      ((sh1.Top < sh2.Top) and (b1 > sh2.Top))) then begin


    Result := True;
  end;

end;

Está en Delphi y usa TShapes, pero es fácil de entender y creo que puedes pasarla a Builder y cambiar los TShape por TButton sin grandes problemas.
__________________
Germán Estévez => Web/Blog
Guía de estilo, Guía alternativa
Utiliza TAG's en tus mensajes.
Contactar con el Clubdelphi

P.D: Más tiempo dedicado a la pregunta=Mejores respuestas.

Última edición por Neftali [Germán.Estévez] fecha: 30-12-2008 a las 10:32:34.
Responder Con Cita