Hello, I've managed to do it... but still don't understand why the heck is it working
Code:
procedure TBlurp.DoCollision(Sprite:TSprite; var Done:boolean);
var
TileLeft, TileRight,
TileTop, TileBottom: Integer;
begin
if Sprite is TPlatform then
begin
TileLeft := Trunc(TPlatform(Sprite).X);
TileTop := Trunc(TPlatform(Sprite).Y);
TileRight := Trunc(TPlatform(Sprite).X) + TPlatform(Sprite).Image.Width;
TileBottom := Trunc(TPlatform(Sprite).Y) + TPlatform(Sprite).Image.Height;
// up
if (GetKeyState(VK_UP) < 0) then
begin
if (Self.Top+3 > TileBottom) and
(Self.Right > TileLeft) and
(Self.Left < TileRight) then
begin
Y := TileBottom;
end;
end;
// down
if (GetKeyState(VK_DOWN) < 0) then
begin
if (Self.Bottom -3 < TileTop ) and
(Self.Right > TileLeft) and
(Self.Left < TileRight) then
begin
Y := TileTop-PlayerH;
end;
end;
// left
if GetKeyState(VK_LEFT) < 0 then
begin
if (Self.Left+3 > TileRight) and
(Self.Top< TileBottom) and
(Self.Bottom>TileTop) then
begin
X := TileRight;
end;
end;
// right
if GetKeyState(VK_RIGHT) < 0 then
begin
if (Self.Right-3 < TileLeft )and
(Self.Top< TileBottom) and
(Self.Bottom>TileTop) then
begin
X := TileLeft -PlayerW;
end;
end;
end;
end;
it works like 99% of the time... sometimes, I can't seem to reproduce it every time I'm able to enter the tile....pfff
EDIT : by increasing left and right to +3 and -3 it seems I'm unable to enter the wall now...evern after trying to quiet a while...
my character is 30x60...
Greetings
Robert
unSimple 0.1.zip
Bookmarks