PDA

Click to See Complete Forum and Search --> : Tile-based game?


Spie
Dec 5th, 2000, 10:07 PM
I am having a problem geting the program to draw the grass... It draws one tile about every 4 inches or so. ...and the character leaves a trail. Please help :(

HarryW
Dec 5th, 2000, 10:47 PM
Well if you post your code then maybe that would help. I don't really know what to say from the description, maybe some would, but I think it's easier if you post your code.

Spie
Dec 6th, 2000, 03:21 PM
goto http://www.geocities.com/spie_12345/tll/game.html

HarryW
Dec 6th, 2000, 06:47 PM
Well, there's good news and bad news.

Good news:
The problem was simple, you need to set the scalemode of the picture boxes to 3 - Pixels and use the ScaleWidth and ScaleHeight for the size of your images in your BitBlt call. Ie. tile.w = picTile(0).ScaleWidth etc.

Bad news:
It ran really really slowly when I fixed this. I'm just having a look now to find out why.

HarryW
Dec 6th, 2000, 07:23 PM
Aha, I found the problem. Hehe, it was kinda stupid actually, I forgot to set the For loops in your Draw() function to ScaleWidth and ScaleHeight :rolleyes: It was drawing an area of tiles that was 225 times the size of your picturebox ;)

So yes, that's the problem - change everything to ScaleWidth and ScaleHeight.

Spie
Dec 6th, 2000, 09:38 PM
Thanks, man... I have been trying to solve that problem for a while... I am kinda new at this.
Btw. Do you like my character :)

Spie
Dec 6th, 2000, 09:43 PM
sorry for the second post, but do you have any idea why he flickers?
thanks again for the help on the tiling. :)

HarryW
Dec 6th, 2000, 10:30 PM
You need to add this:

'Check the player vars for animation
If player.Animated Then
Animate
End If

or just
If player.Animated Then Animate

HarryW
Dec 6th, 2000, 10:32 PM
Oh and yes, your character is kinda cute I guess :) Did you draw it or get it somewhere?

Spie
Dec 6th, 2000, 10:57 PM
I got the size and width from somewhere else, but drew the rest...

Spie
Dec 8th, 2000, 04:51 PM
I have another question (sorry :þ) Is there some way I can tell the program where to put which tile... like make a lake, or something like that?

HarryW
Dec 8th, 2000, 11:25 PM
Your best bet for something like that is to have all the coordinates in a map file, and then just draw the next tile as specified in the map.

It's best to use a one-dimensional array for the map, rather than two dimensional, so that you can resize your viewable area at run time. You can get and put this array from/to a file with something like this:


Dim MapArray() As WhateverType

'to save it to file
Open FileName For Binary As #1
Put #1, , MapArray
Close #1

'to load it back
Open FileName For Binary As #1
Get #1, , MapArray
Close #1


Say that your map file was for a 50 x 50 tile map, then you would have an array that was 2500 elements. Each 50-element section is a row. When you want to know what a tile at coordinates (x, y) is then you just find that tile in the array like this:


Tile = MapArray(x + 50 * y)


That's assuming your map is 50 tiles wide remember.

You just need to change your background-drawing code so that it finds what tile it's meant to draw from an array, like that.

Fox
Dec 9th, 2000, 07:02 AM
Sorry Harry, but your loading code wont work :D
Since you use a resizable array you need to set the correct size before loading the data from your file. Therefore we need to store its size in the file, too:


Dim MapArray() As WhateverType

'To save it to file
Open FileName For Binary As #1
'Store map size
Put 1,,CLng(UBound( MapArray,1))
'Store map
Put #1,, MapArray
Close #1

'To load it back
Dim Temp as Long
Open FileName For Binary As #1
'Load map size
Get 1,,Temp
'Allocate memory
ReDim MapArray( Temp )
'Load map
Get #1, , MapArray
Close #1

HarryW
Dec 9th, 2000, 07:11 AM
Doesn't the array store a descriptor at the beginning? It manages with strings okay. Strange.

Fox
Dec 9th, 2000, 07:43 AM
Maybe it saves the info, dunno... but in fact it does not resize the array when loading.

Spie
Dec 9th, 2000, 10:45 AM
hope you don't mind me asking...but where do I put that code? :D

Spie
Dec 9th, 2000, 10:48 AM
Oh. nm. you told me in your reply, sorry :)

... how do I make the file, though?

[Edited by Spie on 12-09-2000 at 11:59 AM]

HarryW
Dec 9th, 2000, 11:07 AM
It will get created, if it doesn't exist, when you open it.

You'll probably have to make some kind of simple map editor if you want to set up your map files.

Spie
Dec 9th, 2000, 11:15 AM
hehe, i can try that :) thanks

HarryW
Dec 12th, 2000, 01:06 AM
No idea sorry.

It's not hard though, you just need to create your map data so that you store the data in the same format as you are going to use it. A common way to do that is to have a UDT for each tile defining its properties, and save an array of these values in the file. Then use the same UDT in your main program.

You'll probably need to have more or less the same display routine as you use in your main game, and either use the mouse to change tiles when you click on them or use the cursor keys to select tiles and then select options for that tile. It will take a little thinking I expect. Try writing down what you want the interface to be like and then break it down into small problems, and then into smaller problems until each problem is a manageable chunk.

Sorry I can't be of more help.

Spie
Dec 12th, 2000, 03:52 PM
k...i can try that :) thanks again

Jotaf98
Dec 14th, 2000, 11:10 AM
Hey, I have a prototype of a map editor but I can't get the scroll bars to work to view the whole map (the rest runs fine). If I can use the scroll bars to view the whole map, I'll give it to you ;)

(It's a Picture control in another Picture control, all I have to do is move the Map Picture inside the Container Picture according to the scroll bars)

Jotaf98
Dec 16th, 2000, 10:52 AM
Well, it's so simple that I don't think I need to send it to you:

I have a PictureBox control (picMapContainer) occupying the whole form. It has 2 ScrollBars in its sides. Then, inside picMapContainer, I have another PictureBox (picMap).

All I wanna do is scroll picMap inside its container according to the ScrollBars... picMap stores the whole map, and is way bigger than picMapContainer.

This would do it for a simple game (imagine a 5000x5000 pixels map - it would consume LOADS of memory, so that's why a big map wouldn't fit), but I have another drawing technique that might be better... just forget about my problem, it will probably ready tomorrow!