3D Chequerboard in 2D

Previous topic - Next topic

Brick Redux

Its good to be back guys and here I present a Space Harrier style floor that moves.  Needs work but thats for you lot to deal with.

Cheers.

Mark

Code (glbasic) Select
/////////////////////////////////////////////////////////////////////////
//
// 3D Chequerboard in 2D
// A 50p Production
// in association with
// Jelly Babies and some coffee
//

GLOBAL dir, grid, size, jump, scale, ypos, zpos, xpos, tilex[], tiley[], tilez[], polyx[], polyy[]
GLOBAL color, whichcolor, still_free_of_ESC, needsomemorecoffee, andsomemoresugar
GOSUB setup

/////////////////////////////////////////////////////////////////////////
//
// Loop
//
//

WHILE still_free_of_ESC

GOSUB updatethegrid

GOSUB drawthegrid

SHOWSCREEN

WEND

/////////////////////////////////////////////////////////////////////////


SUB drawthegrid:

whichcolor=1

FOR x = 0 TO grid-2

INC whichcolor

IF whichcolor>2
whichcolor=1
ENDIF

color = whichcolor

FOR z = 0 TO grid-2

INC color

IF color>2
color=1
ENDIF

tx = tilex[x][z] / tilez[x][z]
ty = tiley[x][z] / tilez[x][z]

polyx[0]=tx ; polyy[0]=ty

tx = tilex[x+1][z] / tilez[x+1][z]
ty = tiley[x+1][z] / tilez[x+1][z]

polyx[1]=tx ; polyy[1]=ty

tx = tilex[x+1][z+1] / tilez[x+1][z+1]
ty = tiley[x+1][z+1] / tilez[x+1][z+1]

polyx[2]=tx ; polyy[2]=ty

tx = tilex[x][z+1] / tilez[x][z+1]
ty = tiley[x][z+1] / tilez[x][z+1]

polyx[3]=tx ; polyy[3]=ty
//////////////////////////////////////////////////////////////////
// Calculate color depth

shade=(ty/2)

IF shade<0
shade=50
ENDIF

IF color = 1
newcol=RGB(shade,shade,shade)
ELSE
newcol=RGB( 0,shade,0)
ENDIF

///////////////////////////////////////////////////////////////////
// Draw Tile
// cx & cy IN place but NOT used here for manipulating the board - ascend,descend,tilt left/right etc
//

STARTPOLY 0

POLYVECTOR  polyx[0]+cx,polyy[0]+cy,  0, 0,newcol

POLYVECTOR  polyx[1]+cx,polyy[1]+cy,  0, 0,newcol

POLYVECTOR  polyx[2]+cx,polyy[2]+cy,  0, 0,newcol

POLYVECTOR  polyx[3]+cx,polyy[3]+cy,  0, 0,newcol

ENDPOLY

NEXT
NEXT

ENDSUB


SUB updatethegrid:

jump = size / grid

zpos = 8

FOR z = 0 TO grid -1

xpos = scale

FOR x = 0 TO grid -1

tilex[x][z] = xpos
tiley[x][z] = ypos
tilez[x][z] = zpos

xpos = xpos + jump * scale

NEXT

INC zpos , -jump / 20

NEXT

INC size,dir

IF size<160 AND dir=0.1

INC size , 0.1 //....scrolls the board, erm sort of....cough

ELSE

dir=-0.1

ENDIF

IF size>150 AND dir=-0.1

DEC size , 0.1

ELSE

dir=0.1

ENDIF

ENDSUB


SUB setup:

dir=0.1 ; still_free_of_ESC=TRUE

grid = 30 ; size = 150

jump = size / grid ; scale = 25 ; ypos = 400 ; zpos = 8

DIM tilex[grid][grid] ; DIM tiley[grid][grid] ; DIM tilez[grid][grid] ; DIM polyx[9] ; DIM polyy[9]

ENDSUB


ark
A mournful owner of a HP HDX18 Laptop that has died...FECK!

mentalthink


Brick Redux

 :D

Its a real pleasure just for your replies.

:good:
A mournful owner of a HP HDX18 Laptop that has died...FECK!

Brick Redux

The cx and cy variables apart from being used to adjust hieght and slope can also produce warp effects to the grid.

One such effect I experimented with left a image similar to swirls/blades of grass.

Polyvector is a very powerful command indeed.
A mournful owner of a HP HDX18 Laptop that has died...FECK!

erico

I smell lotus around here... :P

Great snippet, maybe someday I could try a Feedback (msx2) remake with it. :good:

Brick Redux

Heres a scrolling version, needs streamlining.

Code (glbasic) Select
/////////////////////////////////////////////////////////////////////////
//
// 3D Chequerboard in 2D v.2
//
//
//
//

GLOBAL dir, grid, size, jump, scale, ypos, zpos, xpos, tilex[], tiley[], tilez[], polyx1[], polyy1[]
GLOBAL color, whichcolor, still_free_of_ESC, width, height, polyx2[], polyy2[], newcolor, newcolor1
GETSCREENSIZE width, height
GOSUB setup
GOSUB updatethegrid
/////////////////////////////////////////////////////////////////////////
//
// Loop
//
//

WHILE still_free_of_ESC



GOSUB drawthegrid

SHOWSCREEN

WEND

/////////////////////////////////////////////////////////////////////////


SUB drawthegrid:

whichcolor=1

FOR x = 0 TO grid-2

INC whichcolor

IF whichcolor>2
whichcolor=1
ENDIF

color = whichcolor

FOR z = 0 TO grid-2

INC color

IF color>2
color=1
ENDIF

tx = tilex[x][z] / tilez[x][z]
ty = tiley[x][z] / tilez[x][z]

polyx1[0]=-tx ; polyy1[0]=ty

polyx2[0]=tx ; polyy2[0]=ty

tx = tilex[x+1][z] / tilez[x+1][z]
ty = tiley[x+1][z] / tilez[x+1][z]

polyx1[1]=-tx ; polyy1[1]=ty

polyx2[1]=tx ; polyy2[1]=ty

tx = tilex[x+1][z+1] / tilez[x+1][z+1]
ty = tiley[x+1][z+1] / tilez[x+1][z+1]

polyx1[2]=-tx ; polyy1[2]=ty

polyx2[2]=tx ; polyy2[2]=ty

tx = tilex[x][z+1] / tilez[x][z+1]
ty = tiley[x][z+1] / tilez[x][z+1]

polyx1[3]=-tx; polyy1[3]=ty
polyx2[3]=tx; polyy2[3]=ty
//////////////////////////////////////////////////////////////////
// color

IF color = 1
newcol=RGB(255,255,255)
newcol1=RGB(0,0,180)
ELSE
newcol=RGB(0,0,180)
newcol1=RGB(255,255,255)
ENDIF

///////////////////////////////////////////////////////////////////
// Draw Tile
// cx & cy IN place but NOT used here for manipulating the board - ascend,descend,tilt left/right etc
//

STARTPOLY 0

POLYVECTOR  polyx1[0]+width/2,polyy1[0], 0, 0,newcol

POLYVECTOR  polyx1[1]+width/2,polyy1[1], 0, 0,newcol

POLYVECTOR  polyx1[2]+width/2,polyy1[2], 0, 0,newcol

POLYVECTOR  polyx1[3]+width/2,polyy1[3], 0, 0,newcol

ENDPOLY

STARTPOLY 0

POLYVECTOR  polyx2[0]+width/2,polyy2[0], 0, 0,newcol1

POLYVECTOR  polyx2[1]+width/2,polyy2[1], 0, 0,newcol1

POLYVECTOR  polyx2[2]+width/2,polyy2[2], 0, 0,newcol1

POLYVECTOR  polyx2[3]+width/2,polyy2[3], 0, 0,newcol1

ENDPOLY


NEXT
NEXT
///////////////////////////////////////////////////////////////////
// Scroll the grid
//
FOR z = 0 TO grid -1

FOR x = 0 TO grid -1

IF tilez[x][z]>0.23

DEC tilez[x][z] , 0.02

ELSEIF tilez[x][z]<0.23

tilez[x][z]=0.73 ; GOSUB updatethegrid

ENDIF

NEXT

NEXT


ENDSUB


SUB updatethegrid:

jump = size / grid

zpos = 8

FOR z = 0 TO grid -1

xpos = 10/scale

FOR x = 0 TO grid -1

tilex[x][z] = xpos
tiley[x][z] = ypos
tilez[x][z] = zpos

INC xpos, jump*scale

NEXT

INC zpos , -jump  / 20

NEXT

ENDSUB


SUB setup:

still_free_of_ESC=TRUE

grid = 30 ; size = 150

jump = size / grid ; scale = 35 ; ypos = 500 ; zpos = 8

DIM tilex[grid][grid] ; DIM tiley[grid][grid]
DIM tilez[grid][grid] ; DIM polyx1[9] ; DIM polyy1[9]
DIM polyx2[9] ; DIM polyy2[9]
ENDSUB


A mournful owner of a HP HDX18 Laptop that has died...FECK!