Results 1 to 23 of 23

Thread: Tile-based game?

  1. #1

    Thread Starter
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126
    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

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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.
    Harry.

    "From one thing, know ten thousand things."

  3. #3

    Thread Starter
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126

  4. #4
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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.
    Harry.

    "From one thing, know ten thousand things."

  5. #5
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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 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.
    Harry.

    "From one thing, know ten thousand things."

  6. #6

    Thread Starter
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126
    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

  7. #7

    Thread Starter
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126
    sorry for the second post, but do you have any idea why he flickers?
    thanks again for the help on the tiling.

  8. #8
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    You need to add this:
    Code:
    'Check the player vars for animation
    If player.Animated Then
        Animate
    End If
    or just
    Code:
    If player.Animated Then Animate
    Harry.

    "From one thing, know ten thousand things."

  9. #9
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Oh and yes, your character is kinda cute I guess Did you draw it or get it somewhere?
    Harry.

    "From one thing, know ten thousand things."

  10. #10

    Thread Starter
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126
    I got the size and width from somewhere else, but drew the rest...

  11. #11

    Thread Starter
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126
    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?

  12. #12
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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:

    Code:
    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:

    Code:
    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.
    Harry.

    "From one thing, know ten thousand things."

  13. #13
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Sorry Harry, but your loading code wont work
    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:

    Code:
    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

  14. #14
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Doesn't the array store a descriptor at the beginning? It manages with strings okay. Strange.
    Harry.

    "From one thing, know ten thousand things."

  15. #15
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Maybe it saves the info, dunno... but in fact it does not resize the array when loading.

  16. #16

    Thread Starter
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126
    hope you don't mind me asking...but where do I put that code?

  17. #17

    Thread Starter
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126
    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]

  18. #18
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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.
    Harry.

    "From one thing, know ten thousand things."

  19. #19

    Thread Starter
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126
    hehe, i can try that thanks

  20. #20
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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.
    Harry.

    "From one thing, know ten thousand things."

  21. #21

    Thread Starter
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126
    k...i can try that thanks again

  22. #22
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    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)

  23. #23
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width