Archived

This topic is now archived and is closed to further replies.

_Hybrid_

please help =) tilebased map ...

Recommended Posts

_Hybrid_    122
ok, here i come... with sort of a dumb question : hmmm, how to tell my problem... well, i want to make a tiny tilebased program like pacman the problem is that i dont know how to make the map routine! i want a routine which looks like this : #define GRASS 0 //i use different graphics for #define STONE 1 //every ground structure, of course =) #define WATER 2 // #define PLAYER 3 // int map_load() { int map[5][5] = { //now a simple map... {0,0,0,1,1}, //with the defined elements {0,1,2,0,0}, {0,1,2,2,2}, {1,1,0,0,2}, {3,0,0,2,2} } //BUT WHAT HAS TO BE HERE??? //i want the map to be displayed on the screen with a //for-routine(for(x=0;....) // } HOW(!!!) do i do that ? i have made some simple graphics already, and im using the DJGPP compiler with the ALLEGRO game library who can post some code??? thx, Freddy

Share this post


Link to post
Share on other sites
Jonus    170
Well first i will need to copy the 'tiles' to the 'backbuffer-surface' which you later 'flip' with the 'primary-surface'.

I don't know allegro. And i am a kind of noobee myself but i guess the loop must look like:
copy_bitmap_to_backsurface(char * texture,int tile_height,int tile_height,int tile_nr)
{

}

for(int x=0;x<5;x++)
for(int y=0;y<5;y++)
{
   copy_bitmap_to_backsurface("myCrazyBMP",48,48,map[x][y]);
}

flip_surface();


I don't know how the copy_bitmap_to_backsurface function must look in your program and how to implement it with allegro.

Edited by - Jonus on August 1, 2001 7:03:18 AM

Share this post


Link to post
Share on other sites
_Hybrid_    122
thx...

i tried it that way u described, but it doesnt work
i think i has to be done anything like this(with arrays in a array )

FOR(x=0;x<5;x++)
FOR(y=0;y<5;y++)
copy_bitmap_to_backsurface(BITMAP[bmp],height,widht,...)

i got problems finding out which bitmap the program has to load(water, stone, player, grass, etc)

i shall work like a parser, or something like that...
the program ''reads'' the map structure and then ''prints'' the bitmap on the screen

copy_bitmap_to_backsurface(bitmap[map[x][y]],...) perhaps like that...

cheers, freddy

Share this post


Link to post
Share on other sites
Derilect101    122
Yup you got it the Bmp[map[y][x]] will work to find out what graphic to draw at that location! Also I think there are some decent windows compilers out there I would switch to direct draw or direct 3d or opengl. More compatible and I personally think easier to use! Dunno if you have done any windows programming before but its scary looking at first but not that bad everything is the same just has different names plus you''ll save yourself a headache I think I tried to write a decent tile engine using allegro(isn''t that also hair growth stuff?)and boy that wasn''t fun! Opengl which I prefer after working with Direct Draw (havent tried D3d yet) is pretty easy to do 2d in and 3d one you set up the main windows loop and setup the window and stuff...you dont have to worry about it anymore and focus on logic also Direct Input is a wonderul API! Microsoft will make it so you have to conform sooner or later so why not now!

Share this post


Link to post
Share on other sites
_Hybrid_    122
thx derilect!

i tried to do it like i guessed... but it does only print one bitmap, even if i make a map with another structure...

but u told me to use openl.. i know that it is the 'best' api but i even dont understand the main loop to init opengl

could u give me some hints where to begin coding in opengl??

and can u give me some hints what compiler i could use then... dont tell me to use microsoft visual c++

most likely i would like to code opengl with LCC if u know this one...

cheers

Edited by - _Hybrid_ on August 1, 2001 8:07:38 AM

Share this post


Link to post
Share on other sites
shalom    122
Why don''t you want to use VC++? Everyone uses it, and despite the fact that its Microsoft, it is the industry standard.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
VC++ happens to be one of the only good programs Microsoft has ever made, you should at least give it a go ;-)

Share this post


Link to post
Share on other sites
Dino    172
If you want a compiler recommendation I highly recommend Borland''s compiler. It makes a leaner and usually fast executable than MSVC++. Visual C++ is a bit too bloated and slow for my tastes, however it''s IDE is usually better than Borland''s. I personally use Borland C++ Builder 5 and I love it. It strips out all the dead code from the compiled EXE, but it''s IDE is a bit buggy at times I have found.

The Borland compiler is also free for download. It is just the compiler though, there''s no interface to it.





Dino M. Gambone
Good judgement is gained through experience. Experience, however, is gained through bad judgement.



Share this post


Link to post
Share on other sites
Jonus    170
quote:
Original post by _Hybrid_
I tried it that way u described, but it doesnt work
i think i has to be done anything like this(with arrays in a array )

FOR(x=0;x<5;x++)
FOR(y=0;y<5;y++)
copy_bitmap_to_backsurface(BITMAP[bmp],height,widht,...)


No i don''t think that your problems are related to the map structure or the for-loop.(btw why is FOR capitalized?)

quote:
Original post by _Hybrid_
I got problems finding out which bitmap the program has to load(water, stone, player, grass, etc)


Which bitmap? First, all your map-tiles should be on in ONE bmp-file. And then you can make something like:

struct stiles
{
flaot x1,x2,y1,y2;
}

sTiles MAP_TILES[5];
// Then init the array with coorrect source coordiantes

quote:
Original post by _Hybrid_
i shall work like a parser, or something like that...
the program ''reads'' the map structure and then ''prints'' the bitmap on the screen

copy_bitmap_to_backsurface(bitmap[map[x][y]],...) perhaps like that...


This function should look like:

copy_bmp(sTiles & source_rect,target_x,target_y,nummber)
{

}

Share this post


Link to post
Share on other sites
Derilect101    122
Yeah the reason ya got only 1 bitmap is because you need move move them over or you''ll just keep drawing one on top of the other so just keep track of your x and y locations so first tile lets say draws from 0-31 on the x and 0-31 on the y. for the next tile start at 32-64 on the x and keel 0-31 on the y until you have to draw the next row and so on

Share this post


Link to post
Share on other sites
Derilect101    122
Forgot to mention too that nehe.gamedev.net has really good OpenGl tutorials and it explains the code real well also after the first couple lessons on there you should start getting the hang of it also Opengl isn''t the "best" api its just a nice one and direct 3d is comparable...its all a matter of preference really. theres a D3d sight nexe.gamedev.net if ya wanna give D3d a go see which one you prefer!

Share this post


Link to post
Share on other sites
_Hybrid_    122
hmmm, thx for those hints...

but i wont use any of your compilers, cause i have been programming with it for a while now and its executable size is 1/8th of the size of microsoft i think...

cheers

Share this post


Link to post
Share on other sites
Ksero    262
If you still want that code, here it is... I haven''t tried it... I don''t have a compiler here, but this is basically what you want to do...
  
BITMAP *graphics[4]; //four different tiles


graphics[0] = load_bitmap("grass.bmp");
graphics[1] = load_bitmap("stone.bmp");
//And so on...


//All tiles have same width and height

int tilew = graphics[0]->w;
int tileh = graphics[0]->h;
for(int x=0;x<5;x++)
for(int y=0;y<5;y++)
{
blit(graphics[map[x][y]],screen,0,0,tilew*x,tileh*y,tilew,tileh);
}

//Ksero

Share this post


Link to post
Share on other sites