Archived

This topic is now archived and is closed to further replies.

how a simple level editor is made?

This topic is 5015 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

high, im thinking of making a level editor for my pacman clone (for learning purposes) and was wondering, how do people make these? i would do it like this: first, the game is tile based so the level editor must be. what i would do would be to first fill up the screen with an array of "blank space" tiles. if using 32x32 tiles with an 800x600 screen, i would make an array map[25][19] (y,x), then i would loop through each element of the array and draw a tile at the element*32, like a traditional tile based program. then, each frame i would re-draw this map array. now, based on mouse input, i would do collision detection for where the user clicks, then, where that user clicked, i would find which elemeny this was in the map array, and re-assign the value of this element to whatever the user was currently drawing. as in, if the user was drawing a wall tile, he would click on the screen, it would find which element this spot was in the array, then it would change this value to WALL. then, the next frame, when the map was re-drawn, it would now be a wall in that spot. there would have to be a menu of some kind to switch between tiles (maybe an invisable one and the user (me) would just have to know which key to press to switch tiles?) anyway, after the user was done with making the map, this array would be either written to a txt file and uploaded later, or if i wanted to make the level editor a part of the game (most likely) i would just transfer the array to be the map the user next plays on. so, is this how its typically done? or am i going about it all wrong way, or what? thanks for any input [edited by - graveyard filla on March 19, 2004 9:41:26 PM]

Share this post


Link to post
Share on other sites
Hi filla,
I''ve just finished doing one for a 3d version of pac man (http://homepage.ntlworld.com/d.bevan4/DEMO.zip) which used visual basic. In my opinion things like this are much easier to do in VB. Then like you planned to do anyway, you can save the design and incorporate it into a c++ game code. The approach you are taking certainly seems like a good one to me. However I always think its better for the user to be able to see what kind of tiles they are going to be laying down. If its too much to learn people probably won''t use it. If you have VB then give it a go, you''ll be surprised how quickly you can knock something together. If you are using DirectX for your game you can even get it running in a picture box like I have.
Hope this has been of some use.
Drb2k2

Share this post


Link to post
Share on other sites
Just finished level editor for my Breakout clone yesterday (with C++/OpenGL) and basically I did it the same way you just described.

Infact one button is not still working in my editor and it´s "Test", purpouse of that would be to test the level but I have to finish the whole game first :]

In my editor there´s on left side menu buttons:


New // Just clear´s the game board and sets current filename
// to ""
Save // Saves file with current name, if no name have been
// given, then opens save as window
Save.. // Opens save as window
Load // Opens load window
Test // By clicking this you can play the level (not ready)
Exit // Back to game´s main menu

And then on the other side there´s tiles and items..

and in the middle there´s the game board.


[edited by - Mkk on March 20, 2004 7:49:43 AM]

Share this post


Link to post
Share on other sites
If there is something you want to know more about be free to ask and I can try to explain it to you..

And like I said already, yes, that what you described in your first post is how the things basically should work..

About source code.. I can put it in the net if you want to but it´s not the most readable code in the world I bet.


[edited by - Mkk on March 20, 2004 5:18:33 PM]

Share this post


Link to post
Share on other sites
well, i just cant picture how to make the menu screen non invisable. as in, how do you put options (like save, load etc) on one side, and then tile choices on the other side? if you have to include all of this stuff in the array, how do you transfer this array to a game-playable array?

as in, if your game map is [25][19] tiles, how do you make a screen big enough to fit [25][19] tiles, AND put buttons in the sides? you could make a bigger array, but then that array would not be compatible with a game-map array.

do you just make a bigger screen, then draw your map array to the screen, then with the extra space you put the buttons and stuff in? of course these buttons couldnt be a part of this array, duh, wait i think i just answered my own question ok well is this how you did it?

Share this post


Link to post
Share on other sites
Here you can see pic of my editor:


"well, i just cant picture how to make the menu screen non invisable. as in, how do you put options (like save, load etc) on one side, and then tile choices on the other side? if you have to include all of this stuff in the array, how do you transfer this array to a game-playable array?"

Sorry, but what stuff do you mean? Only thing that I will read/write from my editor is one variable array and that´s
int gameBoard[10][20] and every block is represented as one integer in that array.

"as in, if your game map is [25][19] tiles, how do you make a screen big enough to fit [25][19] tiles, AND put buttons in the sides? "

Ok, so your game board fullfils whole screen? Then I think you could do visible menu for example:

- By doing so that in editor blocks are smaller than in game it self (16x16 for example)..

- So that by clicking for example right mouse button it would
appear and then you could select "palette" and then it would disappear again..

- Do it so that when you move your mouse to like upper left corner the menu would appear and after moving mouse out of menu it would again disappear..

Or something like that, of course all of these would need some extra work..


"you could make a bigger array, but then that array would not be compatible with a game-map array."

What do you mean by this?..

"do you just make a bigger screen, then draw your map array to the screen, then with the extra space you put the buttons and stuff in?"

Because my game board´s size is only 460(10*46)x460(20*23), I have already free space in left and right.

"of course these buttons couldnt be a part of this array, duh, wait i think i just answered my own question ok well is this how you did it? "

What do you mean that buttons couldn´t be part of array?


[edited by - Mkk on March 20, 2004 6:10:48 PM]

Share this post


Link to post
Share on other sites
ok, heres what i figured out (in my last post).

i have a pacman clone that is [25][19] tiles. it fills the whole screen 800x600 with 32x32 tiles. so, if i wanted to make an editor, i would have to make an invisable menu, or else where would i fit the buttons if the array fills the whole screen?

anyway, the solution is:

make the screen 1024x768

then fill my screen with the [25][19] map array

this would not fill the whole screen! so then i would just put my buttons along the edges where there was space. now, i still have an array that is [25][19] (therefore it IS game-map compatible, IE i could explort this array and use it as a map array in-game.)

so do you think this will work? what i mean by the buttons not being part of the array was, just that, the buttons i would add would NOT be part of the array, hell, they wont even be tiles. i will just draw them manually to the screen. if i had to put the buttons as part of the array, then the array would have to be bigger(say [29][22]) and which case would NOT be compatible with my game map, ie if i tried using that map in my game, it would crash.

so does this all sound good? thanks for your help m... oh and your map editor looks sweet

[edited by - graveyard filla on March 20, 2004 6:42:37 PM]

Share this post


Link to post
Share on other sites
I think that having bigger resolution in editor is working idea.

It looks like you are looking this problem somehow odd angle, when you are talking about buttons in array and bigger arrays and stuff.

Let me explain how I did this (check if mouse is in board and stuff):

First I checked if the cursor is inside the game board:

if (mouseX >= 170 && mouseX < 629 && mouseY > 140 && mouseY < 600)
{
/* If it is, then I will do calculations so that mouse coords
relate to the right place in the array.
Notice that those decreases from the coordinates (-170 and
-140) are amount of pixels from windows bottom left corner to
place where the game board starts, that´s the way to get
right place in the array: */


GLint tempMouseX = mouseX;
GLint tempMouseY = mouseY;

tempMouseX = ((tempMouseX - 170)/46);
tempMouseY = ((tempMouseY - 140)/23);


// Then I will check if user has mouse2 button down (in my

// editor this will mean same as erase):


if (mouse2)
{
gameBoard[tempMouseX][tempMouseY] = 0; // set that place in

// game board as empty

}

// Then check has user chosen any palette:


if (editorChosen != 0) // Has user chosen any palette

{
// Yes he is, then check if mouse left button down

if (mouse1)
{
// Put chosen palette in gameBoard variable

gameBoard[tempMouseX][tempMouseY] = editorChosen;
}
}
}




[edited by - Mkk on March 21, 2004 2:03:32 AM]

Share this post


Link to post
Share on other sites
i havent messed with mouse input yet... is it much harder then regular input? im using SDL.... but, how do i find what tile the user clicked on? i was thinking of using regular tile based collision detection...is this how its usually done? how does mouse input work? can you check what coordinates the mouse is at while the user is pressing a button? if so then my collision idea should work...

Share this post


Link to post
Share on other sites
Don´t know how you can get mouse coords with SDL but I´m pretty sure it´s easy thing to do..

about collision and things.. I just described in my last post how I did them.. I don´t know what do you mean by saying "regular tile based collision detection"..

Share this post


Link to post
Share on other sites
graveyard filla: Yes, 46 and 23 are the width and height of my tiles..

So to get the right tile.. first you have to decrease the number of pixels that are there before the gameboard itself.. In my editor there 170 pixels on x and 140 on y before the gameboard.

Example: The mouse is on bottom left corner of game board, let´s say it´s values are, x: 192, y: 150.

Here´s a pic.

Now we start to calculate numbers..

first we take off these extra pixels before game board (170 on x and 140 on y):

x = 192-170
x = 22

y = 150-140
y = 10

then we divide these numbers by width/height of the block:

x = 22/46 (width = 46)
x = 0,47826086956521739130434782608696
(but because x is integer type of variable, decimal numbers
are not considered and x will be zero)
x = 0

y = 10/23 (height = 23)
y = 0,43478260869565217391304347826087 (and y is also integer..)
y = 0

and now we have x = 0, y = 0 and we can put stuff to
first place in the array (and that´s the tile where the mouse is pointing):

gameBoard[x][y] = tile;


[edited by - Mkk on March 22, 2004 5:37:04 AM]

Share this post


Link to post
Share on other sites