map editor help

Forum for the creative side of the game development process: art, music, storyline, gameplay, concepts, etc. Any sort of relevant discussion is welcome here.

Moderator: PC Supremacists

acerookie1
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 48
Joined: Fri Feb 12, 2010 12:46 pm
Favorite Gaming Platforms: PC, Wii, SNES, GameCube
Programming Language of Choice: C++

Re: map editor help

Post by acerookie1 »

eatcomics wrote:He has nothing to render images with... Since he's using the winapi he just can make windows and such, he needs another api for images... try SDL
im using sfml. i just need the concept of how to do it. to render the images.
Image
User avatar
MrDeathNote
ES Beta Backer
ES Beta Backer
Posts: 594
Joined: Sun Oct 11, 2009 9:57 am
Current Project: cocos2d-x project
Favorite Gaming Platforms: SNES, Sega Megadrive, XBox 360
Programming Language of Choice: C/++
Location: Belfast, Ireland
Contact:

Re: map editor help

Post by MrDeathNote »

acerookie1 wrote:
eatcomics wrote:He has nothing to render images with... Since he's using the winapi he just can make windows and such, he needs another api for images... try SDL
im using sfml. i just need the concept of how to do it. to render the images.
I'm a little confused as to what you need help with. Do you mean you don't know how to render an image in sfml or do you mean you don't know how to render the map as a whole i.e. by looping through an array holding tile numbers?
http://www.youtube.com/user/MrDeathNote1988

Image
Image

"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
acerookie1
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 48
Joined: Fri Feb 12, 2010 12:46 pm
Favorite Gaming Platforms: PC, Wii, SNES, GameCube
Programming Language of Choice: C++

Re: map editor help

Post by acerookie1 »

MrDeathNote wrote:
acerookie1 wrote:
eatcomics wrote:He has nothing to render images with... Since he's using the winapi he just can make windows and such, he needs another api for images... try SDL
im using sfml. i just need the concept of how to do it. to render the images.
I'm a little confused as to what you need help with. Do you mean you don't know how to render an image in sfml or do you mean you don't know how to render the map as a whole i.e. by looping through an array holding tile numbers?
editing it as a whole.
Image
User avatar
Moosader
Game Developer
Game Developer
Posts: 1081
Joined: Wed May 07, 2008 12:29 am
Current Project: Find out at: http://www.youtube.com/coderrach
Favorite Gaming Platforms: PC, NES, SNES, PS2, PS1, DS, PSP, X360, WII
Programming Language of Choice: C++
Location: Kansas City
Contact:

Re: map editor help

Post by Moosader »

Though the source code is a bit messy, have you looked at MusuGo? The code is there to show how I had it detect when a tile on the map was clicked and changing the tile, and having a scrolling tileset to go through, and level saving/loading.
acerookie1
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 48
Joined: Fri Feb 12, 2010 12:46 pm
Favorite Gaming Platforms: PC, Wii, SNES, GameCube
Programming Language of Choice: C++

Re: map editor help

Post by acerookie1 »

Moosader wrote:Though the source code is a bit messy, have you looked at MusuGo? The code is there to show how I had it detect when a tile on the map was clicked and changing the tile, and having a scrolling tileset to go through, and level saving/loading.
i have looked through the source from musgo. what seems to confuse me is where your drawing it and it seems to be more object oreiented than previous releases and its taking me longer to understand whats going on than before. i lost the old source code i was referencing by moving to another computer. :nono: i'm working on trying to figure it out my self. :lol: gotten 60% there thanx to ur tutorials, moosader.
Image
User avatar
Moosader
Game Developer
Game Developer
Posts: 1081
Joined: Wed May 07, 2008 12:29 am
Current Project: Find out at: http://www.youtube.com/coderrach
Favorite Gaming Platforms: PC, NES, SNES, PS2, PS1, DS, PSP, X360, WII
Programming Language of Choice: C++
Location: Kansas City
Contact:

Re: map editor help

Post by Moosader »

I'll try to step through the code for ye once I get home or something.
acerookie1
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 48
Joined: Fri Feb 12, 2010 12:46 pm
Favorite Gaming Platforms: PC, Wii, SNES, GameCube
Programming Language of Choice: C++

Re: map editor help

Post by acerookie1 »

um ok. :worship: :bow: :worship: :bow:
Image
User avatar
Moosader
Game Developer
Game Developer
Posts: 1081
Joined: Wed May 07, 2008 12:29 am
Current Project: Find out at: http://www.youtube.com/coderrach
Favorite Gaming Platforms: PC, NES, SNES, PS2, PS1, DS, PSP, X360, WII
Programming Language of Choice: C++
Location: Kansas City
Contact:

Re: map editor help

Post by Moosader »

The array
Okay, so first you're obviously going to need an array. What is the array going to be of? An array of tiles, which you create yourself...

Code: Select all

class Tile
{
    private:
        int x, y, w, h, fx;
        bool solid;
    public:
        Tile();
        void Setup( int tx, int ty, int tw, int th, int tfx, bool tsolid );
        void Draw( BITMAP *buffer, BITMAP *tileset, int xOff, int yOff );
};
I have variables storing X, Y, W, H, and "FX", where FX is the X-coordinate on the filmstrip. My filmstrip is only one tile high, one long strip, so I only need the x coordinate.
>> I would probably change the x, y, w, h to an SDL_Rect or Rectangle object now.

Drawing the map
My array is 1D because it's easier to make it dynamic that way, I was lazy ;P But 2d or 3d is probably more "intuitive". It doesn't matter much, as their coordinates are stored inside of the Tile instance anyway.
To draw the map, you just call a function that calls each Tile's draw function.

Code: Select all

void Tile::Draw( BITMAP *buffer, BITMAP *tileset, int xOff, int yOff )
{
    if ( fx != 0 && fx != 1 )
    {
        masked_blit( tileset, buffer, fx, 0, x-xOff, y-yOff, w, h );
    }
    if ( fx == 1 )
    {
        line( buffer, x-xOff, y-yOff, x-xOff+w, y-yOff+h, makecol( 255, 0, 0 ) );
        line( buffer, x-xOff, y-yOff+h, x-xOff+w, y-yOff, makecol( 255, 0, 0 ) );
    }
}
On my filmstrip, the first tile was empty, so the first if-statement is to tell it to draw if it is NOT the blank tile (just extra work). I think fx = 1 denotes a collision tile, which would be for a special layer. Not sure why I did it this way, code is old. :P


Checking what the mouse clicks
So that would draw the map, how about clicking a tile to change it?

Under my "if ( mouse_b & 1)" code (for left-click):

Choosing a tile from the tileset

Code: Select all

if ( mouse_y < 32 ) //choosing tile
{
	cursor.SetFx( (( mouse_x + tileScroll ) / 32 ) * 32 );
}
My tileset was displayed on the top of the screen, between y=0 and y=32, so it's saying if the mouse's y coordinate is above that region, they're clicking on the tileset to choose a tile.

Scrolling the map

Code: Select all

else if ( mouse_y < 60 && mouse_x < 138)
{
	HandleButton( &cursor, &level[levelIndex], &winTile, &tileScroll, imgTileset->w, mapSave, mapLoad, &system, MAX_X, MAX_Y );
}
This is just the little scrolling buttons I had in my map editor, not important. Adjusts the scrolling of the tileset.

Clicking a button on the bottom menu

Code: Select all

else if ( mouse_y >= winSub.Y1() )  //on bottom menu
{
	cursor.SetClick( true );
}
This would just be hitting a button on the bottom menu.

Clicking on the map to change a tile

Code: Select all

else    //on level
{
	level[levelIndex].CheckClick( &cursor, 1, MAX_X, MAX_Y );
}
This would be clicking in the map region, setting a tile to whatever the brush currently is (more later).

What are behind those functions?

Selecting a tile off the tileset

Code: Select all

cursor.SetFx( (( mouse_x + tileScroll ) / 32 ) * 32 );
This is just a basic Set function for the Brush object cursor. It is setting the brush by telling it what x coordinate on the filmstrip to draw from.

This might look a little confusing, but it's the mouse position on the tileset, offset by how much the tileset is scrolled. I don't know why I divided and multiplied by 32. Old code. ;P

Drawing onto the map

Code: Select all

level[levelIndex].CheckClick( &cursor, 1, MAX_X, MAX_Y );
The Level item has a function to check which tile the mouse's x and y coordinate correspond to.

Code: Select all

void Level::CheckClick( Brush *mouse, int click, int MAX_X, int MAX_Y )
{
    //See if a tile was clicked
    int mx = ( mouse_x + xOff ) / 32;
    int my = ( mouse_y + yOff ) / 32;
    
    int tLayer = mouse->Layer();
    int tBrush = mouse->Fx();
mx and my are the "index ID" of the tile, instead of storing the pixel location.
TILE mx = 3 is at (3*32) or fx = 96.

The current layer is stored in the brush (essentially just an integer), and the current brush pixel-x coordinate on the filmstrip.

Code: Select all

if ( click != 1 )
        tBrush = 0;
If the mouse is right-clicking, then it erases the current tile instead of drawing something.

Code: Select all

if ( mx < MAX_X && my < MAX_Y ) 
    {
        tile[ tLayer ][ mx ][ my ].FX ( tBrush );
    }
If the tile the mouse is clicking is within the array of tiles, then set that tile's FX coordinate to the brush FX coordinate given.

Code: Select all

if ( mouse->Size() == 3 )
    {
        if ( mx-1 < MAX_X && my < MAX_Y ) 
            tile[ tLayer ][ mx-1 ][ my ].FX ( tBrush );
        if ( mx+1 < MAX_X && my < MAX_Y ) 
            tile[ tLayer ][ mx+1 ][ my ].FX ( tBrush );
        if ( mx < MAX_X && my-1 < MAX_Y ) 
            tile[ tLayer ][ mx ][ my-1 ].FX ( tBrush );
        if ( mx < MAX_X && my+1 < MAX_Y ) 
            tile[ tLayer ][ mx ][ my+1 ].FX ( tBrush );
        if ( mx-1 < MAX_X && my-1 < MAX_Y ) 
            tile[ tLayer ][ mx-1 ][ my-1 ].FX ( tBrush );
        if ( mx-1 < MAX_X && my+1 < MAX_Y ) 
            tile[ tLayer ][ mx-1 ][ my+1 ].FX ( tBrush );
        if ( mx+1 < MAX_X && my-1 < MAX_Y ) 
            tile[ tLayer ][ mx+1 ][ my-1 ].FX ( tBrush );
        if ( mx+1 < MAX_X && my+1 < MAX_Y ) 
            tile[ tLayer ][ mx+1 ][ my+1 ].FX ( tBrush );
    }
}
This is an extension of the drawing, if the brush is of size 3 instead of 1, it sets the eight surrounding tiles to the same brush.



Let me know if this helps.
User avatar
Arce
Jealous Self-Righteous Prick
Jealous Self-Righteous Prick
Posts: 2153
Joined: Mon Jul 10, 2006 9:29 pm

Re: map editor help

Post by Arce »

I would help, but I know nothing about map editors...

Sorry!
<qpHalcy0n> decided to paint the office, now i'm high and my hands hurt
User avatar
Moosader
Game Developer
Game Developer
Posts: 1081
Joined: Wed May 07, 2008 12:29 am
Current Project: Find out at: http://www.youtube.com/coderrach
Favorite Gaming Platforms: PC, NES, SNES, PS2, PS1, DS, PSP, X360, WII
Programming Language of Choice: C++
Location: Kansas City
Contact:

Re: map editor help

Post by Moosader »

Arce wrote:I would help, but I know nothing about map editors...

Sorry!
lol
User avatar
MrDeathNote
ES Beta Backer
ES Beta Backer
Posts: 594
Joined: Sun Oct 11, 2009 9:57 am
Current Project: cocos2d-x project
Favorite Gaming Platforms: SNES, Sega Megadrive, XBox 360
Programming Language of Choice: C/++
Location: Belfast, Ireland
Contact:

Re: map editor help

Post by MrDeathNote »

Arce wrote:I would help, but I know nothing about map editors...

Sorry!
Lol, when you lie at least make up something believable
http://www.youtube.com/user/MrDeathNote1988

Image
Image

"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
User avatar
Trask
ES Beta Backer
ES Beta Backer
Posts: 738
Joined: Wed Oct 29, 2008 8:17 pm
Current Project: Building a 2D Engine
Favorite Gaming Platforms: Sega Genesis and Xbox 360
Programming Language of Choice: C/C++
Location: Pittsburgh, PA
Contact:

Re: map editor help

Post by Trask »

Arce wrote:I would help, but I know nothing about map editors...

Sorry!
Lulz.

I actually know nothing about making one(unlike some people featured in the AiGD series), but Moosader's insight here is giving me a good understanding on how to begin. Thank you!
MarauderIIC wrote:You know those people that are like "CHECK IT OUT I just made Linux run on this piece of celery [or other random object]!!"? Yeah, that's Falco, but with ES.
Dear god, they actually ported ES to a piece of celery!
Martin Golding wrote: "Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."
acerookie1
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 48
Joined: Fri Feb 12, 2010 12:46 pm
Favorite Gaming Platforms: PC, Wii, SNES, GameCube
Programming Language of Choice: C++

Re: map editor help

Post by acerookie1 »

thanx moosader! :bow: :worship: :bow: . you should really add this to your 2d map editor book.
Image
XianForce
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 767
Joined: Wed Oct 29, 2008 8:36 pm

Re: map editor help

Post by XianForce »

acerookie1 wrote:thanx moosader! :bow: :worship: :bow: . you should really add this to your 2d map editor book.
For sure... You may want to also consider adding deallocation of a dynamic 3D array... haha
User avatar
Moosader
Game Developer
Game Developer
Posts: 1081
Joined: Wed May 07, 2008 12:29 am
Current Project: Find out at: http://www.youtube.com/coderrach
Favorite Gaming Platforms: PC, NES, SNES, PS2, PS1, DS, PSP, X360, WII
Programming Language of Choice: C++
Location: Kansas City
Contact:

Re: map editor help

Post by Moosader »

XianForce wrote:
acerookie1 wrote:thanx moosader! :bow: :worship: :bow: . you should really add this to your 2d map editor book.
For sure... You may want to also consider adding deallocation of a dynamic 3D array... haha
Oy vey. I did, at one time, have a dynamic 3D array working. But MusuGo uses a 1D array lol. :p (it might use three/four separate 1D arrays, even. Laziness...)
Post Reply