Archived

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

ZadrraS

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

Recommended Posts

ZadrraS    157
it took me a while to realize that im stuck, i started my tetris clone, but i can''t make that when the brick lands, it would restart at the top while a new one is created at the place where the old one lands (if thats even the right way to do it...). How do i do that that (my english sucks too ) a brick that landed would be redrawn every frame, the same if there would be 5 bricks at the bottom, all of them should be redrawn every frame. So, how do i do that? Or, maybe there is a "more right" way to do it than mines...

Share this post


Link to post
Share on other sites
Endurion    5408
Distinguish the play field and the falling bricks.
Once a brick is landed add it to the play field (consider the play field ONE big object if you want) and destroy it.
Create a new brick on top.

Share this post


Link to post
Share on other sites
leiavoia    960
you could also consider the playing field as a 2D array of tiles. When a falling "tetrad" object falls and contacts the bottom, it becomes 4 blocks, each block inhabiting a tile on the array. the array or "field" object would have calls like:

bool IsBlocked( int x, int y ); // check to see if inhabited.

Share this post


Link to post
Share on other sites
ZadrraS    157
I only have 1 block falling, i didn''t make "tetrads" yet. Should i make an array that would store whats in that place? My tetris is 400x and 800z. All the bricks are 40x40 size, making my game 20x10 tiles.
Sory for sounding/being stupid, but im only a beginner and my english skills suck too..

Share this post


Link to post
Share on other sites
you know, i actually wanted to make a tetris clone, but i couldnt figure out (in my head) how the hell to rotate the blocks. so i decided to make pacman instead, thinking it would be easier. well i could personally say to stick to testris. this wasnt easier . i had a lot of fun though and i learned a lot, i even made a map editor for it. i still couldnt tell you how the hell to rotate a tetris block tho

[edited by - graveyard filla on March 23, 2004 1:04:23 PM]

Share this post


Link to post
Share on other sites
leiavoia    960
well, with tetris, there must be a thousand and one ways to do it, i''m sure. I''m just suggesting the route i might take.

i would create the "Well" class. It''s the 10x20 array of "Block" classes. Blocks can be either filled or not filled, and a variety of colors:


class Block {
SDL_Color color;
bool filled
}

class Well {
Block blocks[10][20];
bool IsFilled( int x, int y ) { return blocks[x][y].filled; }
bool SetFill( int x, int y, bool f ) { blocks[x][y].filled = f; }
}


A tetrad then, would just be a collection of 4 X/Y pixel coords on the well. When the pixel coords reach an "even number" (that is, divisible by 20 if you have 20x20 tiles), you check for collisions. If no collisions, keep going. If collision: take each of the 4 "blocks" and make them "become one with the well" by calling SetFill() for each of the 4 positions in the tetrad; Then check for cleared lines, etc.

... or something like that.

Share this post


Link to post
Share on other sites
ZadrraS    157
Ok.... im still having tons of problems... How do i check and change each tiles in the screen status? It would take 200 if and elses to do that( or even more):

if (y==760) {
if (x==0) {
map[20][1]=1;
else if (x==1) {
map[20][2]=1;
}
}

and etc...
So, whats the right way to do it?

Share this post


Link to post
Share on other sites
i dont understand your questoin... could you describe what your trying to accomplish better? more english and less code also, what about for loops? something like

for(int x = 0; x < MAX_WIDTH; x++)
{
for(int y = 0; y < MAX_HEIGHT; y++)
{
if(map[x][y] == whatever)
do stuff;
}
}

Share this post


Link to post
Share on other sites
ZadrraS    157
im just damn confused .. my screen is made of 10x20 blocks, every block is 40x40 pixels... i have an array called map[10][20] and i need to check every block, is it occupied.. And when/if i do that, i have no idea how to continue

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
ZadrraS    157
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]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
ZadrraS    157
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
ZadrraS    157
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.

Share this post


Link to post
Share on other sites