• Advertisement
Sign in to follow this  

[Help] c++ SDL, (tetris like game) create or showing pieces Board?

This topic is 1374 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, i need some help with my tetris like game, im new in SDL, and  i can't figure it out how to add new pieces i can make a piece appears, and then, when it touches the bottom, a new piece appears, but its something like this...

 

SDL_BlitSurface( image, &sel1[frame], screen, ▭

rect.y++;

if (rect.y==348)
{
        SDL_BlitSurface( image, &sel1[frame], screen, &rect2);
}
so.. this code create a piece then it descends to the bottom then a new piece appears, but I have problem with the rect position.. i guess i need an SDL_Rect array? or something like that? ...I want it to continue appearing pieces indefinitely, do i need to create an array? or something like SDL_BlitSurface = NEW SDL_BlitSurface ? like in C#... im pretty sure that i missing something important here....
 
And also need to know when i need to clear the line? I don't know how to set the condition .... something like if (the first space is occupied && the second is occupied && etc..) but how do i know that the space is occupied?
 
This is kinda what i have:
 
SDL_Surface* screen, *image;
screen = SDL_SetVideoMode( 186, 348, 32, SDL_SWSURFACE );
SDL_FillRect(screen,&screen->clip_rect,color);
SDL_BlitSurface( image, &sel1[frame], screen, &inPos);
 
...so with this i dont think that i can make a comparison for the if...the only thing that i can think is something like ... if (rect.y==348)/*Bottom*/ , and /*&&*/ rect.x==0 /*left*/ then ... the first space is occupied but how can i know that an image is in there? ... i guess i need some graphic comparision o i dont know wacko.png sad.png i saw in a tetris tutorial something like this:
 
0   0   0   0
0   0   0   0
0   0   0   0
0   0   0   0
1   0   1   0
but is something like a board but i cant find anything about this in SDL ... do i need OPENGL? its a little confusing :S ... sorry if im too noob with game programing and thank you all for your help unsure.png
 
TL;DR?.. my 2 questions are: how to create or appear pieces indeterminately or forever... And How I can compare or know that all the spaces are filled to clear a line? ..only with c++ and SDL?
thank you very much!!sad.png

Share this post


Link to post
Share on other sites
Advertisement

Okay so your problem is probably not SDL itself, but how to build your code. SDL is only for the output, all the game logic has to come from you.

So what you need is a 2 dimensional array for the field, in which you save the states of each space.

To render that field you go over it and tell SDL to render something at the appropriate spaces.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement