Hello,
After reading a few tile based collision detection tutorials with smooth scrolling enabled...I realized , that I need to check collisions based on direction I'm traveling in ( this might not work if I go both X,Y at same time, but for now I don't really care, one step at a time and not get overwhelmed)
So right now I kinda hacked my own code... which is ugly
Code:
procedure TMain.DrawMonster;
var i : integer;
begin
// re-draw monster at new position
for i := 0 to length(Monster)-1 do
begin
// AI[i].Top:=Monster[i].StartY*(Panel2.Height div 15);
// AI[i].Left:=Monster[i].StartX*(Panel2.Width div 20);
AI[i].Top:=AI[i].Top+Monster[i].VelocityY;
AI[i].Left:=AI[i].Left+Monster[i].VelocityX;
if (Monster[i].SetDir = dDown) or (Monster[i].SetDir = DRight) then
begin
Monster[i].PositionY:=AI[i].Top div (Panel2.Height div 15);
Edit2.Text:=inttostr(Monster[i].PositionY);
Monster[i].PositionX:=AI[i].Left div (panel2.Width div 20);
Edit3.Text:=inttostr(Monster[i].PositionX);
end;
if (Monster[i].SetDir = dUp) or (Monster[i].SetDir = DLeft) then
begin
Monster[i].PositionY:=(AI[i].Top+(AI[i].Height-1)) div (Panel2.Height div 15);
Edit2.Text:=inttostr(Monster[i].PositionY);
Monster[i].PositionX:=(AI[i].Left+(AI[i].Width-1)) div (panel2.Width div 20);
Edit3.Text:=inttostr(Monster[i].PositionX);
end;
end;
My mistake up till now, and with all my previous attempts as well was this
when I calculated bottom and right side I simply did LEFT+WIDTH or TOP+WIDTH...which
in the case of a 32x32 tile
which has top,left 1,1
resulted in a bottom,right 33,33 I know it seems so stupid now, but somehow I did not see it...
that Is why now I add to left and top , height-1 and width-1...so I
get 1,1 and 32,32...
I tried it and it works...on the far right corner of the level there is no perfect touch on my monitor 1920x1080, but that is probably because (or 99% sure) my tile sizes are not n2...
so I guess I did It...this will work nicely at 640x480 with 32x32 tiles...
I'll modify my class in the upcoming days..to handle this calculation inside it...and not like this
Greetings
Robert
Bookmarks