Page 2 of 3

Re: map editor help

Posted: Thu Feb 18, 2010 5:05 pm
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.

Re: map editor help

Posted: Mon Feb 22, 2010 12:30 pm
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?

Re: map editor help

Posted: Mon Feb 22, 2010 3:35 pm
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.

Re: map editor help

Posted: Mon Feb 22, 2010 3:40 pm
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.

Re: map editor help

Posted: Mon Feb 22, 2010 3:52 pm
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.

Re: map editor help

Posted: Mon Feb 22, 2010 4:13 pm
by Moosader
I'll try to step through the code for ye once I get home or something.

Re: map editor help

Posted: Mon Feb 22, 2010 4:19 pm
by acerookie1
um ok. :worship: :bow: :worship: :bow:

Re: map editor help

Posted: Mon Feb 22, 2010 7:04 pm
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.

Re: map editor help

Posted: Tue Feb 23, 2010 1:54 pm
by Arce
I would help, but I know nothing about map editors...

Sorry!

Re: map editor help

Posted: Tue Feb 23, 2010 2:05 pm
by Moosader
Arce wrote:I would help, but I know nothing about map editors...

Sorry!
lol

Re: map editor help

Posted: Tue Feb 23, 2010 4:15 pm
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

Re: map editor help

Posted: Wed Feb 24, 2010 1:05 pm
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!

Re: map editor help

Posted: Wed Feb 24, 2010 3:21 pm
by acerookie1
thanx moosader! :bow: :worship: :bow: . you should really add this to your 2d map editor book.

Re: map editor help

Posted: Wed Feb 24, 2010 11:15 pm
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

Re: map editor help

Posted: Wed Feb 24, 2010 11:40 pm
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...)