Hello,
Thank you Paul for the suggestion... I guess in my confusion I confused you as well sorry... Andorra 2d also top left origin... anyway I was banging my head against the wall the whole day (probably overcomplicating something that is not that complex...) . I've decided I give a try to what Traveler said before... to include direction in my testforwall function. And this time (kinda like a wonder) it really works :
TestWall function
Code:
function TBlurp.testForWall(spriteXpos,spriteYpos:single;spriteWidth,spriteHeight:integer;direction:string):boolean;
begin
testForWall := false;
if direction = 'left' then
begin
if not (TileInfo[round(spriteXpos) div 64, round(spriteYpos) div 64].tilenr in [2]) or not
(TileInfo[round(spriteXpos)div 64, (round(spriteYpos)+spriteHeight) div 64].tilenr in [2]) then testForWall := true;
end;
if direction = 'right' then
begin
if not(TileInfo[(round(spriteXpos)+spriteWidth) div 64, round(spriteYpos) div 64].tilenr in [2]) or not
(TileInfo[(round(spriteXpos)+spriteWidth) div 64, (round(spriteYpos)+spriteHeight) div 64].tilenr in [2]) then testForWall :=true;
end;
if direction = 'up' then
begin
if not (TileInfo[round(spriteXpos) div 64, round(spriteYpos) div 64].tilenr in [2]) or not
(TileInfo[(round(spriteXpos)+spriteWidth) div 64, round(spriteYpos) div 64].tilenr in [2]) then testForWall :=true;
end;
if direction = 'down' then
begin
if not (TileInfo[round(spriteXpos)div 64, (round(spriteYpos)+spriteHeight) div 64].tilenr in [2]) or not
(TileInfo[(round(spriteXpos)+spriteWidth) div 64, (round(spriteYpos)+spriteHeight) div 64].tilenr in [2]) then testForWall :=true;
end;
end;
controlling of character
Code:
ActTime := ActTime + AdPerCounter.TimeGap;
if ActTime > 25 then
begin
if GetKeyState(VK_LEFT) < 0 then
begin
if not Blurp.testForWall(Blurp.X-4,Blurp.Y,Blurp.Image.Width,Blurp.Image.Height-1,'left') then
begin
Blurp.X:=Blurp.X-4;
AdSpriteEngine.X:=AdSpriteEngine.X+4;
end;
end;
if GetKeyState(VK_RIGHT) < 0 then
begin
if not Blurp.testForWall(Blurp.X,Blurp.Y,Blurp.Image.Width,Blurp.Image.Height-1,'right') then
begin
Blurp.X:=Blurp.X+4;
AdSpriteEngine.X:=AdSpriteEngine.X-4;
end;
end;
if GetKeyState(VK_UP) < 0 then
begin
if not Blurp.testForWall(Blurp.X,Blurp.Y-4,Blurp.Image.Width-1,Blurp.Image.Height,'up') then
begin
Blurp.Y:=Blurp.Y-4;
AdSpriteEngine.Y:=AdSpriteEngine.Y+4;
end;
end;
if GetKeyState(VK_DOWN) < 0 then
begin
if not Blurp.testForWall(Blurp.X,Blurp.Y,Blurp.Image.Width-1,Blurp.Image.Height,'down') then
begin
Blurp.Y:=Blurp.Y+4;
AdSpriteEngine.Y:=AdSpriteEngine.Y-4;
end;
end;
ActTime := 0;
end;
Right now I'm doing the movement onIdle of TFORM ... which means I'm not using TimeGap for movement... which is bad I know, I just wanted to make it real simple for now (so that I can sleep well, that atleast I've acomplished half of what I wanted).... tomorrow I'll modify my code so that the movement is done in the Sprites.OnMove , and I only give x or y velocity here...
Anyway I've attached my code with the compiled executable, if I may ask you to please test it, it works. And I'm hoping it works just as well as the one you've suggested. (multiple solutions for the same problem).
egyszeru 7 5-os maskepp.zip
Greetings
Rob
Bookmarks