Public feed #724308

collision

public text v1 · immutable
Raw Edit
·published 2007-10-03 14:13 UTC
rendered paste body
function TForm1.collision(): integer;
var
  i: integer;
begin
  //koda
  for i := 0 to length(objects[0]) -1 do begin
    //zgoraj na objektu - spodaj na osebi

    if (
          (objects[0][i] <= x_char + w_char) and
          (objects[0][i] + objects[2][i] > x_char) and
          (objects[1][i] > y_char_last + h_char) and
          (objects[1][i] <= y_char + h_char)
       )
    then begin
      //label6.Caption := 'Collision detected "up"';
      memo1.lines.add('Collision detected: up');
      y_collision := objects[1][i];
      Result := C_UP;
      break;

    //pod objektom, če objekt ni transparenten
    end else if
      (
          (objects[0][i] <= x_char + w_char) and
          (objects[0][i] + objects[2][i] > x_char) and
          (objects[1][i] + objects[3][i] < y_char_last) and
          (objects[1][i] + objects[3][i] >= y_char)
      )
    then begin
      memo1.lines.add('Collision detected: bottom');
      y_collision := objects[1][i] + objects[3][i];
      Result := C_BOTTOM;
      break;
    // desno od objekta
    end else if
      (
          (objects[1][i] + objects[3][i] > y_char) and
          (objects[1][i] < y_char + h_char) and
          (objects[0][i] + objects[2][i] < x_char_last +1) and
          (objects[0][i] + objects[2][i] >= x_char)
      )
    then begin
      memo1.lines.add('Collision detected: right');
      x_collision := objects[0][i] + objects[2][i];
      result := C_RIGHT;
      break;
    //levo od objekta - še ne deluje
    end else if
      (
          (objects[1][i] + objects[3][i] > y_char) and
          (objects[1][i] < y_char + h_char) and
          (objects[0][i] > x_char_last + w_char +1) and
          (objects[0][i] <= x_char + w_char)

      )
    then begin
      memo1.lines.add('Collision detected: right');
      result := C_LEFT;
      break;
    end else begin
      //label6.Caption := '';
      result := 0;
    end;
  end;
end;