im using sfml. i just need the concept of how to do it. to render the images.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
map editor help
Moderator: PC Supremacists
-
- 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
- MrDeathNote
- 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
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?acerookie1 wrote:im using sfml. i just need the concept of how to do it. to render the images.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
http://www.youtube.com/user/MrDeathNote1988
"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
"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
-
- 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
editing it as a whole.MrDeathNote wrote: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?acerookie1 wrote:im using sfml. i just need the concept of how to do it. to render the images.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
- Moosader
- 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
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.
-
- 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
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. i'm working on trying to figure it out my self. gotten 60% there thanx to ur tutorials, moosader.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.
- Moosader
- 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
I'll try to step through the code for ye once I get home or something.
-
- 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++
- Moosader
- 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
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...
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.
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
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
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
This would just be hitting a button on the bottom menu.
Clicking on the map to change a tile
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
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
The Level item has a function to check which tile the mouse's x and y coordinate correspond to.
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.
If the mouse is right-clicking, then it erases the current tile instead of drawing something.
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.
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.
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 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 ) );
}
}
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 );
}
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 );
}
Clicking a button on the bottom menu
Code: Select all
else if ( mouse_y >= winSub.Y1() ) //on bottom menu
{
cursor.SetClick( true );
}
Clicking on the map to change a tile
Code: Select all
else //on level
{
level[levelIndex].CheckClick( &cursor, 1, MAX_X, MAX_Y );
}
What are behind those functions?
Selecting a tile off the tileset
Code: Select all
cursor.SetFx( (( mouse_x + tileScroll ) / 32 ) * 32 );
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 );
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();
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;
Code: Select all
if ( mx < MAX_X && my < MAX_Y )
{
tile[ tLayer ][ mx ][ my ].FX ( tBrush );
}
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 );
}
}
Let me know if this helps.
Re: map editor help
I would help, but I know nothing about map editors...
Sorry!
Sorry!
<qpHalcy0n> decided to paint the office, now i'm high and my hands hurt
- Moosader
- 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
lolArce wrote:I would help, but I know nothing about map editors...
Sorry!
- MrDeathNote
- 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
Lol, when you lie at least make up something believableArce wrote:I would help, but I know nothing about map editors...
Sorry!
http://www.youtube.com/user/MrDeathNote1988
"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
"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
- Trask
- 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
Lulz.Arce wrote:I would help, but I know nothing about map editors...
Sorry!
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!
Dear god, they actually ported ES to a piece of celery!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.
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."
-
- 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
For sure... You may want to also consider adding deallocation of a dynamic 3D array... hahaacerookie1 wrote:thanx moosader! . you should really add this to your 2d map editor book.
- Moosader
- 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
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...)XianForce wrote:For sure... You may want to also consider adding deallocation of a dynamic 3D array... hahaacerookie1 wrote:thanx moosader! . you should really add this to your 2d map editor book.