Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Small Level Editor Question

Author
Message
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 30th Jun 2010 22:52
I am trying to decide if I want to make a level editor but there are a few things that I am unsure about. First off I have a lot of the basics for a level editor for instance I am using Box2d for my physics and I have rigid and static box's working fine. Now what I would want to be able to do with this is something like this:

1. You run the game and you get a menu that shows "Play Level", and "Level Editor".

2. I would like you to be able to go into Level Editor load a level that you made in photoshop.

3. After you load the level I would want the player to start placing static boxes for the collision of the level.

4. Now this is where I am not to sure on what to do. Basically after you place the collision in on the level I want you to be able to save it and then go back to the main menu and load the level with the new collision. Now down the road I would want to be able to rigid boxes and a lot of other game objects but for now I want to keep it simple.

So what exactly would I want to save to the file? I haven't really tried anything like this but for instance when I create a static box it looks like this:

box[0] = new Box(PosX, PosY, Scale,ImageID,BoxID ,b2World* world,Camera* GameCamera);

Now with the editor I wouldn't even need to designate the ImageId or the BoxID but regardless this is the parameters for making a box so would I then write that to a file and save it. And then when I want to load my levels they load the creating code for my objects? If so could someone just give me an example of how to do that?

Sorry if it is a little confusing but any help will greatly be appreciated, even if you can think of a better way to make a small level editor or I guess for now it really is just a collision making editor but like I said after I get this down I will be able to have the player add in there own game objects like fireballs and what not.
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 1st Jul 2010 00:08
I have the code for my Capt. Ooze level editor at home. I can post it later for you to use as a guide. You won't be able to use as is but the code is easy to read and follow.
Till then,

JTK
Matty H
16
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 1st Jul 2010 00:19
I have not really done anything like this but on a very basic level all you would need is a text file, something like this:



The top line is just for readability, its not really needed.
'shape' might just be 1 = box, 2 = circle etc

You can create text files like this very easily, adding a line every time a box is created and then read it back into your game when needed.

Is this what you meant?

Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 1st Jul 2010 01:03
@JTK,
Yeah if you don't mind posting that maybe with some commented lines or an explanation on what your doing I would greatly appreciate that.

@Matty,
Yeah thats a little how I imagine it. I mean I was wondering if it is possible to just have actual code like this:



Would I be able to write that to a file and then read it as actual code so it will be able to reference world and camera. If so then really for my editor all I have to do is log where I want to put all of my collision boxes and how big they will be. Then I just use that file to create them when you want to play the level.
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 1st Jul 2010 02:00
The short answer is yeah, kinda. Check out lua scripting...

Personally though I'd go matty's route. Its similar to what I did. Check out the demo code. The fps demo you get with gdk (I forget the name of it) has a simple level definition that it uses. capt ooze code follows a similar format but saves it to file instead of hard coding it.

JTK
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 1st Jul 2010 02:48
Okay well I will wait for your post and check out what you did so I can get an idea of how it works
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 1st Jul 2010 03:33
Ok. Here goes:

First off, you have to assume that the various classes are well defined and functional (they were for my purposes). Additionally, the method names do what they are called (ie: someobject->SetPosition() will set the object's position accordingly).

Second, all respective calls to LoadFromFile() will assign the object's ID value accordingly. Subsequent calls to LoadFromFile() by a given object will dbClone() an existing object. This is all handled internally by the CEntityObject base class...

Finally, this level editor was basically an unformatted game world. The proverbial "mouse-cursor" was the player (no actual mouse). Move the player where you want, press the appropriate key - voila!

Now to the goodies that you're waiting for...

This file is the actual source that I used to create the level editor. The first part of the file identifies which keystrokes place what objects at the current location.

The second part is the actual code. should be easy to follow as a guide


Now that the level was saved (hard coded filename), I have another class that I use within the game itself called CLevelMap. The CLevelMap class will load the file specified and create the appropriate objects at the proper locations. Here's the code:

.H file


.cpp file


Finally, the level editor code was used to create the following file which was then loaded up by the CLevelMap class:

LevelMap.dat:


As I said, you won't be able to use it directly, but it should give you an idea on how to proceed.


I hope this helps,

JTK

Login to post a reply

Server time is: 2024-11-19 20:34:28
Your offset time is: 2024-11-19 20:34:28