Scrolling Game Development Kit Forum

SGDK Version 1 => Help/FAQ => Topic started by: Anonymous on 2005-09-01, 01:07:21 AM

Title: question about map editor
Post by: Anonymous on 2005-09-01, 01:07:21 AM
hi, all
I'm a new guy for SGDK. I want to make a scrolling game. I find that SGDK is very useful for it. But I'm not sure that SGDK can fit all my requirement whether or not, but anyway the map editor is quite useful for the game development. So I just want to know how about the map editor for other game development? I mean, if I know the map format generated from the SGDK, can I use this map in other game?

Any help and suggestion will welcome!

frank
Title: question about map editor
Post by: bluemonkmn on 2005-09-01, 05:56:53 AM
Yes, that's one of the purposes of the kit.  You should be able to make a map in GameDev, and use it in your own project.  You might want to make a script/program to export the map data to your own format.  This can be done by using GameDev as a COM object to load the game, use the objects inside GameDev (like ProjectObj.Maps(0).MapLayer(0).Data.MapData, which returns a byte array with one byte for each tile) to extract the pieces of the project you want in order to write them to a file in your own format.  You can also export the project to an XML file (this is a built-in feature of the IDE), which is a nicer format from which to extract data in some ways.  If you need more help on any of this, let me know.
Title: question about map editor
Post by: arcus on 2005-09-02, 03:46:28 AM
Thank you very much for your reply.
I still have these questions:
1. Can I paste with different size tile in SGDK?
2. When I play the game, how about the SGDK streagy of loading the map? Does it load the screens just near the sprite or the whole map?
3. It seems that SGDK can export map data into xml file. Is there any dtd file to describe the xml format? where can I find the load code of build the whole world according to the map data file?

Thanks a lot

have a nice weekend

Frank
Title: question about map editor
Post by: bluemonkmn on 2005-09-03, 09:24:03 AM
[list=1]
Code: [Select]
ReDim BA(0 To Layers(I).Columns * Layers(I).Rows - 1) As Byte
Get #FF, , BA
Layers(I).Data.MapData = BA

Code: [Select]
NewMap.MapLayer(J).Data.MapData = oLevel4Node.selectSingleNode("Tiles").nodeTypedValue
[/list]
[/list:o]
Title: question about map editor
Post by: guest on 2005-09-06, 12:01:17 AM
Hi!
Maybe my question is similitude as the previous question.

I want to make a 2d game by myself. I use visual c++.net. I found it's best use the scrolling gamedev to editor the map, for it is powerful. But I didn't know how load the files in my c++ project, when I create a map use GameDev. Is there anyway?

Frank,
Title: question about map editor
Post by: arcus on 2005-09-06, 02:52:39 AM
It is so happy meet the same name guy in this topic.
I have a question, how about the format of map, xml or other format. I don't like xml because of the efficiency. I see some other map data file in the gamedev, and how can I read this map information into memory.

Thanks a lot

Frank
Title: question about map editor
Post by: bluemonkmn on 2005-09-06, 06:24:50 PM
As I wrote above, the Map.cls file has a Load function that will demonstrate how to read the map file directly from the .MAP file that GameDev created.  Do you need help converting this code to C++ code that will read the file?
Title: question about map editor
Post by: arcus on 2005-09-06, 07:26:06 PM
Quote from: "bluemonkmn"
As I wrote above, the Map.cls file has a Load function that will demonstrate how to read the map file directly from the .MAP file that GameDev created.  Do you need help converting this code to C++ code that will read the file?

yes, it is exactly what I want.  Would you please to give me some help for this?

Thanks a lot
Frank
Title: question about map editor
Post by: bluemonkmn on 2005-09-07, 06:16:21 AM
I don't have time to write the whole C++ procedure for you, but I can get you started at understanding the VB code so you can write the C++ code.

The first thing to understand about the file format of the .MAP file is that it consists of many sections.  Each section contains a 4-character header followed by a 32-bit integer representing the length in bytes of that section.  The one exception is the BMGC section which has a version number between the header and the section length.  For example, the file I am looking at has BMGC0005 as the first 8 bytes.  The next byte is 0x12 (hex 12 = decimal 18) followed by 3 zero-bytes.  That represents a long integer whose value is 18.  So the next 18 bytes represent the BMGC section, and immediately after that is the "LYRS" section header.

You will see that the first line that reads the file is "Get #FF, , S".  Since S is a string containing 4 characters, this will read 4 characters (8-bit characters) from the file.  You will see that the code is verifying that the first 4 characters are "BMGC" which is the signature for the beginning of the .MAP file.

Next it does "Get #FF, , S" again which reads the next 4 characters.  These 4 characters represent the version of the MAP file as a string.  For example, "0005" represents a map file from GameDev version 1.4.x.

Next it does "Get #FF, , SLen".  Since SLen is declared as a "Long", it will read a 32-bit integer from the file.  This integer represents the length of the map header section of the file before you get to the LYRS section.  It is the number of bytes after the end of this integer and before the "LYRS" signature.

Next it does Get #FF, , PixWidth, which you will see is a property of the Map object at the top of the file.  It is declared as a Long, so it too will read a 4-byte (32-bit) integer from the file.  This integer represents the map width entered by the user (the width of the map in pixels).

Get #FF, , PixHeight is treated similarly.

Next you see BackgroundMusic = LoadString(FF).  The LoadString function will perform two main steps.  It reads a long integer from the file.  Then it creates a string whose length matches that integer and reads that many characters into the string.  This particular string represents the name of the background music clip for this map.

Next you will see that it reads a long integer called BackgroundColor from the file, but only if the version of the file is greater than 4 (because background color did not exist before version 1.3).  

If you continue to follow the function through like this you can identify every byte in the MAP file format.  I don't have time to finish the entire description here, but this is a basic picture of what has been covered so far:

"BMGC" - map header signature
"000n" - 4-character string representing map version (0005 is 1.4.x)
32-bit int - length of remainder of BMGC section
32-bit int - Pixel width of this map
32-bit int - Pixel height of this map
32-bit int - length of background music string
<string> - name of background music for this map (length determined above)
VERSION 4 OR LATER: 32-bit int - background color of this map

Is this helpful at all?  Can you proceed to understand more of the function based on this and let me know where you get stuck or are you completely lost still?
Title: question about map editor
Post by: arcus on 2005-09-09, 03:25:24 AM
Thanks greatly for the reply.
I follow the guideline as you say, and meet some problem.
e.g.,

"code
AddLayer LName, LTDName, LXR, Lyr, LTrans > 0
.............
ReDim BA(0 To Layers(I).Columns * Layers(I).Rows - 1) As Byte
Get #FF, , BA
Layers(I).Data.MapData = BA "

1,"Layers(I).Data.MapData" This code is related to BMDXCtls.dll, would you please give more detail information about the BMDXCtls.dll? And can you describe the relationship among the layer, map, tileset and so on from the code side?  For example, which class is related to these object and there relationship.
 
2,What is the information include in "BA"?

thanks a lot
have a nice weekend

Frank
Title: Map file format
Post by: bluemonkmn on 2005-09-09, 06:23:40 AM
BMDXCtls.dll is written in C++ so it should be easier to read if you are a C++ programmer.  The source code is available on SourceForge in the project where you can find the GameDev source code.  Included in the source code is a help file for BMDXCtls to understand the interface.  However, I don't think you need to get any of BMDXCtls because BA is quite simple, and you don't need to look at BMDXCtls to understand it.  BA is simply an array of bytes.  Each layer on a map has tiles on it.  Each tile is one byte.  When the Load function reads BA from the file, the size of BA is Columns * Rows where Columns is width of the layer in tiles and Rows is the height of the layer in tiles.  So the total number of tiles is Columns * Rows -- 1 byte for each tile.  The first byte represente the tile at the top left corner of the layer.  The next byte is the tile to the right of that.  The last byte is the tile at the lower right corner of the map.

Each byte in a layer represents an index into the tileset where the graphic for that tiel can be found.  Each layer refers to only 1 tileset.  And if the first byte on the layer is 3, then the tile that should be drawn on the layer in that position is number 3 from teh tileset.  The tileset indexes start from 0, so tile number 3 is the fourth tile in the tileset.  A map is just a collection of layers, and each layer can have its own tileset.  Each layer has its own size too (because the tile sizes on the layers might be different and the scroll rates might be different too).

Does this help?
Title: question about map editor
Post by: arcus on 2005-09-13, 02:06:06 AM
hi,
I have another question.
In the .map file, I can only read the tileset name, such as
            Get #FF, , SLen
            LTDName = Space$(SLen)
            Get #FF, , LTDName
but I cannot get the image location information or the which image assciated with this tileset name, how can I get these information? Because without this, I cannot paste image according to a layer in my application.

Thanks a lot
Frank
Title: GDP
Post by: bluemonkmn on 2005-09-13, 05:19:54 AM
The locations of the files (maps and tilesets etc) are all located in the GDP file, not the MAP file.  I hope that's not a problem.  The GDP file is plain text (you can read it in notepad).  So I don't think you need me to describe the format of the GDP file.  But I am very interested to hear how this turns out.  Please come back and let me know of your success!  Of course I'll be happy to answer any more questions you may have too.

When you are done, if you are willing to share your C++ code that loads the MAP file and the GDP file, there may be others who would be interested.  I could post the code that does this (and give you credit of course) if you're interested.  I have always wanted a GameDev runtime engine written in C++, but I've never had the motivation to do it myself -- how many of GameDev's features will be implemented/supported in your engine?  This sounds very interesting!
Title: question about map editor
Post by: arcus on 2005-09-13, 11:39:37 PM
Thank you very much for help.
I want to make a scrolling game, and I hope to use GameDev as the map editor. While for the basic game logic, I will create it in c++ with DirectX. And I'm still not sure whether I can use GameDev's physics and script system?
Anyway I will share the c++ code when the work is done?

thanks a lot
frank
Title: Reusing GameDev
Post by: bluemonkmn on 2005-09-14, 05:29:59 AM
If you want to use GameDev's physics system, you'd either need to use the engine itself (GDPlay.exe) to play the game, or re-create the logic within the engine in your own code.  GameDev's scripting system is just VBScript, but if you want all the same objects exposed, once again, you'd have to use GameDev's engine to play the game.  The ScrHost.dll is the wrapper for GameDev's VBScript support, but it doesn't contain any of the GameDev objects used in scripting -- those are all inside GDPlay.exe.

You could use GameDev's physics system without actually using GameDev to run the game by interacting with GDPlay.exe as a COM object.  You can call the methods in GDPlay.exe to load the project and manage the sprites etc, and you could do all the drawing on your own.  But if you do that, I think you should not write an EXE because communicating from one EXE to another EXE is slow if you make many calls (and I think checking on the status of all the sprites would involve many calls to GDPlay.exe).  If you write it as a DLL, though, then you could have some external launcher -- the achitecture would go something like this:
1. Launcher.exe: Load GDPlay.exe
2. Launcher.exe: Load MyGame.dll
3. Launcher.exe: Connect MyGame.dll to GDPlay.exe
4. Launcher.exe: Pass control to MyGame.dll (MyGame.Play() )
5: MyGame.dll: Tell GDPlay.exe to load project
6. GDPlay.exe: Loads all project data
7. MyGame.dll: Load your own copy of the project?
8. MyGame.dll: Tell GDPlay to Initialize Map1
9. GDPlay.exe: Initializes its copy of Map1 and creates all the sprite objects
10. MyGame.dll: Begin game -- initialize your own copy of the project and begin playing.
11. MyGame.dll: Draw the tiles for Map1 in your own engine
12. MyGame.dll: Tell GDPlay to move the sprites for Map1
13. GDPlay.exe: Moves all the sprites in its copy of the project data
14. MyGame.dll: Draw the sprites in the positions determined by GDPlay's copy of the project.
15: Go to step 11.

Of course it would be easier to only load one copy of the project in GDPlay.exe, and let GameDev do the drawing, but it sounds like you want to write your own code to draw the map, which complicates things a bit.
Title: Re-creating physics
Post by: bluemonkmn on 2005-09-27, 05:34:23 AM
If you want to re-create the physics of GameDev sprites in C++ code, rather than re-using GameDev at runtime, you could look at Sprite.cls.  The main function that handles sprite movement is called Sub Advance().  Inside there, you will see that one of the first things it does is:
DY = DY + CSng(.Template.GravPow - 10) / 10

That increases the Y velocity of the sprite (DY) based on the gravity on the sprite's template.  The gravity is a number between 0 and 20, so after subtracting 10, then it is a number between -10 and +10.  This function does a lot of tests and calculations.  It's too many to describe here, but almost everything that a sprite does starts here.  One of the main functions that this function depends on is ReactToSolid.  You will see that function in the same file.  It controls how a sprite reacts to solid areas of the map.

Even though there is a lot of code, you may be interested only in a very small part of it.  For example, if you only want to handle 8-state sprites controlled by the player, without supporting platforms, you would only need to be concerned with these lines from Sub Advance:
Code: [Select]
  With rDef
      DY = DY + CSng(.Template.GravPow - 10) / 10
   
      If .Template.StateType = CONTROL_INPUT Then
          bAccel = ProcessAction(Prj.GamePlayer.CtlActions)
          ReactToSolid
      End If
      Dis = X
      CurVel = Y
      X = X + DX
      Y = Y + DY
   
      CurState = CurState Mod 8
      If Abs(DX) < Abs(DY / 2) Then ' Vertical movement only
          If DY < 0 Then
              CurState = 0 ' Up
          ElseIf DY > 0 Then
              CurState = 4 ' Down
          End If
      ElseIf Abs(DY) < Abs(DX / 2) Then ' Horizontal movement only
          If DX < 0 Then
              CurState = 6 ' Left
          ElseIf DX > 0 Then
              CurState = 2 ' Right
          End If
      Else ' Horizontal and vertical movement
          If DX < 0 Then
              If DY < 0 Then
                  CurState = 7 ' Up left
              ElseIf DY > 0 Then
                  CurState = 5 ' Down left
              End If
          ElseIf DX > 0 Then
              If DY < 0 Then
                  CurState = 1 ' Up right
              ElseIf DY > 0 Then
                  CurState = 3 ' Down right
              End If
          End If
      End If
      If bAccel And .Template.Flags And FLAG_ACCELSTATES Then CurState = CurState + 8
   
      If Abs(Int(X) - Int(Dis)) >= Abs(Int(Y) - Int(CurVel)) Then
          Dis = Abs(Int(X) - Int(Dis))
      Else
          Dis = Abs(Int(Y) - Int(CurVel))
      End If
      AdvanceFrame Dis
   
      If (.Template.Inertia < 100) Then
          If (byAccelDir And 1) = 0 Then
              DX = DX * .Template.Inertia / 100
          End If
          If .Template.GravPow = 10 Then
              If (byAccelDir And 2) = 0 Then
                  DY = DY * .Template.Inertia / 100
              End If
              If Abs(DY) < 0.05 Then DY = 0
          End If
          If Abs(DX) < 0.05 Then DX = 0
      End If
   
   End With
Title: question about map editor
Post by: arcus on 2005-09-28, 11:08:59 PM
Thank you very much for your reply.
I have a question for SGDK. E.g., in the map there is a slope, and the sprite walk on the slope. How to adjust the pose and angle according to the slope not the plane. It is quite ugly that the sprite is always in same pose whenever on plane or slope. Is there any solution in SGDK to solve this problem?


Thanks a lot
Frank
Title: Diagonal states
Post by: bluemonkmn on 2005-09-29, 05:31:34 AM
SGDK provides 8-state sprites that can have different appearances for travelling in the 8 primary directions of a gamepad.  This should help solve the problem by providing unique states specifically for when the sprite is moving diagonally.