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.