Welcome! Log In Create A New Profile


Maps for Liqwiid Wars

Posted by steaky1212 
Maps for Liqwiid Wars
June 30, 2009 12:55PM

Most of the algorithm is down for my version of Liquid Wars.
However, to get closer to Liquid Wars I need to have maps. I am semi-content on hardcoding 1 map for testing, but would like a much cleaner/better way of doing it - involving importing a bmp/png/jpeg etc and LiqwiidWars assigning map properties given the picture.

So have a folder of png's (or whatever) and a specific colour (or transparency) is the WALL. Is there a neat way of doing this, or do I just load the map, put a countdown to start and while its counting down run through every pixel and depending on the colour there set a WALL array.

I was basically hoping for a way to "read" the picture without displaying it, then when the WALL is set up display everything and start the game.

Re: Maps for Liqwiid Wars
June 30, 2009 04:12PM
lol, there is no magic "convert_bmp_to_easycollidable_array_of_objects()" function.

I hate to say this, but to ruin your hopes and dreams:
-Programming isn't magic
-Standard official C++ isn't as standard and official as you would think.


To solve what you are doing, there are several ways to go about it. First off, I imagine you have some sort of collision system in place, where you have a way of testing if an object collides with another object, and both of those objects can be drawn. If that is not true, then you need to step back and get those in place.

Next, you need to iterate through a monocolored bitmap, it would literally be 0 and 1. If it is 1, create an object at X,Y to collide with, if 0, skip to next pixel. You could also do 0 and 255 of Red, Green, or Blue if you don't know how to do a monocolored bitmap, and you only know how to do a png or something.

here is an example:

the bitmap:

I assume you know how X,Y works, so here is some psudocode for how to interpret the above (Not sure how you read pixels, but I assume they are in a 1D array

    //DO NOT copy paste this code, it won't work. This is just to give you a concept of how to go about
    //solving your problem.
    int imgwidth = 4;
    for (int i=0; i<sizeof(bitmap); i++)
        //we assume you extracted bitmap to some kind of array
        //you could also do bitmap as it is the same thing as *(bitmap+i);
        if (*(bitmap+i) == 1)
            //addobject is a magic function that adds a collidable box to some collection
            //addobject( x , y )

the level should look like the bitmap, but with objects.
That would be the conceptually elegant way to go about it.
Re: Maps for Liqwiid Wars
June 30, 2009 04:33PM
lol, there is no magic "convert_bmp_to_easycollidable_array_of_objects()" function.

I hate to say this, but to ruin your hopes and dreams:
-Programming isn't magic
-Standard official C++ isn't as standard and official as you would think.

I know both of these things already, but I didnt know if there was a way of reading off the graphics buffer before displaying it.

I know GRRLIB has a function to check the value for each coord, so I might just have a countdown timer for like 5secs, and use a particular colour for the map walls. Step through each pixel on the map and set values in a 2d array accordingly.
This should work so long as the size of the array is the same as or bigger than the map.
Re: Maps for Liqwiid Wars
June 30, 2009 05:04PM
Ok, well I learned early on when making roguelike games for the PC, that you DO NOT want to use an array to represent a map. While it may seem intuitive, it actually leads to so many problems down the road.

Instead, do a 1D array (or a vector, preferably) that just stores the pointers to objects, and in each object store the X,Y coordinates of the object.

I say a vector because then you do not have to worry about the size of the map, and you don't have to work with malloc();

so, just use my above psudocode and instead of using addobject us

tempobj = new myBlock(x,y);

I would say

myvector.push_back(new myBlock(x,y));

but when I tried to compile it like that, it just crashed, horribly, even though it should work...

Also, learn pointers, they may seem complicated, but once you figure out what it means, it makes programming so much easier.

(Don't be afraid to use the best aspects of C and C++, the combination of both we call C+)
Re: Maps for Liqwiid Wars
June 30, 2009 08:58PM
You can use simple image formats like bmp or even create your own... you can handle them offscreen as you wish then... you can find myriads of bmp routines in C I guess...
Re: Maps for Liqwiid Wars
June 30, 2009 09:08PM
There are no standard library or any libraries at that which will do the work for him.

The only routines I can think of would just load the image into a usable form. After that, he has to write his own interpreter for the data.
Re: Maps for Liqwiid Wars
June 30, 2009 09:19PM
There are no standard library or any libraries at that which will do the work for him.

The only routines I can think of would just load the image into a usable form. After that, he has to write his own interpreter for the data.

Well his main problem at the moment seemed to be reading pixel by pixel from an image loaded without actually displaying it...

@steaky1212 : By the way, what with the countdown timer and reading graphics offscreen? You don't need a timer for that thing... Either Grrlib allows it or forces you to use getpixel functions solely on screen... don't know the limitations... but you can always resort to a simpler format to read the map... (bmp, xbm or your own..)

Such formats being so simple you can directly convert the map you read into your internal data format... you build a hashtable, vector, matrix, array... that's another problem...
Re: Maps for Liqwiid Wars
June 30, 2009 09:32PM
@steaky1212: What are you currently using to draw?

You can usually get the raw data of the image before you pass it to the screen to be drawn, unless you are drawing to the screen directly through your own methods... in that case... @_@
Re: Maps for Liqwiid Wars
June 30, 2009 10:14PM
wow, a lot has been written in that short time.

The plan was to draw the map as a background.
set the walls up.
Populate a 2(maybe 3) dimension array to hold the army fighters.
move the fighter according to algorithm
output the fighter positions

(I learnt the array "trick" doing homebrew for gameboy and it worked fine)

as of yet, i havent done any real work on the GUI as need to have count-down timer for game anyways, plus army population.

ATM I am outputting video with all the VIDEO_SetNextFramebuffer(xfb) etc stuff, as opposed to a separate library/wrapper.
I am assuming you can set and get using
fb[rmode->fbWidth/VI_DISPLAY_PIX_SZ*py + px] = color

this way I can set the individual pixels, and presumably I can read the value too (for the walls)

but atm I havent output a background/map
Re: Maps for Liqwiid Wars
July 01, 2009 12:21AM
Ack-- I had a feeling you were doing that -_-... well, that means you have to start from scratch and write some new functions!

First off, I highly advise against storing them in an array and using their location in the array to hold their X,Y values. Instead of changing two values to represent the data, you are moving around whole chunks of memory just to represent two variables. I could go on and on about how it is a bad idea, but +shrugs+ whatever dude~ I won't bring this up any more.

So, since you are writing directly to the output, how do you do it currently? Do you just write to it directly or do you have your own sprite library created?

I have a feeling you are writing to it directly, which means a lot more explaining from me, and I can just HOPE you have your own sprite library +crosses fingers+

and by writing to it directly I mean like

fb[x+width*y] or *((fb+x)+y) or *(fb+x+y+width)

or one of many other ways of accomplishing that.
Re: Maps for Liqwiid Wars
July 02, 2009 08:53AM
this would be a bad time to say directly then :s
looks like I'm starting it from scratch then :p

in which case, i really dont like pointers, and i never understood why people would use them. maybe i can get to a point of using em - but not liking it.

Surely if I store everything in 2d arrays then the algorithm to give gradient is in array, fighters are in array, map in array, it gets really easy to see where everything is in relation to everything else.

how would you do it if you were me? (this isnt a "do it for me" its just asking for advice).
Re: Maps for Liqwiid Wars
July 02, 2009 09:41PM
fyi, arrays are just pointers. Trust me, if you like arrays, then you will surely love pointers.

The seperation of things into "layers" like that are nice, and could work.

What you do is you have a singleton or global variable containing the "map" array. You don't have to make it global or a singleton, but if everyone can access it, it will be a lot easier than passing it back and forward inbetween functions.

Now, this array will be your map, you can either make a "map" file that the game reads from to load it, or hardcore it for testing. If you need me to expand on those two things, tell me and I will write some psudocode for you.

Now, you have your array that holds the map. Now, write a function that just loops through this array and maps it to the screen, like:

    for each (x in maparray){
        for each (y in maparray)
            screen[x][y] = maparray[x][y]==1?WHITE_COLOR:BLACK_COLOR;
how it works should be self explanitory. If you are unfamiliar with how "?:" works, just tell me, and I will explain what that did in terms of if and else (no use explaining it if you already know :P)

This would allow you to make your maparray a collection of char or int, so your map would look like:

or something like that, making hardcoding it simple as:

char maparray[ ][ ] =

It isn't a COMPLETE rewrite of the system, just a few modifications that will make the code easier to work with.

Feel free to ask as many questions as needed or ask me to explain something better or in more detail.
Sorry, only registered users may post in this forum.

Click here to login