[SDL] Multiple objects of the same type on the screen...

Started by
18 comments, last by ZadrraS 20 years ago
whats the problem? your going tile based? then you need enums to represent the tiles like this:


enum Tiles
{

OPEN,
BLOCKED,

};

now, you need to assign the values to the map[][] array. then you just do: (im assuming you have map[y][x] and not map[x][y]

for(int y = 0; y < 10; y++){      for(int x = 0; x < 20; x++)     {          if(map[y][x] == BLOCKED)             this tile is blocked;                    else if(map[y][x] == OPEN)              this tile is open;      }}


this will loop through each element of your map array and check its state. still a little confused on what your trying to do, but i hope this helps
FTA, my 2D futuristic action MMORPG
Advertisement
Just so you would know, im making a tetris. The problem with your code is that its 10x and 20y, but i have 400x and 800y. My tiles are 40x40... So: 400/40=10 horizontal cubes, 800/40=20 verticalcubes.

[edited by - ZadrraS on March 27, 2004 2:42:39 PM]
you need to give me more info... what is the current problem? are you trying to draw these tiles to the screen? regardless of anything, my code will work in checking each tile''s state. it sounds like you want to draw. if you want to draw, you just multiply the x and y * tilesize (40 in your case)... this is how you could fill up your screen with the testris game

for(int y = 0; y < 10; y++){      for(int x = 0; x < 20; x++)     {          if(map[y][x] == BLOCKED)             Draw(block,x*40,y*40);                    else if(map[y][x] == OPEN)              Draw(open_space,x*40,y*40);      }}


btw... 800x400? what kind of resolution is that? you meant 800x600?
FTA, my 2D futuristic action MMORPG
I need to set the y and x (your example) to BLOCKED or OPEN, i can''t do "if(map[y][x] == BLOCKED)" if the program doesn''t even know is it blocked or free.
i dunno, man, is this the initial status of the map[][]? if so, then just do

map[][] =
{{0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,} //x amount of numbers here
{ 0,0,0,0,0,1,0,0,0,0,0,1,0,0,1,}
//y amount of { } bracks here
//etc, if not already doing [y][x] then i suggest you change
because when initializing all the elements of an array like this, you can actually visualize it if you do [y] then [x]. oh , and if this still doesnt work, heres a pic of my game thats near completion (my take on pac-man) so i can contribute something worthwhile (at least in my mind)



[edited by - graveyard filla on March 27, 2004 3:30:52 PM]
FTA, my 2D futuristic action MMORPG
That didn''t really help, but thanks anyway, i think i figured out a way to do it myself And the pac-man clone looks good , don''t forget to post it somewhere when its finished.



"DonkeyPunch-Man", lol.
hehe, sorry i couldnt help. heres another pic just cuz im bored and want to show off my work ... i just blew up one of the enemies



[edited by - graveyard filla on March 27, 2004 3:46:43 PM]
FTA, my 2D futuristic action MMORPG
Ok. I didn''t get it.... Could somebody give me a source code to a simple tetris? Maybe then ill understand what i need.
go back to "view posts over 30 days" and find "build testris in an hour with c++". yes it doesnt use SDL but it still shold help. also, maybe your not ready for testris? try making pong or breakout or something
FTA, my 2D futuristic action MMORPG
That tut doesn''t really help much.. And i already done a pong clone.

This topic is closed to new replies.

Advertisement