1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type TForm1 = class(TForm) procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure FormCreate(Sender: TObject); procedure MoveChar(Sender: TObject; var Done: Boolean); procedure FormClose(Sender: TObject; var Action: TCloseAction); private { Private-Deklarationen } MoveToX: Integer; MoveToY: Integer; PositionX: Integer; PositionY: Integer; public { Public-Deklarationen } Background: TBitmap; Character: TBitmap; BildBuffer: TBitmap; end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin MoveToY := Y; MoveToX := X; end;
procedure TForm1.FormCreate(Sender: TObject); begin Background := TBitmap.Create; Background.LoadFromFile('monkey.bmp'); Character := TBitmap.Create; Character.LoadFromFile('guy.bmp'); BildBuffer := TBitmap.Create;
PositionX := 200; PositionY := 200;
Application.OnIdle := MoveChar; end;
procedure TForm1.MoveChar(Sender: TObject; var Done: Boolean); var TopLeft, BottomRight: TPoint; begin if (MoveToX = PositionX) and (MoveToY = PositionY) then Done := true else begin
Done := false; if (MoveToX > PositionX) then PositionX := PositionX + 3; if (MoveToX < PositionX) then PositionX := PositionX - 3; if (MoveToY > PositionY) then PositionY := PositionY + 3; if (MoveToY < PositionY) then PositionY := PositionY - 3; sleep(20);
BildBuffer.FreeImage; BildBuffer := Background;
TopLeft := Point(round(PositionX-Character.Width/2),PositionY-Character.Height); BottomRight := Point(round(PositionX+Character.Width/2),PositionY);
BildBuffer.Canvas.BrushCopy( Rect(TopLeft,BottomRight), Character, Rect(0,0,Character.Width,Character.Height), clWhite);
Form1.Canvas.BrushCopy(Rect(0, 0, 640, 400), BildBuffer, Rect(0,0,640,400), clWhite);
end; end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin //BildBuffer.Free; Background.Free; Character.Free; end;
end. |