Qbasicnews.com

Full Version: A serious programming problem here....
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I want to display tiles in isometric view, but the geometry involved boggles my mind.

Suppose I have a set of tiles and the following parameters:

screen.x.adj > x point position of where to start drawing
screen.y.adj > y point position of where to start drawing
y.max > tile amount in Y
x.max > tile amount in X
tile.size.x > X*Y size of tile sprite (mine is 32)
screen.x.max > tile display max in X direction
screen.y.max > tile display max in Y direction
blackspace.size > blank tile buffer between edge of view screen and tiles. (so that the uppermost (1,1) tile can be scrolled to)

I just don't understand at all how to figure out, given x.adj and y.adj, which tiles to draw...... maybe i'll figure it out later...... ideas?
Some time ago I attempted to make an isometric engine. I did not go much far, but I managed to display the 3D map.

Check it here (DQB included): ISOTEST
I can do that too. That's easy -- you just display the whole thing.

Problem is, which tiles to display when you're looking at a diamond through a window?
You can use the painter's algorihm. Simply order your objects by Z coordinate and paint them in reverse Z order. The nearest objects will overwrite the farthest. I know this is slow...
That's exactly what my code does, but Agamemnus knows how to do it...

What do you need, then? :???:
I guess what I want is..

given an X, Y give me an array of real--diamond-- (x, y) tiles to start from (top left to bottom right stripes) and the amount tiles in each band..
Tile size is 44x44 (actual 32x32, but it's rotated)

This is my code for a regular X*Y map, but how do I make it isometric? Sad

Code:
FOR x% = 1 TO view.max.x%
x1% = x% + view.adj.x%
addy% = 22 - addy%
FOR y% = 1 TO view.max.y%
y1% = y% + view.adj.y%
IF x1% > 0 THEN
IF y1% > 0 THEN
IF x1% < map.max.x% THEN
IF y1% < map.max.y% THEN
temp% = terrain(uglPGet(map, x1%, y1%)).imagestart%
uglPutMsk video.mask, addx% + x% * tilesize.x% + screen.adj.x%,
addy% + y% * 2 * tilesize.y% + screen.adj.y%, bmp.terrain(temp%)
END IF
END IF
END IF
NEXT y%
NEXT x%
You have to draw the tiles from back to front. Check the code I gave you.
hmmm.... this?

Code:
SUB PintaMapa (Mapa%(), Tiles%())
DQBclearLayer 1
FOR x% = 0 TO 9
FOR y% = 0 TO 9
IF Mapa%(-1, x%, y%) <> 0 THEN
DQBput 1, 160 + x% * 16 - y% * 16 - 16, 26 + 8 * y% + x% * 8,
VARSEG(Tiles%(0, 0)), VARPTR(Tiles%(0, 0))
END IF
NEXT y%, x%
FOR i% = 0 TO 4
FOR x% = 0 TO 9
FOR y% = 0 TO 9
IF Mapa%(i%, x%, y%) <> 0 THEN
DQBput 1, 160 + x% * 16 - y% * 16 - 16, 16 + 8 * y% + x% * 8 - i% * 10 ,
VARSEG(Tiles%(0, 1)), VARPTR(Tiles%(0, 1))
END IF
NEXT y%, x%, i%
END SUB

EDIT:

I tried to apply your method, but it's no good for maps that don't fit the screen. It always has a border (doesn't fill the whole screen)... I could just be doing it wrong.

EDIT, again: Just saw your second post. I'll try it.............
Yup.

Code:
FOR x% = 0 TO 9
FOR y% = 0 TO 9
IF Mapa%(-1, x%, y%) <> 0 THEN
DQBput 1, 160 + x% * 16 - y% * 16 - 16, 26 + 8 * y% + x% * 8,
VARSEG(Tiles%(0, 0)), VARPTR(Tiles%(0, 0))
END IF
NEXT y%, x%

This is the 1st loop which draws the floor. The tiles are ordered from left to right, then from top to bottom. That causes the tiles to draw from back to front.

160 + x% * 16 - y% * 16 - 16, 26 + 8 * y% + x% * 8

This is the formula.

Code:
x% = CENTER + x%*16 - 16*y% - 16
y% = TOP + 8*y% + x*8

'cause the tiles are 32x16, so:

Code:
x% = CENTER + x%*(W%\2) - (W%\2)*y% - 16
y% = TOP + (H%\2)*y% + (H%\2)*x%

The next FOR set just draws the tiles over the flor.
Pages: 1 2