Results 1 to 13 of 13

Thread: Making a Level File???

  1. #1

    Thread Starter
    Fanatic Member Mushroom Realm's Avatar
    Join Date
    Mar 2002
    Location
    Murrieta, California
    Posts
    650

    Making a Level File???

    Ive got my game pretty much worked out, but i can think of the best way to make the level file. I want it to be able to give me a number (1 - 4), for each spot on the grid (15-30). What would be the best way to do this. I dont need to encode the file.

  2. #2
    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
    It's very easy, are you already using an array (with 2 dimensions)? If you are it's gonna be easy, loading it from a file... if not, I'll have to tell ya how to use it to store your tiles in memory...
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  3. #3

    Thread Starter
    Fanatic Member Mushroom Realm's Avatar
    Join Date
    Mar 2002
    Location
    Murrieta, California
    Posts
    650
    Im using a 2d array for the level map, i dont know how i should write the file for fastest use?

  4. #4
    Addicted Member
    Join Date
    Aug 2002
    Location
    Baltimore, MD
    Posts
    230
    Use binary files.

  5. #5
    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
    Here's some code:

    VB Code:
    1. Dim X As Long, Y As Long, TempByte As Byte
    2.  
    3. Open App.Path & "\map.txt" For Binary As #1
    4. X=0
    5. Y=0
    6. Do Until EOF(1) 'Loop trough all the characters (bytes) in the file
    7.     Get #1,,TempByte
    8.     If TempByte=10 Then
    9.         'Characters 10 and 13 mean a line break - so one of them makes us go to the next line
    10.         Y=Y+1
    11.         X=0
    12.     ElseIf TempByte=13 Then
    13.         'Do nothing...
    14.     Else
    15.         'Another character - put it in the map array
    16.         MapArray(X,Y)=TempByte
    17.     End If
    18.     X=X+1
    19. Loop
    20. Close #1
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  6. #6
    Addicted Member
    Join Date
    Aug 2002
    Location
    Baltimore, MD
    Posts
    230
    If you store your map data in a UDT you can write the entire UDT to the file with one line:

    Code:
       Public Type udtMap
          'Map properties here
       End Type
    
       Dim iFileNum As Integer
       Dim objMap As udtMap
    
       'Fill in the map here
    
       iFileNum = FreeFile
    
       Put iFileNum, , objMap
    
       Close iFileNum
    There are a two caveats to doing it this way, but if you have a simple map it should work fine.

    Notice the call to FreeFile.

    NEVER just use a file number as in the above example. It's very sloppy programming and can get you into trouble if you use multiple files.

  7. #7
    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
    Hehe it's sloppy but it's faster to type
    Also, I never open more than one file or a maximum of 2 at a time - that's sloppy programming, you should keep them in memory or something

    Your code is cool but I'm not sure if it's good for dynamic arrays...
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  8. #8

    Thread Starter
    Fanatic Member Mushroom Realm's Avatar
    Join Date
    Mar 2002
    Location
    Murrieta, California
    Posts
    650
    I tried to clean up the code to better suit me:

    Dim X, Y, TempByte, Counter As Byte
    Do Until EOF(1)
    For Y = 1 To 15
    For X = 1 To 30
    Get #1, , TempByte
    Map(X, Y) = TempByte
    For Counter = 0 To 17
    SetPixel picPercent.hdc, (X * Y), Counter, vbBlue
    DoEvents
    Next Counter
    Next X
    Next Y
    Loop
    Close

    picpercent is a picturebox that i wanted to fill in while it loads, the height is 17, that part works fine.

    I think its loading right, but later when im setting the form to display the contents of the map it doesnt work right. I wanted to scan for numbers (0 - 3) 0 is a clear spot, 1 is a wall, 2 is u, 3 is an enemy.:

    Private Sub SetWalls()
    Dim X, Y, TempX, TempY, Temp As Byte
    For Y = 1 To 15
    For X = 1 To 30
    Check = Map(X, Y)
    If Check = 1 Then
    For TempY = (Y * 10) To ((Y * 10) + 10)
    For TempX = (X * 10) To ((X * 10) + 10)
    SetPixel frmScreen.hdc, TempX, TempY, vbBlack
    Next TempX
    Next TempY
    End If
    Next X
    Next Y
    End Sub
    Private Sub SetPixelLocation()
    Dim X, Y, Temp As Byte
    For Y = 1 To 15
    For X = 1 To 30
    Check = Map(X, Y)
    If Check = 2 Then
    Pixel.Move (X * 10), (Y * 10)
    End If
    Next X
    Next Y
    End Sub
    Private Sub DisplayEnemies()
    Dim X, Y, Check, Temp As Byte
    For Y = 1 To 15
    For X = 1 To 30
    Check = Map(X, Y)
    If Check = 3 Then
    Temp = picEnemy.Count
    If Temp > 1 Then
    Load picEnemy(picEnemy.UBound + 1)
    picEnemy(picEnemy.UBound).Visible = True
    End If
    picEnemy(picEnemy.UBound).Move (X * 10), (Y * 10)
    End If
    Next X
    Next Y
    End Sub

    Thats all three subs that i call. Though the load is on a different form , could that be the problem?

  9. #9

    Thread Starter
    Fanatic Member Mushroom Realm's Avatar
    Join Date
    Mar 2002
    Location
    Murrieta, California
    Posts
    650
    Pixel is the characters name

  10. #10
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Mushroom: Use [vbcode] and [/vbcode] to make your code readable...

  11. #11
    Addicted Member
    Join Date
    Aug 2002
    Location
    Baltimore, MD
    Posts
    230
    Originally posted by Jotaf98
    Your code is cool but I'm not sure if it's good for dynamic arrays...
    Yup, it allocates whatever it needs when it loads it from the file. That's what makes it so cool.

  12. #12
    Addicted Member
    Join Date
    Aug 2002
    Location
    Baltimore, MD
    Posts
    230
    Ugh, you're looping through the array three times?!?! Just loop through it once and display whatever you need for whatever is at that position Where are you calling the three functions from? It doesn't make a difference where you load the array from as long as it's Public.

  13. #13
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Just some ideas..

    VB Code:
    1. Public Type tMap
    2.    Tile as Integer
    3.    Event as Integer
    4.    'whatever...
    5. End Type
    6.  
    7. Public MapW as Integer
    8. Public MapH as Integer
    9. Public Map() as tMap
    10.  
    11. 'Save data
    12. Open Filename for Binary as Filenumber
    13.     Put Filenumber ,, MapW
    14.     Put Filenumber ,, MapH
    15.    
    16.     Put Filenumber ,, Map
    17. Close Filenumber
    18.  
    19. 'Load data
    20. Open Filename for Binary as Filenumber
    21.     Get Filenumber ,, MapW
    22.     Get Filenumber ,, MapH
    23.    
    24.     ReDim Map(MapW, MapH)
    25.     Get Filenumber ,, Map
    26. Close Filenumber

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