displaying a map help.

02-21-2002, 01:31 PM

I've just started coding a tile based game.
and wonder if somebody could give me some advice on the code below.

I am currently creating a random world 40x40 with 32x32 squares. Currently there are only two different tiles.

This is no problem.
The problem I have is when displaying this.

For i = 1 To 40
For j = 1 To 40

If MapArea(i, j) = 0 Then
screen.PaintPicture tile1.Picture, (i) * 32, (j) * 32
End If

If MapArea(i, j) = 1 Then
screen.PaintPicture tile2.Picture, (i) * 32, (j) * 32
End If

Next j, i

The tiles display but the first row on both axis stays white.. I know why this is because of the (I) * 32 part..

I was just wondering what other ways can this be tackled with.
Also eventually as the tile set grows bigger what would be the better way to continue.



02-21-2002, 01:44 PM
Could you attach your code files here so that I could see what happens? Thanks!

02-21-2002, 01:46 PM
code attached.

02-21-2002, 03:24 PM
Try looping from 0 to 40 instead of 1 to 40. ;)

02-22-2002, 07:45 AM
Squirm is correct--your arrays are base 0, so your first element in each array will be at index 0. Loop from 0 to 40 instead of 1 to 40.

02-22-2002, 09:11 AM
In terms of better ways to organise the code for larger tile sets a Select Case statement wouldn't go astray. Of course this can also become cumbersome.

The game I am working on has the potential to have over 1000 different tiles. It would be daft to select case for the whole lot, so each tile type's properties are stored in an array of User Defined Types. The map then stores an integer indicating the position in the array where the info on the appropriate tile may be found.

For x = 0 to 40
For y = 0 to 40
Tile1.Picture = LoadPicture App.Path & "\GFX\" & Terrain(MapArea(x,y)).piccy
Screen.PaintPicture Tile1.Picture, x * 32, y * 32
Next x,y
This isn't exactly how I am doing it, as I have modified it to fit your model more closely. :)

02-22-2002, 09:57 AM
thanks for the advice everyone.

wow 1,000 tiles that a lot! I don't think mine will be near that big.. I suppose it depends on what tile size I finally go with...

I've been looking at imagelists this afternoon to see if I can link in with that. At least then I could load all the tiles into memory first.

I've been trying to code this map type editor this afternoon and found that using single pictures is getting the code more and more long winded.


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum