Jump to content

  • Log In with Google      Sign In   
  • Create Account

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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 javiside   Members   -  Reputation: 104

Like
0Likes
Like

Posted 16 July 2014 - 12:48 AM

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


Sponsor:

#2 Flonk   Members   -  Reputation: 367

Like
0Likes
Like

Posted 16 July 2014 - 04:12 AM

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.



#3 sunandshadow   Moderators   -  Reputation: 5203

Like
0Likes
Like

Posted 16 July 2014 - 05:02 AM

Why on earth is this in the writing forum???  Moving it to a technical forum...


Phone game idea available free to someone who will develop it (Alphadoku game - the only existing phone game of this type is both for windows phone only and awful. PM for details.)


I want to help design a "sandpark" MMO. Optional interactive story with quests and deeply characterized NPCs, plus sandbox elements like player-craftable housing and lots of other crafting. If you are starting a design of this type, please PM me. I also love pet-breeding games.


#4 V3ntr1s   Members   -  Reputation: 482

Like
1Likes
Like

Posted 16 July 2014 - 05:27 AM

I think this could help laugh.png






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS