Archived

This topic is now archived and is closed to further replies.

nop_90h

First Time Isometric Tiling Engine Problem...

Recommended Posts

I have a 22*22 "arena" with Civ II sytle control with the mouse. How can I *accurately* detect which tile has been clicked on? My solution is "somewhat jumbled" and is only 90% accurate. You could just ignore my code and point me to an article/website, any help will be gratefully recieved. Be nice, this is my first try! It does work. Cheers, Nop_90h Here is the delphi code: - ++++++++++++++++++++++++++ function TForm1.CalcYcoord(X,Y:Integer):Integer; var StartY:Integer; begin StartY := (DX.SurfaceHeight div 2); Result := StartY + (TileImages.Items.Items[0].Height*Y - TileImages.Items.Items[0].Height*X) div 2; end; function TForm1.CalcXcoord(X,Y:Integer):Integer; var StartX:Integer; begin StartX := 3 - TileImages.Items.Items[0].Width; Result := StartX + (TileImages.Items.Items[0].Width*X + TileImages.Items.Items[0].Width *Y) div 2; end; procedure TForm1.DXMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var XTile,YTile:Double; SuccessfulMove: Boolean; Temp: TCharacter; Str: String[32]; begin SuccessfulMove := False; YTile := (Y - (DX.SurfaceHeight div 2)- (TileImages.Items.Items[0].Height div 2)) / TileImages.Items.Items[0].Height; XTile := (X - (3-TileImages.Items.Items[0].Width)) / TileImages.Items.Items[0].Width; X := Trunc(XTile) - Trunc(YTile); Y := Trunc(XTile) + Trunc(YTile); If (Abs(YTile - Trunc(YTile)) < 0.70 ) AND (Abs(YTile - Trunc(YTile)) > 0.30 ) Then begin If (Abs(XTile - Trunc(XTile)) > 0.70 ) Then begin Temp.X := X; Temp.Y := Y; If YTile > 0 Then Temp.Y := Temp.Y + 1 else Temp.X := Temp.X + 1; SuccessfulMove := True; end else If (Abs(XTile - Trunc(XTile)) < 0.30 ) Then begin Temp.X := X; Temp.Y := Y; If YTile > 0 Then Temp.X := Temp.X - 1 else Temp.Y := Temp.Y - 1; SuccessfulMove := True; end; end else IF (Abs(XTile - Trunc(XTile)) < 0.70 ) AND (Abs(XTile - Trunc(XTile)) > 0.30 ) Then begin Temp.X := X; Temp.Y := Y; SuccessfulMove := True; end;

Share this post


Link to post
Share on other sites
Try here. He (TANSTAAFL) even mentions that he got his method of tile selection from looking at how Civ II did it (don't that beat all).

[edited by - SysOp_1101 on August 5, 2003 11:39:14 PM]

Share this post


Link to post
Share on other sites
Cheers for that, missed it :S. Funnily enough my current method (as far as I can see) pretty similar to that, except for step 3 which was a stroke of genius! Maybe I played on CivII too much when I was about 11 and something rubbed off? Such a *classic* game...


Cheers, Nop_90h

Share this post


Link to post
Share on other sites