## isometric world experiment

BasicCoder2
Posts: 3405
Joined: Jan 01, 2009 7:03

### isometric world experiment

Some time ago I wrote a little example of cubes in an isometric world.

viewtopic.php?f=2&t=16086&hilit=block

Today I was thinking about how they implement isometric games and am sharing this little example. It consists of two types of objects, cubes and a cylinder. You have to imagine a 3D sprite as a 2D drawing of a 3D view of a character within a transparent cube. In this case the character is a cylinder shape. The cylinder "character" is actually 4 pixels taller than the cubes so you can see it behind a single cube.

The world is a 20x20x20 world made up of cube volumes. In this example it is filled randomly with some cubes. The cubes are then dropped by testing if there is anything under each cube. A spare area is found to place the cylinder. You can move the cylinder around with the cursor keys. On the right is a plan which shows where the cubes have landed and also shows the current position of the cylinder.

Actually I think a voxel world is made this way but with very small cubes of different colors?

What I have not implemented is the ability of the cylinder to jump onto a block maybe I will do that later.

Code: Select all

`'       z'       |'       |'       |'       +-------> x'      /'     /'    / y'screenres 1000,480,32dim shared as integer world(20,20,20)Dim As Uinteger c'code rgb colors of spritedim as uinteger sColor(7)sColor(0)=&HFFFF00FF 'pink transparent colorsColor(1)=&HFF010101 'blacksColor(2)=&HFF00FE00 'greensColor(3)=&HFF0000FE 'bluesColor(4)=&HFFFE0000 'redsColor(5)=rgb(0,12,232)  'dark bluesColor(6)=rgb(153,217,234) 'light blueDim Shared As Any Ptr blockImageblockImage = ImageCreate( 32, 32 ) ' allocate memory for 32x32 spritedim shared as any ptr cylindercylinder = imagecreate(31,36)dim shared as integer cylinderX,cylinderY'read block imageFor y As Integer = 0 To 31    For x As Integer = 0 To 31        Read c        Pset blockImage,(x,y), sColor(c)    Next xNext y'read cylinder imageFor y As Integer = 0 To 35    For x As Integer = 0 To 30        Read c        Pset cylinder,(x,y), sColor(c)    Next xNext yDim Shared As Integer cx,cycy = 160cx = 220Sub Set3DPixel(x As Integer,y As Integer,z As Integer,c As Uinteger)    Pset(x-y+cx,cy+y-z),cEnd SubSub line3D(x1 As Integer,y1 As Integer, z1 As Integer, x2 As Integer,y2 As Integer, z2 As Integer, c As Uinteger)    Line (x1-y1+cx,cy+y1-z1)-(x2-y2+cx,cy+y2-z2),cEnd SubSub box3D(x1 As Integer,y1 As Integer, z1 As Integer, x2 As Integer,y2 As Integer, z2 As Integer, c As Uinteger)    Line (x1-y1+cx,cy+y1-z1)-(x2-y2+cx,cy+y2-z2),c,bEnd SubSub putBlock(x As Integer,y As Integer,z As Integer)    Put (x*21-y*10+cx-20,cy+y*10-z*21-10),blockImage,transEnd SubSub putCylinder(x As Integer,y As Integer,z As Integer)    Put (x*21-y*10+cx-20,cy+y*10-z*21-14),cylinder,trans   '-4 to lift cylinder for its heightEnd Subsub randomBlocks()    dim as integer x,y,z    for z = 0 to 19        For y = 0 To 19            For x = 0 To 19                world(x,y,z)=int(rnd(1)*50)                if world(x,y,z)>0 then                    world(x,y,z)=0                else                    world(x,y,z)=1                end if            Next x        Next y    next zend subSub displayWorld()        Dim As Integer x,y,z,xx,yy    screenlock()    Cls        'draw x coordinate    z = 0:y=0    For x = 0 To 440        set3DPixel(x,y,z,rgb(255,255,255))    Next x        'draw z coordinate    x=0:y=0    For z = 0 To 440       set3DPixel(x,y,z,rgb(255,255,255))    Next z        'draw y coordinate    z = 0:x=0    For y = 0 To 210        set3DPixel(x,y,z,rgb(255,255,255))    Next y        line (430,370)-(430,479),rgb(255,255,255)    line (10,370)-(10,479),rgb(255,255,255)    line (10,370)-(430,370),rgb(255,255,255)    line (430,370)-(640,160),rgb(255,255,255)        'paint walls and floor    Paint (48,56),rgb(100,100,100),rgb(255,255,255)  'side wall    Paint (32,400),rgb(150,150,150),rgb(255,255,255) 'front    Paint (638,440),rgb(127,127,200),rgb(255,255,255) 'right side    Paint (270,20),rgb(90,90,90),rgb(255,255,255)  'back wall    Paint (240,190),rgb(100,10,0),rgb(255,255,255)  'table top        'draw floor grid    z = 0   ' for y as integer = 0 to 210 step 10    '    line3D(0,y,z,420,y,z,rgb(255,255,255))   ' next y       ' for x as integer = 0 to 420 step 21   '     line3D(x,0,z,x,210,z,rgb(255,255,255))   ' next x        for y = 0 to 19        For x = 0 To 19            For z = 0 To 19                If world(x,y,z)=1 Then                    putBlock(x,y,z)                End If                if world(x,y,z)=3 then                    putCylinder(x,y,z)                end if            Next        Next    next    locate 2,2    print cylinderX;"   ";cylinderY        'draw floor plan    for j as integer = 0 to 19        for i as integer = 0 to 19            if world(i,j,0)=0 then                line (i*16+650,j*16)-(i*16+16+650,j*16+16),rgb(255,100,0),bf            end if            if world(i,j,0)=1 then                line (i*16+650,j*16)-(i*16+16+650,j*16+16),rgb(0,200,255),bf            end if            if world(i,j,0)=3 then                circle (cylinderX*16+658,cylinderY*16+8),8,rgb(255,255,255),,,,f            end if        next i    next j        draw string (650,400),"CURSOR KEYS MOVE CYLINDER",rgb(255,255,255)    draw string (650,420),"HIT SPACE BAR FOR NEW WORLD",rgb(255,255,255)        screenunlock()End Subsub dropBlocks()    dim as integer dropFlag    dropFlag = 1    while dropFlag = 1        dropFlag = 0      'no drops        for z as integer = 1 to 19            For x as integer = 0 To 19                For y as integer = 0 To 19                    If world(x,y,z)=1 and world(x,y,z-1)=0 Then                        world(x,y,z)=0                        world(x,y,z-1)=1                        dropFlag = 1                    end if                Next y            Next x        next z        displayWorld()        sleep 20    wendend sub' MAIN PROGRAMDim As Double nowrandomBlocks()dropBlocks()   'find spare area on ground for cylinder to startdim as integer x,y,flagflag = 0while flag = 0    x = int(rnd(1)*20)    y = int(rnd(1)*20)    cylinderX = x    cylinderY = y    if world(x,y,0)=0 then        world(x,y,0)=3        flag = 1    end ifwenddisplayWorld()now = Timerdim as integer dx,dy,nx,ny,ddim as string keyDo    key = inkey    if key = " " then        randomBlocks()        dropBlocks()        'find spare area on ground for cylinder to start        dim as integer x,y,flag        flag = 0        while flag = 0            x = int(rnd(1)*20)            y = int(rnd(1)*20)            cylinderX = x            cylinderY = y            if world(x,y,0)=0 then                world(x,y,0)=3                flag = 1            end if        wend    end if    If TIMER>(now+0.1) Then        now = Timer        d = -1        'MOVE RIGHT        if multikey(&H20) or multikey(&H4D) then    '&H4D arrow right key            d = 0        end if                'MOVE LEFT        if multikey(&H1E) or multikey(&H4B) then    '&H4B arrow left key            d = 1        end if        ' UP        if multikey(&H11) or multikey(&H48) then             d= 2        end if        ' DOWN         if multikey(&H1F) or multikey(&H50) then             d = 3         end if         dx = 0        dy = 0        if d = 0 then dx =  1        if d = 1 then dx = -1        if d = 2 then dy = -1        if d = 3 then dy =  1                        nx = cylinderX + dx        ny = cylinderY + dy                if nx < 0  then nx = 0        if nx > 19 then nx = 19        if ny < 0  then ny = 0        if ny > 19 then ny = 19                if world(nx,ny,0)=0 then            world(cylinderX,cylinderY,0)=0   'empty where cylinder was            world(nx,ny,0)=3                 'move to new position            cylinderX = nx            cylinderY = ny        end if                            displayWorld()        sleep 2    End If    sleep 2    Loop Until multikey(&H01)End'block DATAData 0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0Data 0,0,0,0,0,0,0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,0Data 0,0,0,0,0,0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,3,1,0Data 0,0,0,0,0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,3,3,1,0Data 0,0,0,0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,3,3,3,1,0Data 0,0,0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,3,3,3,3,1,0Data 0,0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,3,3,3,3,3,1,0Data 0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,3,3,3,3,3,3,1,0Data 0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,3,3,3,3,3,3,3,1,0Data 0,1,2,2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0DATA 0,0,0,0,0,1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,1,0,0,0,0DATA 0,0,0,0,0,1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,1,0,0,0,0DATA 0,0,0,0,0,1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,1,0,0,0,0DATA 0,0,0,0,0,1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,1,0,0,0,0DATA 0,0,0,0,0,1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,1,0,0,0,0DATA 0,0,0,0,0,1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,1,0,0,0,0DATA 0,0,0,0,0,1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,1,0,0,0,0DATA 0,0,0,0,0,1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,1,0,0,0,0,0DATA 0,0,0,0,0,1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,1,0,0,0,0,0,0DATA 0,0,0,0,0,0,1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,1,1,0,0,0,0,0,0,0DATA 0,0,0,0,0,0,0,1,5,5,5,5,5,5,5,5,5,5,5,1,1,1,0,0,0,0,0,0,0,0,0DATA 0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0`
Last edited by BasicCoder2 on Oct 31, 2014 8:29, edited 1 time in total.
Lothar Schirm
Posts: 333
Joined: Sep 28, 2013 15:08
Location: Bavaria, Germany

### Re: isometric world experiment

Very impressive!
BasicCoder2
Posts: 3405
Joined: Jan 01, 2009 7:03

### Re: isometric world experiment

Lothar Schirm wrote:Very impressive!

But a long way from the impressive results of actual isometric games :)
I was just trying to get my head around the mechanics of an isometric game engine.
Here is an attempt at a larger world that scrolls a window over it with the idea of keeping the character (the cylinder in this case) centered on the screen. Instead of mapping to the screen directly it is mapped to a bitmap, bmpWorld, over which there is a 640x480 window which is positioned at (WINX,WINY) within the bitmap. The WINX and WINY values have to be computed to center the actual position of the cylinder image which is at location (cylinderX*20,clinderY*10) within the bmpWorld bitmap. WINX and WINY are computed in the main loop. The cylinder should be located at a fixed point shown by the yellow cross hairs but in fact it drifts so the computation is not quite right.

The size of the world can be changed by the constant values at the start. If made smaller than the display there is no scrolling required.

const WORLDX = 80
const WORLDY = 60
const WORLDZ = 20

Code: Select all

`'       z'       |'       |'       |'       +-------> x'      /'     /'    / y'screenres 640,480,32const WORLDX = 80const WORLDY = 60const WORLDZ = 20dim shared as integer WINX,WINY,WINW,WINH   'displacement into bmpWorldWINX = 0WINY = 0WINW = 640WINH = 480dim shared as integer BMAPW,BMAPHBMAPW = WORLDX*20+WORLDY*10BMAPH = WORLDY*20dim shared as integer world(WORLDX,WORLDY,WORLDZ)dim shared as any ptr bmpWorldbmpWorld = imagecreate(BMAPW,BMAPH)Dim As Uinteger c'code rgb colors of spritedim as uinteger sColor(7)sColor(0)=&HFFFF00FF 'pink transparent colorsColor(1)=&HFF010101 'blacksColor(2)=&HFF00FE00 'greensColor(3)=&HFF0000FE 'bluesColor(4)=&HFFFE0000 'redsColor(5)=rgb(0,12,232)  'dark bluesColor(6)=rgb(153,217,234) 'light blueDim Shared As Any Ptr blockImageblockImage = ImageCreate( 32, 32 ) ' allocate memory for 32x32 spritedim shared as any ptr cylindercylinder = imagecreate(31,36)dim shared as integer cylinderX,cylinderY'read block imageFor y As Integer = 0 To 31    For x As Integer = 0 To 31        Read c        Pset blockImage,(x,y), sColor(c)    Next xNext y'read cylinder imageFor y As Integer = 0 To 35    For x As Integer = 0 To 30        Read c        Pset cylinder,(x,y), sColor(c)    Next xNext yDim Shared As Integer cx,cycy = 0cx = WORLDY*10Sub Set3DPixel(x As Integer,y As Integer,z As Integer,c As Uinteger)    Pset bmpWorld,(x-y+cx,cy+y-z),cEnd SubSub line3D(x1 As Integer,y1 As Integer, z1 As Integer, x2 As Integer,y2 As Integer, z2 As Integer, c As Uinteger)    Line bmpWorld,(x1-y1+cx,cy+y1-z1)-(x2-y2+cx,cy+y2-z2),cEnd SubSub box3D(x1 As Integer,y1 As Integer, z1 As Integer, x2 As Integer,y2 As Integer, z2 As Integer, c As Uinteger)    Line bmpWorld,(x1-y1+cx,cy+y1-z1)-(x2-y2+cx,cy+y2-z2),c,bEnd SubSub putBlock(x As Integer,y As Integer,z As Integer)    Put bmpWorld,(x*21-y*10+cx-20,cy+y*10-z*21-10),blockImage,transEnd SubSub putCylinder(x As Integer,y As Integer,z As Integer)    Put bmpWorld,(x*21-y*10+cx-20,cy+y*10-z*21-14),cylinder,trans   '-4 to lift cylinder for its heightEnd Subsub randomBlocks()    dim as integer x,y,z    for z = 0 to WORLDZ-1        For y = 0 To WORLDY-1            For x = 0 To WORLDX-1                world(x,y,z)=int(rnd(1)*400)                if world(x,y,z)>0 then                    world(x,y,z)=0                else                    world(x,y,z)=1                end if            Next x        Next y    next zend subSub displayWorld()        Dim As Integer x,y,z,xx,yy    screenlock()    cls        line bmpWorld,(0,0)-(BMAPW-1,BMAPH-1),rgb(0,0,0),bf        'draw floor grid    z = 0    for y as integer = 0 to WORLDY*10 step 10       line3D(0,y,z,WORLDX*20,y,z,rgb(255,255,255))    next y        for x as integer = 0 to WORLDX*20 step 21        line3D(x,0,z,x,WORLDY*10,z,rgb(255,255,255))    next x        for y = 0 to WORLDY-1        For x = 0 To WORLDX-1            For z = 0 To WORLDZ-1                If world(x,y,z)=1 Then                    putBlock(x,y,z)                End If                if world(x,y,z)=3 then                    putCylinder(x,y,z)                end if            Next        Next    next        put (0,0),bmpWorld,(WINX,WINY)-(WINX+WINW-1,WINY+WINH-1),pset        locate 2,2    print cylinderX;"   ";cylinderY    'cross hairs on center of display    line (320,0)-(320,479),rgb(255,255,0)    line (0,240)-(639,240),rgb(255,255,0)    screenunlock()End Subsub dropBlocks()    dim as integer dropFlag    dropFlag = 1    while dropFlag = 1        dropFlag = 0      'no drops        for z as integer = 1 to WORLDZ-1            For x as integer = 0 To WORLDX-1                For y as integer = 0 To WORLDY-1                    If world(x,y,z)=1 and world(x,y,z-1)=0 Then                        world(x,y,z)=0                        world(x,y,z-1)=1                        dropFlag = 1                    end if                Next y            Next x        next z        displayWorld()        sleep 20    wendend sub' MAIN PROGRAMDim As Double nowrandomBlocks()dropBlocks()   'find spare area on ground for cylinder to startdim as integer x,y,flagflag = 0while flag = 0    x = int(rnd(1)*WORLDX)    y = int(rnd(1)*WORLDY)    cylinderX = x    cylinderY = y    if world(x,y,0)=0 then        world(x,y,0)=3        flag = 1    end ifwenddisplayWorld()now = Timerdim as integer dx,dy,nx,ny,ddim as string keyDo    key = inkey    if key = " " then        randomBlocks()        dropBlocks()        'find spare area on ground for cylinder to start        dim as integer x,y,flag        flag = 0        while flag = 0            x = int(rnd(1)*WORLDX)            y = int(rnd(1)*WORLDY)            cylinderX = x            cylinderY = y            if world(x,y,0)=0 then                world(x,y,0)=3                flag = 1            end if        wend    end if        If TIMER>(now+0.1) Then        now = Timer        d = -1        'MOVE RIGHT        if multikey(&H20) or multikey(&H4D) then    '&H4D arrow right key            d = 0        end if                'MOVE LEFT        if multikey(&H1E) or multikey(&H4B) then    '&H4B arrow left key            d = 1        end if        ' UP        if multikey(&H11) or multikey(&H48) then             d= 2        end if        ' DOWN         if multikey(&H1F) or multikey(&H50) then             d = 3         end if         dx = 0        dy = 0        if d = 0 then dx =  1        if d = 1 then dx = -1        if d = 2 then dy = -1        if d = 3 then dy =  1                        nx = cylinderX + dx        ny = cylinderY + dy                if nx < 0  then nx = 0        if nx > WORLDX-1 then nx = WORLDX-1        if ny < 0  then ny = 0        if ny > WORLDY-1 then ny = WORLDY-1                if world(nx,ny,0)=0 then            world(cylinderX,cylinderY,0)=0   'empty where cylinder was            world(nx,ny,0)=3                 'move to new position            cylinderX = nx            cylinderY = ny        end if        '========  scroll screen if required  ============                WINX = cylinderX*20 - (WINW\2) - cylinderY*10 + BMAPH\2                if WINX < 0 then WINX = 0        if WINX > (BMAPW - WINW) then WINX = (BMAPW - WINW)                WINY = cylinderY*10 - (WINH\2)                if WINY < 0 then WINY = 0        if WINY > (BMAPH - WINH) then WINY = (BMAPH - WINH)         '==================================================        displayWorld()        sleep 2    End If    sleep 2    Loop Until multikey(&H01)End'block DATAData 0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0Data 0,0,0,0,0,0,0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,0Data 0,0,0,0,0,0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,3,1,0Data 0,0,0,0,0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,3,3,1,0Data 0,0,0,0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,3,3,3,1,0Data 0,0,0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,3,3,3,3,1,0Data 0,0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,3,3,3,3,3,1,0Data 0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,3,3,3,3,3,3,1,0Data 0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,3,3,3,3,3,3,3,1,0Data 0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,3,3,3,3,3,3,3,3,1,0Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,3,3,3,3,3,3,3,3,1,0Data 1,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,1,3,3,3,3,3,3,3,3,3,1,0Data 1,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4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5,5,5,5,5,5,5,5,5,5,5,5,5,5,1,0,0,0,0DATA 0,0,0,0,0,1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,1,0,0,0,0DATA 0,0,0,0,0,1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,1,0,0,0,0DATA 0,0,0,0,0,1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,1,0,0,0,0DATA 0,0,0,0,0,1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,1,0,0,0,0,0DATA 0,0,0,0,0,1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,1,0,0,0,0,0,0DATA 0,0,0,0,0,0,1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,1,1,0,0,0,0,0,0,0DATA 0,0,0,0,0,0,0,1,5,5,5,5,5,5,5,5,5,5,5,1,1,1,0,0,0,0,0,0,0,0,0DATA 0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0`
BasicCoder2
Posts: 3405
Joined: Jan 01, 2009 7:03

### Re: isometric world experiment

While searching the internet for information on isometric worlds I noticed that they don't draw them the way I have illustrated above so now I am redoing the code.

This is a short example showing how to convert from normal coordinates to isometric coordinates.

Code: Select all

`screenres 640,480,32color rgb(0,0,0),rgb(255,255,255):clsdim as any ptr cubecube = imagecreate(34,36)dim as uinteger cfor j as integer = 0 to 35    for i as integer = 0 to 33        read c        if c = 0 then pset cube,(i,j),rgb(0,0,0)        if c = 1 then pset cube,(i,j),rgb(255,0,255)        if c = 2 then pset cube,(i,j),rgb(192,192,192)        if c = 3 then pset cube,(i,j),rgb(160,160,160)        if c = 4 then pset cube,(i,j),rgb(128,128,128)    next inext j'bload "cube2.bmp",cubedim as integer cx,cy     ' cx,cy origin on screen for isometric griddim as integer x,y,z     ' x,y of point on normal 3D gridcx = 320cy = 150z = 0'DRAW THE X-AXISfor y = 0 to 109 step 9    for x  = 0 to 109        pset(cx-y*2+x*2,y+x+cy-z),rgb(0,255,0)        pset(cx-y*2+x*2-1,y+x+cy-z),rgb(0,255,0)    next xnext y'DRAW THE Y-AXISfor x = 0 to 109 step 9    for y  = 0 to 109          pset(cx-y*2+x*2,y+x+cy-z),rgb(255,0,0)        pset(cx-y*2+x*2-1,y+x+cy-z),rgb(255,0,0)    next ynext xlocate 2,2print "HOLD ESC KEY DOWN TO FILL WITH BLOCKS"'NOW FILL FLOOR WITH CUBESfor y = 0 to 100 step 9    for x  = 0 to 100 step 9        put (cx-y*2+x*2-18,y+x+cy-18-z),cube,trans        sleep                              'comment out to speed it up    next xnext ywhile multikey(&H01):wend  'wait for release of esc keyDATA 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1DATA 1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,2,2,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1DATA 1,1,1,1,1,1,1,1,1,1,1,1,0,0,2,2,2,2,2,2,0,0,1,1,1,1,1,1,1,1,1,1,1,1DATA 1,1,1,1,1,1,1,1,1,1,0,0,2,2,2,2,2,2,2,2,2,2,0,0,1,1,1,1,1,1,1,1,1,1DATA 1,1,1,1,1,1,1,1,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,1,1,1,1,1,1,1,1DATA 1,1,1,1,1,1,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,1,1,1,1,1,1DATA 1,1,1,1,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,1,1,1,1DATA 1,1,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,1,1DATA 0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0DATA 0,0,2,2,2,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3,3,3,3,3,3,3,3,3,3,3,3,3,0DATA 0,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0DATA 0,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0DATA 0,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0DATA 0,0,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,0DATA 1,1,0,0,4,4,4,4,4,4,4,4,4,4,4,4,4,0,3,3,3,3,3,3,3,3,3,3,3,3,0,0,1,1DATA 1,1,1,1,0,0,4,4,4,4,4,4,4,4,4,4,4,0,3,3,3,3,3,3,3,3,3,3,0,0,1,1,1,1DATA 1,1,1,1,1,1,0,0,4,4,4,4,4,4,4,4,4,0,3,3,3,3,3,3,3,3,0,0,1,1,1,1,1,1DATA 1,1,1,1,1,1,1,1,0,0,4,4,4,4,4,4,4,0,3,3,3,3,3,3,0,0,1,1,1,1,1,1,1,1DATA 1,1,1,1,1,1,1,1,1,1,0,0,4,4,4,4,4,0,3,3,3,3,0,0,1,1,1,1,1,1,1,1,1,1DATA 1,1,1,1,1,1,1,1,1,1,1,1,0,0,4,4,4,0,3,3,0,0,1,1,1,1,1,1,1,1,1,1,1,1DATA 1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,4,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1DATA 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1`
tinram
Posts: 88
Joined: Nov 30, 2006 13:35
Location: UK

### Re: isometric world experiment

Yes, an impressive program for its size.
1000101
Posts: 2556
Joined: Jun 13, 2005 23:14

### Re: isometric world experiment

When writing isometric engines, one of the main issues you need to consider is z clipping using a standard X-by-Y methodology of tile engines. To both eliminate clipping and optimize render speed I calculate a "visible plot map" which is a single dimension array of z-ordered tile offsets from the centre of the viewport. The "top left" tile is the first plot in the array and the "bottom right" is the last entry in the array. The array is built such that it is drawing tiles in the scene based on scan lines of the viewport just like a "top down" tile engine.

This provides a method of rendering only exactly what you need (optimization) as well as insuring that "oversized" or "irregular" tiles are rendered in the proper z-order.

You already have everything you need to figure out how to generate your plot map, you just need to put it all together.
sean_vn
Posts: 283
Joined: Aug 06, 2012 8:26

### Re: isometric world experiment

I always wanted to write an isometric game, but somehow never figured out the concept correctly. I'll look at you code carefully and try to understand it. I haven't used FB for a while. I've been getting in some much needed practice with C and Java 8. I see things have moved ahead with FB. I just got FB up and running with 64 bit Linux. The Java 8/JNI/C/Assembly language combination has been working well for me. But I would like to go with the simplest thing.
I have neural net code now that is far out there. I'm getting rather highly compressed storage of recall patterns. I'd like to gain some extra money from it but experience shows that to be unlikely. Maybe I should provide it in open source form here after a few months. I think I should at least try to enact an application using it to try to generate cash.
I seem to have the British disease. That is an inability to commercialize innovation. The British guy who invented LCD screens didn't get a cent out of it. Google simply plagiarized a bunch of my work in their 'fastfood' paper. The lesson there is not to put your work on www .code .google . com, maybe not even put it on the web.
http://heyneonandroid.blogspot.com/
sean_vn
Posts: 283
Joined: Aug 06, 2012 8:26

### Re: isometric world experiment

I wanted to write an isometric game when I was a teenager using a Z80 chip, but I got really confused about painting order. I should go and figure it out now, much later in life. As for the neural net I'm getting about 20 to 1 compression of full scale images (at moderate quality) . That means it is realistic for such a neural net to learn a movie a few minutes in length on laptop hardware. You could not play back the movie at anything like full frame rate. Still I think it is something impressive. Java is starting to throw up some problems. I'm getting GUI thread deadlock when I open up entirely different applications such as a browser and memory management problems. I may shift back to FB and perhaps SDL 2. That would fit in with doing an isometric game too.
Posts: 1619
Joined: May 24, 2007 22:10
Location: The Netherlands

### Re: isometric world experiment

Weird, I get errors on the first two pieces of code:

fbc -exx -w all "Untitled2.bas" (in directory: /home/badidea/Desktop)
Compilation failed.
Untitled2.asm: Assembler messages:
Untitled2.asm:36: Error: `dword ptr [CX]' is not a valid base/index expression
Untitled2.asm:87: Error: `dword ptr [CX]' is not a valid base/index expression
Untitled2.asm:103: Error: `dword ptr [CX]' is not a valid base/index expression
Untitled2.asm:154: Error: `dword ptr [CX]' is not a valid base/index expression
Untitled2.asm:170: Error: `dword ptr [CX]' is not a valid base/index expression
Untitled2.asm:237: Error: `dword ptr [CX]' is not a valid base/index expression
Untitled2.asm:318: Error: `dword ptr [CX]' is not a valid base/index expression
Untitled2.asm:1706: Error: `dword ptr [CX]' is not a valid base/index expression

Only the last (third) piece runs here.

FreeBASIC Compiler - Version 1.00.0 (09-14-2014), built for linux-x86 (32bit)
Copyright (C) 2004-2014 The FreeBASIC development team.