coding help

Previous topic - Next topic

namco

Sorry didn't know where to put this.

I'm making a tile based engine and I was testing out my code. It should draw 6 tiles across by 6 tiles down but I'm only getting 2 tiles across and 6 tiles down.

Code:

Code (glbasic) Select

        LOADSPRITE "tileTest.bmp", 1
LOADSPRITE "tileTest2.bmp", 2
LOADSPRITE "grass_and_street.bmp", 3
LOADSPRITE "grass.bmp", 4

        DIM townCenter[6][6]

townCenter[0][0] = 4
townCenter[0][1] = 3
townCenter[0][2] = 1
townCenter[0][3] = 2
townCenter[0][4] = 3
townCenter[0][5] = 4

townCenter[1][0] = 4
townCenter[1][1] = 3
townCenter[1][2] = 1
townCenter[1][3] = 2
townCenter[1][4] = 3
townCenter[1][5] = 4

townCenter[2][0] = 1
townCenter[2][1] = 2
townCenter[2][2] = 4
townCenter[2][3] = 4
townCenter[2][4] = 2
townCenter[2][5] = 1

townCenter[3][0] = 1
townCenter[3][1] = 2
townCenter[3][2] = 4
townCenter[3][3] = 4
townCenter[3][4] = 2
townCenter[3][5] = 1

townCenter[4][0] = 4
townCenter[4][1] = 3
townCenter[4][2] = 1
townCenter[4][3] = 2
townCenter[4][4] = 3
townCenter[4][5] = 4

townCenter[5][0] = 4
townCenter[5][1] = 3
townCenter[5][2] = 1
townCenter[5][3] = 2
townCenter[5][4] = 3
townCenter[5][5] = 4

       // Enter main game while loop

       ELSEIF gameState = 5
GOSUB game

// test out isometric tiles

// 48.5 across, 24 up
// DRAWSPRITE 4, 344, 128
// DRAWSPRITE 3, 296, 152
// DRAWSPRITE 2, 248, 176
// DRAWSPRITE 1, 200, 200

// 4 straight road tiles
// 4 crossroad tiles
// 4 corner tiles
// 4 t-juction tiles

// 12 special cards which consist of:
// 5 dead-end roads
// 2 corner roads
// 2 straight roads
// 3 t-junction roads
// 1 helipad (end)
// 1 town square (start)

xPos = 48
yPos = 24

origXPos = 300
origYPos = 100

FOR x = 5 TO 0 STEP -1
FOR y = 0 TO 5 STEP 1

IF townCenter[x][y] = 1
DRAWSPRITE 1, origXPos, origYPos
ELSEIF townCenter[x][y] = 2
DRAWSPRITE 2, origXPos, origYPos
ELSEIF townCenter[x][y] = 3
DRAWSPRITE 3, origXPos, origYPos
ELSEIF townCenter[x][y] = 4
DRAWSPRITE 4, origXPos, origYPos
ENDIF

origXPos = origXPos + xPos
origYPos = origYPos + yPos

NEXT

origXPos = 300 - 48
origYPos = 100 + 24

NEXT


ENDIF

SHOWSCREEN
         // End main game while loop


Thanks

namco

I know what the problem is now.... it's the

Code (glbasic) Select

origXPos = 300 - 48
origYPos = 100 + 24


that's causing the problems.

Me and my maths!  ;/

Ian Price

Why not use
Code (glbasic) Select

Drawsprite TownCenter[x][y],origXPos, origYPos


Saves a lot of "IF" "ELSEIF" in your "FOR/NEXT" loop. Should speed it up a little. :)
I came. I saw. I played.

namco

Didn't realise you could do that.

Will go and change the code now, thanks Ian! :)