AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

[DelphiX] Kollision

Ein Thema von Matze · begonnen am 9. Sep 2004 · letzter Beitrag vom 12. Sep 2004
 
Benutzerbild von Matze
Matze
(Co-Admin)

Registriert seit: 7. Jul 2003
Ort: Schwabenländle
14.929 Beiträge
 
Turbo Delphi für Win32
 
#2

Re: [DelphiX] Kollision

  Alt 10. Sep 2004, 10:42
Ich hab jetzt mal weiter Probiert, so weit bin ich gekommen:

Im Anhang die gepackte exe, damit ihr seht, wie "seltsam" sich die Figur verhält" und hier der ausschlaggebende Source:

Delphi-Quellcode:
//////////////////////////////////////////
// DOCANGO
//////////////////////////////////////////
procedure TAnimation.DoCanGo(Enabled: Boolean);
begin
  cangoleft := Enabled;
  cangoright := Enabled;
  cangoup := Enabled;
  cangodown := Enabled;
end;


//////////////////////////////////////////
// BEWEGUNG DER ANIMATION
//////////////////////////////////////////
procedure TAnimation.DoMove(MoveCount: integer);
begin
  inherited DoMove(MoveCount);

  If cangoup and (isUp in Form1.DXInput1.States) Then
    if not Jump then
    begin
      DoCanGo(true);
      Y := Y - Step;
    end;
  If cangodown and (isDown in Form1.DXInput1.States) Then
  begin
    DoCanGo(true);
   end;
  If cangoleft and (isLeft in Form1.DXInput1.States) Then
  begin
    DoCanGo(true);
    X := X - Step;
    if not Duck then
      Form1.AnimBild('Girl1left');
  end;
  If cangoright and (isRight in Form1.DXInput1.States) Then
  begin
    DoCanGo(true);
    X := X + Step;
    if not Duck then
      Form1.AnimBild('Girl1right');
  end;

  Collision;
end;


//////////////////////////////////////////
// KOLLISIONS-ABFRAGE
//////////////////////////////////////////
procedure TAnimation.DoCollision(Sprite: TSprite; var Done: Boolean);
begin
  DoCanGo(true);

  if (X < TGegenstand(Sprite).X - Step) then
  begin
    X := X - Step;
    cangoright := false;
  end;
  if (X > TGegenstand(Sprite).X + Step) then
  begin
    X := X + Step;
    cangoleft := false;
  end;
  if (Y + Animation.Height > TGegenstand(Sprite).Y + Step) then
  begin
    Y := Y + Step;
    cangoup := false;
    Jump := false;
  end;
  if (Y < TGegenstand(Sprite).Y + TGegenstand(Sprite).Height - Step) then
  begin
    Y := Y - Step;
    Hoehe := 0;
    cangodown := false;
  end;
end;


//////////////////////////////////////////
// TIMER
//////////////////////////////////////////
procedure TForm1.DXTimer1Timer(Sender: TObject; LagCount: Integer);
begin
  DXInput1.Update;
  DXSpriteEngine1.Move(1);
  DxDraw1.Surface.Fill(0);
  DXDraw1.Surface.Draw(0, 0, FSurface.ClientRect, FSurface, TRUE);
  DXSpriteEngine1.Draw;

  if Jump then
  begin
    InJump := true;
    Animation.Y := Animation.Y - Step;
    inc(Hoehe);
    if Hoehe = 30 then
      Jump := false;
  end else
  begin
    if cangodown then
    begin
      Animation.Y := Animation.Y + Step;
    end else
      InJump := false;
  end;

  DXDraw1.Flip;
end;


//////////////////////////////////////////
// FORM KEY DOWN
//////////////////////////////////////////
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if (key = vk_up) and not InJump and (Hoehe <= 30) then
  begin
    Jump := true;
    InJump := true;
  end;
  if key = vk_down then
  begin
    if not Duck then
      Bild := Animation.Image.Name;
    Ducken(true);
  end;
end;


//////////////////////////////////////////
// FORM KEY UP
//////////////////////////////////////////
procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key = vk_up then
  begin
    Jump := false;
    cangodown := true;
  end;
  if key = vk_down then
    Ducken(false);
end;
Ich habe absichtlich nicht den restlichen Quelltext angehängt, weil er Dinge enthält, die ich noch nicht unbedingt veröffentlichen möchte.

Dass man in der Luft bleibt, wenn man Pfeil-Hoch klickt, wird noch behoben.
Angehängte Dateien
Dateityp: zip project1_788.zip (323,6 KB, 27x aufgerufen)
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 20:00 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz