SRL Archive - SRL Archives

SolveMaze


JuKKa

2008-08-08 18:46:12

i noticed that there werent no Result := True in touchshrine motion detector… so i added that..

function TouchShrine: Boolean;
var
sx, sy, i: Integer;
p: TPoint;
arP: TPointArray;
ararP: T2DPointArray;
bmp1, bmp2: Integer;
begin
MMouse(249, 135, 5, 5);
Wait(200 + Random(200));
Result := IsUpText('Touch');

if Result then
begin
GetMousePos(sx, sy);
Mouse(sx, sy, 0, 0, True);
Wait(8000);
end else
begin
Writeln('Quick Shrine finding failed. Trying motion detector.');
bmp1 := BitmapFromString(MSX2 - MSX1, MSY2 - MSY1, '');
bmp2 := BitmapFromString(MSX2 - MSX1, MSY2 - MSY1, '');

CopyCanvas(GetClientCanvas, GetBitmapCanvas(bmp1), MSX1, MSY1, MSX2, MSY2, MSX1, MSY1, MSX2, MSY2);
Wait(500);
CopyCanvas(GetClientCanvas, GetBitmapCanvas(bmp2), MSX1, MSY1, MSX2, MSY2, MSX1, MSY1, MSX2, MSY2);
DisplayDebugImgWindow(MSX2 - MSX1, MSY2 - MSY1);
CopyCanvas(GetBitmapCanvas(bmp1), GetDebugCanvas, 0, 0, MSX2 - MSX1, MSY2 - MSY1, 0, 0, MSX2 - MSX1, MSY2 - MSY1);

for sx := 0 to MSX2 - MSX1 - 1 do
for sy := 0 to MSY2 - MSY1 - 1 do
if (FastGetPixel(bmp1, sx, sy) <> FastGetPixel(bmp2, sx, sy)) then
begin
SetLength(arP, Length(arP) + 1);
arP[High(arP)] := Point(sx, sy);
end;

ararP := SplitTPA(arP, 10);

SortATPAFromSize(ararP, 0, False);

for i := 0 to High(ararP) do
begin
p := MiddleTPA(ararP[i]);
MMouse(p.x, p.y, 0, 0);
Wait(200 + Random(200));
Result := IsUpText('Touch');
if result then
Break;
end;

if (i <> Length(ararP)) then
begin
Mouse(p.x, p.y, 0, 0, True);
Wait(8000);
end else
begin
Writeln('Shrine not found!');
end;
end;
end;

Wait(200 + Random(200));
Result := IsUpText('Touch');
if result then
Break;

i think sumilion has been little careless while writing the code :P BUT u did it!

thats the code i added…

Sumilion

2008-08-08 19:57:08

Hihi … watch your toung there ;) :D

Yeh thnx I'll add it.

P1nky

2008-08-08 20:54:10

Seriously lol JuKKa next dev BET lol

ZephyrsFury

2008-08-09 01:35:15

Something else I noticed:


CopyCanvas(GetClientCanvas, GetBitmapCanvas(bmp1), MSX1, MSY1, MSX2, MSY2, MSX1, MSY1, MSX2, MSY2);
Wait(500);
CopyCanvas(GetClientCanvas, GetBitmapCanvas(bmp2), MSX1, MSY1, MSX2, MSY2, MSX1, MSY1, MSX2, MSY2);

If you're copying to a bmp canvas wouldn't you want the destination area to be 0, 0, w, h? So something like this:


CopyCanvas(GetClientCanvas, GetBitmapCanvas(bmp1), MSX1, MSY1, MSX2, MSY2, 0, 0 , MSX2 - MSX1, MSY2 - MSY1);
Wait(500);
CopyCanvas(GetClientCanvas, GetBitmapCanvas(bmp2), MSX1, MSY1, MSX2, MSY2, 0, 0 , MSX2 - MSX1, MSY2 - MSY1);

Sumilion

2008-08-09 04:51:57

You're also right, commit it yourself :p (but let it be clear that the difference is minimal)

ZephyrsFury

2008-08-09 05:14:07

Ok… fixed and committed. :)