Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Getting Started with Mappy

This thread is locked; no one can reply to it. rss feed Print
 1   2 
Getting Started with Mappy
MaximumCDawg
Member #16,079
September 2015

Hello all,

I'm trying to make the move from designing games using engines other people built to using C++ with Allegro to make my own. So far so good on the coding side of things; I'm learning the library and how C++ works well enough. I'm up to the point where I'd like to use mapping utilities to make larger tile maps.

Mappy seems like it does exactly what I want, and I'm working on learning that. I've run into an early snag, however. When I load a tilesheet into Mappy for use, it garbles the tile positions so that it makes it nearly impossible to design a map in any reasonable amount of time. Blocks that should be next to each other to allow quick drawing are moved around, and it actually gets worse as you zoom in and out; things move again. What is nicely lined up in my grid out of Mappy gets rearranged in Mappy.

I'd like to know if there's a way to move around the tiles within Mappy in what I'll call the "tile palette" window, for lack of a better term. The Mappy forums are locked up and I can't post there, so I thought I'd try here!

Any thoughts or suggestions?

beoran
Member #12,636
March 2011

Personally, I've had more success with Tiled (http://www.mapeditor.org/) than with Mappy. You can program support yourself or use https://github.com/dradtke/allegro_tiled for allegro 5 to use Tiled tile maps.

MaximumCDawg
Member #16,079
September 2015

Does Tiled have the functionality of being able to move tiles around in your "palette" window so you can organize them before actually starting to paint the map itself? I mucked around on the Tiled website and I didn't see a reference to this.

If neither Mappy nor Tiled has this capability (or if no one knows) then does anyone know of a way to break a png into tiles and allow the user to move them around as tiles to try and prepare them for input to a program like this? I suppose it would be an interesting programming exercise to make such an application myself, but I can't imagine this is a unique problem.

beoran
Member #12,636
March 2011

You can defile tile sets in tiled as you like, but I don't quire remember if you can reshuffle them later as this could cause the ID to change, so it's harder than it seems.

Why not try Tiled yourself, and see if you like it or not? It's free, so the only thing you have to lose is an hour or two to try it out...

MaximumCDawg
Member #16,079
September 2015

Sure, when I'm home after work today maybe I'll check it out. What I liked about Mappy was that integration with Allegro was super slick. If Tiled is just as easy, hey, maybe that's the way to go.

Either way, it looks like arranging the tiles is gonna be a pain in the caboose.

beoran
Member #12,636
March 2011

Actually, in my experience with Tiled, that's the least of my concerns. The tile sets are scrollable and easy enough to use. In the latest versions they gained animation. And tiled has some auto mapping features that make it easier to draw the map itself.

Matias Persson
Member #15,093
May 2013

If you create your own map editor which isn't that hard you can have it do exactly what you want :)

beoran
Member #12,636
March 2011

True, but it's normally easier to use an existing map editor while you are still developing your game engine.

Matias Persson
Member #15,093
May 2013

For some perhaps, I never could figure out how to properly use an existing map editor, not even with all the help I could get, so I developed my own with help from a friend and turned out to be a lot easier for me.

MaximumCDawg
Member #16,079
September 2015

I'm floating between your opinions here. (Havn't had enough time to try Tiled yet.) What bugs me about Mappy is that it loads a single PNG or whatever and then carves it up into tiles, instead of letting the user open a tile and set the graphic specifically for that tile. You lose a ton of flexibility in tile creation when you're anchored to the exact source image like that.

beoran
Member #12,636
March 2011

Tiled is more flexible, IIRC, you can load several images to make a single tile set. Just give it a try already... :)

MaximumCDawg
Member #16,079
September 2015

I did, and it does! Tiled organizes the tilesheets in a much more sensible way and -- critically -- it doesn't cock up the ordering when you zoom in and out. Very usable.

But, I'm told that Tiled doesn't come equipped with a library or API I can just include to draw maps in Allegro. Apparently I have to build my own "parser," so that's something new to learn.

RPG Hacker
Member #12,492
January 2011
avatar

Actually, that's not true. There is at least a C library that parses Tiled maps for you, I have worked on it myself. It is slightly outdated, but most of the functionality should still work with the newest Tiled version. However, I think there even was a library that directly supported drawing Tiled maps to Allegro 5. You'll have to look somewhere on the Tiled website/wiki, I think it had a page where it listed all the libraries for Tiled support.

EDIT:
And here it is. It does mention Allegro 5 in the C section, so hopefully that will help you.

beoran
Member #12,636
March 2011

I already posted a link to a Tiled + Allegro5 API: https://github.com/dradtke/allegro_tiled :)

MaximumCDawg
Member #16,079
September 2015

Ugh. I'm using Visual C++ 2010, since it works with Allegro 5, and Mappy does not have existing utilities that work in this context, as far as I can tell.

So, in digging around the various information about Tiled, it's clear I don't even know what I don't know. I gather that, in order to use Tiled, I need to understand how to get information from an XML file. But there's zero useful tutorials I can find about how to go about doing that.

I mean, I want to learn this stuff, but I'm not even sure how to go about learning what I need to know to make an XML parser or fix those others have made...

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Rodolfo Lam
Member #16,045
August 2015

There is a fully functional Tiled map loader that supports both JSON and TMX files written in C here: (https://github.com/baylej/tmx). It has an Allegro example to show usage and it is a little bit simpler than allegro_tiled from dradtke (Specially on Windows with that glib dependency)... My current project uses it as the Tiled map parser and loader (https://github.com/rlam1/SuperGameCode)

About learning XML... It certainly helps to know it to manually edit the TMX file.. but the beauty of the libraries such as baylej/tmx is that all that is abstracted away in simple functions and it takes care of the details of parsing the XML file. All the heavy lifting is done with it and it presents to you standard C/C++ structs you can use to render your map in Allegro, the only thing it does not support is making changes to the map from it, but why would you do that in game?

MaximumCDawg
Member #16,079
September 2015

So, after puttering around with Tiled for awhile, I gave up and went back to Mappy. It works fine once you understand how to arrange the tiles so they load properly. Anyway, I had no trouble making a basic platformer using Mappy and some of the tile variables to control collisions. CurrentBlock->tl checking for solidity works like a charm.

Now, I've hit another snag. I want to use Mappy to place enemies, triggers, doodads, and that kind of thing on the map. There's apparently a "event layer" system built into Mappy, but I can't find a tutorial that is worth a poop explaining how to use it. Nor can I glean this from the .c file. There's a guide on someone's web site but it appears to describe an older version of Mappy. (http://www.swingame.com/wiki/index.php?title=Mappy_Tutorial)

Anyway, my work around idea was to simply reserve 50 tiles at the beginning of the map to use for flags that the engine would check and then act accordingly. Mappy provides several user fields, the first two being user1 and user2, unsigned longs. So, great: I can use user1 to specify a kind of event (enemy or doodad spawn, for example) and user2 to define what kind of enemy / doodad whatever to spawn. When the engine finds such a block, overwrite it to zero and then do something. Seemed logical.

So I wrote some code that, in theory, should accomplish this:

#SelectExpand
1 // --------------------------------------- 2 // Look for enemy and event tiles 3 // --------------------------------------- 4 5 int searchX = 0; 6 int searchY = 0; 7 BLKSTR* CurrentBlock; 8 for(searchX = 0; searchX < SCREEN_W; searchX += 32){ 9 for(searchY = 0; searchY < SCREEN_H; searchY += 32){ 10 CurrentBlock=MapGetBlockInPixels (searchX,searchY); 11 if(CurrentBlock->user1==1){ 12 CurrentBlock->user1 = 0; // Only act once 13 CurrentBlock->bgoff = 0; // Zero out the block 14 fprintf(stderr, "Saw an enemy"); 15 } 16 } 17 }

In reality... nothing happens. The code never even prints the fprint statement. There ARE tiles with a user1 field equal to 1 on the visible screen. If I swap out the "if(CurrentBlock->user1==1)" and replace it with "if(CurrentBlock->tl==true)" then it quickly sees all of the blocks on the screen and spams the print function. So why can't it see user1?!

RPG Hacker
Member #12,492
January 2011
avatar

Have you tried attaching a debugger and setting a breakpoint there to see what value CurrentBlock->user1 holds? Is "== 1" maybe not what you want, but rather ">= 1" or "!= 0"?

MaximumCDawg
Member #16,079
September 2015

I'll try that tonight, but if the user1 field is not actually holding the "1" I input using Mappy by the time I'm accessing it with Allegro, something is very wrong.

Mark Oates
Member #1,146
March 2001
avatar

What was Tiled not doing for you?

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

MaximumCDawg
Member #16,079
September 2015

It wasn't functional. At least, not in a way that a n00b like me could understand.

Tiled does not have a simple .h and .c (or .cpp) package for Allegro 5, Visual Studio 2010, that I can load up and gives me a ready-made way to parse the output files from Tiled and access the data in the map. Mappy does. So, while Tiled looks like it's better from a map-making standpoint, it would have required me to delve into more learning about how to parse its unique file type than I know at the moment.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

MaximumCDawg
Member #16,079
September 2015

Yeah, I ran across that, but I didn't know what to do with it. I get what Cmake does, conceptually, but I've never used it before. It sounded like I couldn't just plop all the .h and .c files into my project, include them, and go. Also, the description of that file says it doesn't work with Visual Studio, which is what I'm using.

And I read some reports on other forums about problems:
http://www.gamedev.net/topic/652356-having-trouble-using-tiled-with-allegro-5/

I didn't have any of those issues with Mappy. It was just plug and play.

Speaking of, is Mappy really that bad? It's starting to sound like the Tiled fan club up in here. Obviously, if it just doesn't work then I got no option, but still...

EDIT: I sauced it. It was a logic error! I had forgotten that GetBlockInPixels always measures from the corner of the MAPPY MAP, meaning I have to apply the offset as I wander around. Whoops!

<code start=1>
int searchX = 0;
int searchY = 0;
BLKSTR* CurrentBlock;
for(searchX = xOff; searchX < (SCREEN_W+xOff-1); searchX += 32){
for(searchY = yOff; searchY < (SCREEN_H+yOff-1); searchY += 32){
CurrentBlock=MapGetBlockInPixels(searchX,searchY);
if(CurrentBlock->user1==1){
CurrentBlock->user1=0;
fprintf(stderr, "%d \n", CurrentBlock->user5);
}

}
}
</code>

Rodolfo Lam
Member #16,045
August 2015

Mappy isn't bad ;D maybe it's just true we are the Tiled fanclub up there... If it works for you then congratulations! Keep up making something great.

On another note, yes, allegro_tiled is a pain to use on Visual Studio, Glib is apparently not welcome there and it uses that to store the map's list of properties among other things. I gave up on that one and instead used https://github.com/baylej/tmx but that one still uses cmake and not just simple .h and .c files to drop in a project. Try to leave that as a long term project when you gain more experience. Most libraries come in that format and its highly probable in the future you will benefit from using them instead of re-inventing the wheel all over again.

 1   2 


Go to: