• Advertisement
Sign in to follow this  

quadris

This topic is 4321 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

hey, I know many of you won't be impressed, but here is my very first game. *smiles satisfied* A tetris clone, as usual. I used C++ and SDL. screenshot: fail to load and to download: download quadris so, now for the code:
#include "SDL/SDL.h"
#include "SDL\SDL_TTF.h"
#include "SDL\SDL_image.h"
#include "SDL\SDL_Mixer.h"
#include <string>
#include <fstream>



//The attributes of the screen
const int SCREEN_WIDTH = 580;
const int SCREEN_HEIGHT = 560;
const int SCREEN_BPP = 32;

const int DOWNTIMEFAST = 50;
int DOWNTIMESLOW = 500; 
int droptime = 500;//milliseconds before block moving (changes with level)
int grid[16][24];
int level,score,lines, menustate=1;
int gamestatus = 0; //1 for playing, 0 for menu, 3 to exit
char temp[ 64 ];
int sound = 2; //0 for no sound, 1 for only effects, 2 for music and effects
bool continue_possible;//a game can only be continued if its not finished
             
SDL_Surface *background = NULL;
SDL_Surface *spritesheet = NULL;
SDL_Surface *screen = NULL;
SDL_Surface *menutekst1 = NULL;
SDL_Surface *menutekst2 = NULL;
SDL_Surface *menutekst3 = NULL;
SDL_Surface *menutekst4 = NULL;
SDL_Surface *menutekst5 = NULL;
SDL_Surface *linestekst = NULL;
SDL_Surface *scoretekst = NULL;
SDL_Surface *leveltekst = NULL;
SDL_Surface *scoretekstname = NULL;
SDL_Surface *scoretekstscore = NULL;
SDL_Color textColor = { 200, 255, 0 };
SDL_Rect clipsprite[10];
SDL_Event event;
TTF_Font *font;
Mix_Music *music = NULL;
Mix_Chunk *dropsound = NULL;
Mix_Chunk *linesound = NULL;

SDL_Surface *load_image( std::string filename ) 
{
    SDL_Surface* loadedImage = NULL;
    SDL_Surface* optimizedImage = NULL;
    
    loadedImage = IMG_Load( filename.c_str() );

    if( loadedImage != NULL )
    {
        optimizedImage = SDL_DisplayFormat( loadedImage );
        SDL_FreeSurface( loadedImage );
    }
    
    return optimizedImage;
}


void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip=NULL )
{
    //Make a temporary rectangle to hold the offsets
    SDL_Rect offset;
    
    //Give the offsets to the rectangle
    offset.x = x;
    offset.y = y;
    
    //Blit the surface
    SDL_BlitSurface( source, clip, destination, &offset );
}

struct score{
             int score;
             std::string name;
             }highscore[11];

class block{            
                            
      public:
             int contents[4][4];
             int x,y, type;
             void show();
      }blok, tempblok;

void block::show(){
                   int i, j;
                   for (i=0; i<4; i++){
                                for (j=0; j<4;j++){
                                             apply_surface( 80+20*(x+i), 40+20*(y+j), spritesheet, screen, &clipsprite[contents[j]]);
                                             }
                                };
                   
                   };

bool collision(){
                 int i, j;
                 for (i=0;i<4;i++){
                                for(j=0; j<4;j++){
                                             if ((blok.contents[j]!=0) && (grid[blok.x+i+2][blok.y+j]!=0)){
                                                                                                  return true;
                                                                                                  }
                                             }
                                };
                 return false;
                 };

void moveleft(){
                blok.x--;
                if (collision()){
                               blok.x++;
                               }
                };

void moveright(){
                 blok.x++;
                          if (collision()){
                                         blok.x--;
                                         }
                 };

bool movedown(){
                blok.y++;
                if (collision()){
                                 blok.y--;
                                 if (sound!=0)
                                 Mix_PlayChannel( -1, dropsound, 0 );
                                 return false;
                                 }
                return true;
                };

void rotate(){
              int i, j, temp[4][4];
              i=j=0;
              
              for(i=0; i<4; i++)
              for(j=0; j<4; j++)
              temp[ i ][j]= blok.contents[ i ][j];

              for (i=0;i<4;i++){
                                for (j=0; j<4; j++){
                                             blok.contents[j]=temp[j][3-i];
                                             }
                                };
              if (collision()){
                               for(i=0; i<4; i++)
                               for(j=0; j<4; j++)
                               blok.contents[ i ][j]=temp[ i ][j] ;
                               }
              };

void handleevents(){
                           if (event.type == SDL_KEYDOWN){
                                                          switch (event.key.keysym.sym) {
                                                                                      case SDLK_DOWN: droptime = DOWNTIMEFAST;break;
                                                                                      case SDLK_LEFT: moveleft(); break;
                                                                                      case SDLK_RIGHT: moveright();break;
                                                                                      case SDLK_UP: rotate();break;
                                                                                      case SDLK_RETURN: gamestatus=0;
                                                                                                        menustate=2;
                                                                                                         break;
                                                                                      }
                                                          } 
                           
                           if (event.type == SDL_KEYUP){
                                                        if (event.key.keysym.sym == SDLK_DOWN){
                                                                                              droptime = DOWNTIMESLOW;
                                                                                              }
                                                        }
                            
                           };


class timer{
      private:
              int starttime, stoptime, pausedtime;
              bool started, paused;
      public:
             timer();
             bool is_started();
             bool is_paused();
             void pause();
             void unpause();
             void start();
             void stop();
             int telltime();
             }downtimer; //timer for regulating speed of block dropping

timer::timer(){
               starttime=0;
               pausedtime=0;
               stoptime = 0;
               started = false;
               paused = false;
               }

bool timer::is_started(){
                         return started;
                         }

bool timer::is_paused(){
                        return paused;
                        }

void timer::pause(){
                    paused = true;
                    pausedtime=SDL_GetTicks()-starttime;
                    }

void timer::unpause(){
                      paused = false;
                      starttime = SDL_GetTicks()-pausedtime;
                      }

void timer::start(){
                    started=true;
                    paused=false;
                    starttime=SDL_GetTicks();
                    }

void timer::stop(){
                   started=false;
                   paused=false;
                   stoptime=SDL_GetTicks()-starttime;
                    }

int timer::telltime(){
                      if (started)
                          {
                                  if (paused){return pausedtime;}
                                  else{return SDL_GetTicks()-starttime;}
                          }     
                      else{
                           return stoptime;
                           }
                      }





void setclips(){
                clipsprite[0].x=0;
                clipsprite[0].y=0;
                clipsprite[0].w=20;
                clipsprite[0].h=20;

                clipsprite[1].x=20;
                clipsprite[1].y=0;
                clipsprite[1].w=20;
                clipsprite[1].h=20;
                
                clipsprite[2].x=40;
                clipsprite[2].y=0;
                clipsprite[2].w=20;
                clipsprite[2].h=20;                
                
                clipsprite[3].x=60;
                clipsprite[3].y=0;
                clipsprite[3].w=20;
                clipsprite[3].h=20;
                
                clipsprite[4].x=80;
                clipsprite[4].y=0;
                clipsprite[4].w=20;
                clipsprite[4].h=20;
                
                clipsprite[5].x=100;
                clipsprite[5].y=0;
                clipsprite[5].w=20;
                clipsprite[5].h=20;
                
                clipsprite[6].x=120;
                clipsprite[6].y=0;
                clipsprite[6].w=20;
                clipsprite[6].h=20;
                
                clipsprite[7].x=140;
                clipsprite[7].y=0;
                clipsprite[7].w=20;
                clipsprite[7].h=20;
                
                clipsprite[8].x=160;
                clipsprite[8].y=0;
                clipsprite[8].w=20;
                clipsprite[8].h=20;
                
                clipsprite[9].x=180;
                clipsprite[9].y=0;
                clipsprite[9].w=20;
                clipsprite[9].h=20;
                
                };


void removelines(){
                   bool row=true;
                   int i,j,f,y,counter=0;
                   y=blok.y+3;
                   for (j=0;j<4;j++){
                                     row=true;
                                     for (i=2;i<14;i++){
                                                        if ((grid[y]==0) || (grid[y]==8)){
                                                                                          row=false;
                                                                                          }
                                                        }
                                     if (row){
                                              if (sound!=0)
                                              Mix_PlayChannel( -1, linesound, 0 );
                                              lines++;
                                              counter++;
                                              for (i=y;i>0;i--)
                                              for (f=2;f<14;f++)
                                                  grid[f]=grid[f][i-1];
                                                  score= score + level*25* counter;
                                              }
                                     else {y--;}
                                     }
                   score = score+ 10;                 
                   if (score >= 500*level*level){
                                            level++;
                                            DOWNTIMESLOW-=50;
                                            droptime=DOWNTIMESLOW;
                                            } 
                   };

void newblock(){
                int i, j;
                for (i=0;i<4;i++){
                                  for (j=0;j<4;j++){
                                      blok.contents[j]=tempblok.contents[j];
                                      }
                                      }
                blok.type=tempblok.type;
                blok.x=4;
                blok.y=0;
                
                tempblok.type=rand()%7+1;
                for (i=0;i<4;i++){
                                 for (j=0; j<4;j++){
                                 tempblok.contents[j]=0;
                                 }
                   }
                             
                   switch (tempblok.type){
                            case 1: tempblok.contents[2][0]=1;
                                    tempblok.contents[2][1]=1;
                                    tempblok.contents[2][2]=1;
                                    tempblok.contents[2][3]=1;
                                    break;
                            case 2: tempblok.contents[1][1]=2;
                                    tempblok.contents[1][2]=2;
                                    tempblok.contents[2][1]=2;
                                    tempblok.contents[2][2]=2;
                                    break;
                            case 3: tempblok.contents[1][2]=3;
                                    tempblok.contents[2][1]=3;
                                    tempblok.contents[2][2]=3;
                                    tempblok.contents[3][2]=3;
                                    break;
                            case 4: tempblok.contents[1][1]=4;
                                    tempblok.contents[1][2]=4;
                                    tempblok.contents[2][2]=4;
                                    tempblok.contents[3][2]=4;
                                    break;
                            case 5: tempblok.contents[1][2]=5;
                                    tempblok.contents[2][2]=5;
                                    tempblok.contents[3][2]=5;
                                    tempblok.contents[3][1]=5;
                                    break;
                            case 6: tempblok.contents[1][1]=6;
                                    tempblok.contents[2][1]=6;
                                    tempblok.contents[2][2]=6;
                                    tempblok.contents[3][2]=6;
                                    break;
                            case 7: tempblok.contents[1][2]=7;
                                    tempblok.contents[2][2]=7;
                                    tempblok.contents[2][1]=7;
                                    tempblok.contents[3][1]=7;
                                    break;
                            }            
                }
                
void showscreen(){
                  int i, j;
                  apply_surface(0,0,background, screen);
                  for(i=1; i<15; i++)
                  for(j=0; j<23; j++)
                  apply_surface(40+20*i,40+20*j,spritesheet,screen, &clipsprite[grid[j]]);
                  };

void showscore(){
    
                 sprintf( temp, "score: %d", score );
                 linestekst=TTF_RenderText_Solid(font, temp, textColor);
                 sprintf( temp, "level: %d", level );
                 leveltekst=TTF_RenderText_Solid(font, temp,textColor);
                 sprintf( temp, "lines: %d", lines );
                 scoretekst=TTF_RenderText_Solid(font, temp, textColor);
                 apply_surface(360,340,linestekst, screen);
                 apply_surface(360,380,leveltekst, screen);
                 apply_surface(360,420,scoretekst, screen);
                 SDL_FreeSurface(linestekst);
                 SDL_FreeSurface(leveltekst);
                 SDL_FreeSurface(scoretekst);
                 }

                 
void updategrid(){
                  int i,j;
                  for(i=0;i<4;i++){
                                   for (j=0;j<4;j++){
                                                     if (blok.contents[j]!=0)
                                                     grid[blok.x+2+i][blok.y+j]=blok.contents[j];
                                                     }
                                   }
                  }

void newgame(){
     int i, j;
     level=1;
     score=0;
     lines=0;
     continue_possible=true;
     for (i=0; i<16; i++){
                   for (j=0; j<24; j++){
                                 grid[j]=0;
                                 }
                   }
     
     for (i=0; i<=23; i++){
                          grid[0]=8;
                          grid[1]=8;
                          grid[14]=8;
                          grid[15]=8;
                          };
     for (i=2; i<=13; i++){
                          grid[22]=8;
                          grid[23]=8;
                          };                         
     tempblok.type=rand()%7+1;
     for (i=0; i<4;i++){
                   for (j=0; j<4; j++){
                                 tempblok.contents[j]=0;
                                 }
                   }
     tempblok.x=16;
     tempblok.y=0;              
     switch (tempblok.type){
                            case 1: tempblok.contents[2][0]=1;
                                    tempblok.contents[2][1]=1;
                                    tempblok.contents[2][2]=1;
                                    tempblok.contents[2][3]=1;
                                    break;
                            case 2: tempblok.contents[1][1]=2;
                                    tempblok.contents[1][2]=2;
                                    tempblok.contents[2][1]=2;
                                    tempblok.contents[2][2]=2;
                                    break;
                            case 3: tempblok.contents[1][2]=3;
                                    tempblok.contents[2][1]=3;
                                    tempblok.contents[2][2]=3;
                                    tempblok.contents[3][2]=3;
                                    break;
                            case 4: tempblok.contents[1][1]=4;
                                    tempblok.contents[1][2]=4;
                                    tempblok.contents[2][2]=4;
                                    tempblok.contents[3][2]=4;
                                    break;
                            case 5: tempblok.contents[1][2]=5;
                                    tempblok.contents[2][2]=5;
                                    tempblok.contents[3][2]=5;
                                    tempblok.contents[3][1]=5;
                                    break;
                            case 6: tempblok.contents[1][1]=6;
                                    tempblok.contents[2][1]=6;
                                    tempblok.contents[2][2]=6;
                                    tempblok.contents[3][2]=6;
                                    break;
                            case 7: tempblok.contents[1][2]=7;
                                    tempblok.contents[2][2]=7;
                                    tempblok.contents[2][1]=7;
                                    tempblok.contents[3][1]=7;
                                    break;
                            }            
     newblock();
     droptime=DOWNTIMESLOW = 500;
     downtimer.start();
     }

std::string getname(int place){
                      std::string str="";
                      SDL_Surface *name = NULL;
                      SDL_Surface *message1 = NULL;
                      SDL_Surface *message2 = NULL;
                      sprintf( temp, "YOU WILL TAKE PLACE %d IN THE HIGHSCORES!", place );
                      message1=TTF_RenderText_Solid(font, temp, textColor);
                      message2=TTF_RenderText_Solid(font, "ENTER YOUR NAME:", textColor);
                      SDL_Event event2;
                      SDL_EnableUNICODE( SDL_ENABLE );    
                      while ((event2.key.keysym.sym!=SDLK_RETURN) || (str.length()==0)){
                                                                 while (SDL_PollEvent(&event2))
                                                                 {
                                                                      if( event2.type == SDL_KEYDOWN )
                                                                      {
                                                                       if( str.length() <= 16 )
                                                                       {
                                                                        if( event2.key.keysym.unicode == (Uint16)' ' )
                                                                        {
                                                                        str += (char)event2.key.keysym.unicode;    
                                                                        }
                                                                        else if( ( event2.key.keysym.unicode >= (Uint16)'0' ) && ( event2.key.keysym.unicode <= (Uint16)'9' ) )
                                                                        {
                                                                        str += (char)event2.key.keysym.unicode;
                                                                        }
                                                                        else if( ( event2.key.keysym.unicode >= (Uint16)'A' ) && ( event2.key.keysym.unicode <= (Uint16)'Z' ) )
                                                                        {
                                                                        //Append the character
                                                                        str += (char)event2.key.keysym.unicode;
                                                                        }
                                                                        //If the key is a space
                                                                        else if( ( event2.key.keysym.unicode >= (Uint16)'a' ) && ( event2.key.keysym.unicode <= (Uint16)'z' ) )
                                                                        {
                                                                        //Append the character
                                                                        str += (char)event2.key.keysym.unicode;
                                                                        }
                                                                       }
    
                                                                        
                                                                        if( ( event2.key.keysym.sym == SDLK_BACKSPACE ) && ( str.length() != 0 ) )
                                                                        {
                                                                        str.erase( str.length() - 1 );
                                                                        }
                                                                      }

                                                                   }
                                                                 showscreen();
                                                                 blok.show();
                                                                 tempblok.show();
                                                                 apply_surface(( SCREEN_WIDTH - message1->w ) / 2,100,message1,screen);
                                                                 apply_surface(( SCREEN_WIDTH - message2->w ) / 2,130,message2,screen);
                                                                 SDL_FreeSurface( name );
                                                                 name = TTF_RenderText_Solid( font, str.c_str(), textColor );
                                                                 if (name!=NULL)
                                                                 apply_surface(( SCREEN_WIDTH - name->w ) / 2,160,name,screen);
                                                                 SDL_Flip(screen);
                                                                 }
                      SDL_FreeSurface( name );
                      SDL_FreeSurface(message1);
                      SDL_FreeSurface(message2);
                      SDL_EnableUNICODE( SDL_DISABLE );  
                      return str;
                      }

void endofgame(){
                 int i=0,j;
                 while ((score < highscore.score)){i++;};
                 if (i<10){
                           for (j=8;j>=i;j--){
                                              highscore[j+1]=highscore[j];
                                              }
                           highscore.score=score;
                           highscore.name=getname(i+1);
                           }
                 continue_possible=false;          
                 menustate=1;
                 gamestatus=0;
                 }

bool showmenu(){                                               
                apply_surface(120,80,menutekst1,screen);
                apply_surface(120,120,menutekst2,screen);
                apply_surface(120,160,menutekst3,screen);
                apply_surface(120,200,menutekst4,screen);                
                apply_surface(120,240,menutekst5,screen);
                apply_surface(100,48+(40*menustate),spritesheet,screen, &clipsprite[9]); 
                return true;
                } 

void menuact(){
               int i;
               switch (menustate){
                                  case 1 : newgame();
                                           gamestatus=1;
                                           break;
                                  case 2 : if (continue_possible)
                                           gamestatus = 1;
                                           break;
                                  case 3: sound++;
                                          if (sound>2){sound=0;}
                                             switch (sound){
                                                            case 0: menutekst3=TTF_RenderText_Solid(font, "sound off", textColor);
                                                                    //If there is  music playing
                                                                    if( Mix_PlayingMusic() != 0 )
                                                                        {
                                                                        //stop the music
                                                                        Mix_HaltMusic();
                                                                        }
                                                                    break;
                                                            case 1: menutekst3=TTF_RenderText_Solid(font, "effects only", textColor);
                                                                    //If there is  music playing
                                                                         if( Mix_PlayingMusic() != 0 )
                                                                         {
                                                                         //stop the music
                                                                         Mix_HaltMusic();
                                                                         }
                                                                    break;
                                                            case 2: menutekst3=TTF_RenderText_Solid(font, "music and effects", textColor);
                                                                    //If there is no  music playing
                                                                    if( Mix_PlayingMusic() == 0 )
                                                                    {
                                                                     //play the music
                                                                      Mix_PlayMusic( music, -1 );
                                                                      }
                                                                    break;
                                                            }
                                          break;
                                  case 4 : showscreen();
                                           blok.show();
                                           tempblok.show();
                                           for (i=0; i<10; i++){
                                                                char temp[64];
                                                                sprintf( temp, "%d", highscore.score );
                                                                scoretekstname=TTF_RenderText_Solid(font,  highscore.name.c_str(), textColor);
                                                                scoretekstscore=TTF_RenderText_Solid(font, temp, textColor);
                                                                apply_surface(100,80+40*i,scoretekstname, screen);
                                                                apply_surface(400,80+40*i,scoretekstscore, screen);
                                                                }
                                           SDL_Flip(screen);
                                           event.key.keysym.sym=SDLK_UP;
                                           while (i!=0){
                                                        while (SDL_PollEvent(&event)==1){ if ((event.type==SDL_KEYDOWN) &&(event.key.keysym.sym==SDLK_RETURN)) i=0;}
                                                        }
                                           break;
                                  case 5 : gamestatus = 3;
                                           break;
                                  }
               };
               
void randomize() 
{
	time_t t;
	srand((unsigned) time(&t));
}


bool initialiseren()
{    
     int i;
     
     if (SDL_Init(SDL_INIT_EVERYTHING)== -1){
                                      return false;
                                      }
     
     if( TTF_Init() == -1 )
    {
        return false;    
    }

     screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );                                 
     
     if (!screen){return false;}
     SDL_WM_SetCaption( "Quadris!", NULL );
     background= load_image("graph//background.bmp");
     spritesheet= load_image("graph//tetris.bmp");  
     Uint32 colorkey = SDL_MapRGB( spritesheet->format, 0, 0xFF, 0xFF );
     SDL_SetColorKey( spritesheet, SDL_RLEACCEL | SDL_SRCCOLORKEY, colorkey );
     SDL_SetAlpha( spritesheet, SDL_SRCALPHA | SDL_RLEACCEL, 220 );
     font=TTF_OpenFont("fonts//arial.ttf",25);
     menutekst1=TTF_RenderText_Solid(font, "new game", textColor);
     if (menutekst1 ==NULL) {return false;}  
     menutekst2=TTF_RenderText_Solid(font, "continue", textColor);
     if (menutekst2 ==NULL) {return false;}
     menutekst3=TTF_RenderText_Solid(font, "music and effects", textColor);
     if (menutekst3 ==NULL) {return false;}     
     menutekst4=TTF_RenderText_Solid(font, "highscores", textColor);
     if (menutekst4 ==NULL) {return false;}
     menutekst5=TTF_RenderText_Solid(font, "close", textColor);
     if (menutekst5 ==NULL) {return false;}
     
     
     setclips();  
     
     if ((spritesheet == NULL) || (background == NULL)){
                                                        return false;
                                                        }
     
    std::ifstream load( "topscore.sav" );
    if( load != NULL )
        {
        for (i=0; i<11; i++){
            load >> highscore.score;
            load.ignore();
            load >> highscore.name ;
            load.ignore();
            }
        load.close();
        }

     if( Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 ) == -1 )
    {
        return false;    
    }
    
    music = Mix_LoadMUS( "sound//loop1.wav" );
    
    if( music == NULL )
    {
        return false;    
    }

  
    dropsound = Mix_LoadWAV( "sound//kickass.wav" ); 
    linesound = Mix_LoadWAV( "sound//explosion.wav" ); 
    if( ( dropsound == NULL ) || ( linesound == NULL ) ) { return false; } 
    
    
     Mix_PlayMusic( music, -1 );
     randomize();
     newgame();
     return true;
}



void cleanup()
{
    int i;
    
    SDL_FreeSurface(background);
    SDL_FreeSurface(spritesheet);
    SDL_FreeSurface(menutekst1);
    SDL_FreeSurface(menutekst2);
    SDL_FreeSurface(menutekst3);
    SDL_FreeSurface(menutekst4);
    SDL_FreeSurface(menutekst5);
    SDL_FreeSurface(linestekst);
    SDL_FreeSurface(scoretekst);
    SDL_FreeSurface(leveltekst);   
    if( Mix_PlayingMusic() != 0 )
               {
               Mix_HaltMusic();
               }
    Mix_FreeChunk( dropsound );
    Mix_FreeChunk( linesound );
    Mix_FreeMusic( music );
    TTF_CloseFont(font);
    
    //Open a file for reading
    std::ofstream save( "topscore.sav" );
    //If the file loaded
    if( save != NULL )
        {
        for (i=0; i<11; i++){
            save << highscore.score;
            save << "\n";
            save << highscore.name;
            save << "\n";
            }
        save.close();
        }
        
    Mix_CloseAudio();   
    TTF_Quit();
    SDL_Quit();
}


int main( int argc, char* args[] )
{
        
    
    if (initialiseren()==false)
    {
    return 1;
    }
    
                              
    while (gamestatus!=3)
          {
          while (gamestatus ==1){
                       while (SDL_PollEvent(&event)){
                                                     if ((event.type == SDL_KEYDOWN)||(event.type == SDL_KEYUP))
                                                     {
                                                                    handleevents();
                                                     }
                                                     
                                                     if (event.type == SDL_QUIT){gamestatus=3;}
                                                     }
          
          if (downtimer.telltime()>=droptime){
                                              if (movedown()){
                                                                   downtimer.start();
                                                                   }
                                              else {
                                                   if (blok.y==0){
                                                                  endofgame();
                                                                  }
                                                   else{
                                                        updategrid();
                                                        removelines();
                                                        newblock();
                                                        }
                                                   
                                                   }
                                              }
          showscreen();
          blok.show();
          tempblok.show();
          showscore();
          if (SDL_Flip(screen)==-1){
                                    return 1;
                                    }
          }
          while (gamestatus==0){
                while (SDL_PollEvent(&event)){
                                                     if ((event.type == SDL_KEYDOWN))
                                                     {
                                                                    switch (event.key.keysym.sym){
                                                                           case SDLK_UP: menustate--;
                                                                                         break;
                                                                           case SDLK_DOWN: menustate++;
                                                                                           break;
                                                                           case SDLK_RETURN: menuact();
                                                                                            break;
                                                                                             
                                                                           }
                                                                    if (menustate>5)
                                                                    menustate=1;
                                                                    if (menustate<1)
                                                                    menustate=5;
                                                     }

                                                     
                                                     if (event.type == SDL_QUIT){
                                                                    gamestatus=3;
                                                                    }
                                                 }
                
                showscreen();
                blok.show();
                tempblok.show();
                showscore();
                if (showmenu() == false){return 1;};
                if (SDL_Flip(screen)==-1){
                                    return 1;
                                    }
                
                }
          
          
          }
           
          
    cleanup();          
    return 0;    
}




Use it at your own will. I'd appreciate some comment on the coding. There are no doubt simpler or more correct ways of doing tetris. All comments on the game itself are also welcome, please try it out... EDIT: solved bad screenshot link

Share this post


Link to post
Share on other sites
Advertisement
Congratulations on your first accomplishment! Really funny to see dutch variablenames in your code. I used to write for a (also dutch) website and back then I had to use dutch variablenames too. Hehe, keep the good work up!

Share this post


Link to post
Share on other sites
yes,

well I quickly changed the menu language, but i didn't take the effort to change the variablenames :)

Share this post


Link to post
Share on other sites
the code looks very interesting, haven't had time to go through it all yet, but im working on my first game too, also a tetris clone. And I appreciate being able to look at your "Music and effects" and "highscore" parts. So thank you very much

Share this post


Link to post
Share on other sites

The highscores were the hardest part indeed, had to use lots of bugspray ;)

About the DLL's, i don't know if there is a way to just deliver them with the zip file. Can I just put them there so that after unzipping they are useable to my .exe? And if so, in which directory should i put them?

Share this post


Link to post
Share on other sites
PS if you want to check how the highsorelist looks in the file, you can just open highscore.sav with notepad.

Share this post


Link to post
Share on other sites
Putting the Dll's into the same directory as the .exe is fine (and actually the best way to do).

Oh, and distributing Windows fonts is actually a not so good idea...

Share this post


Link to post
Share on other sites
just to check... so I dont put any windows fonts in my program and have it be a "bad idea" is Arial.ttf or whatever Arial.font, I forget what the .* part is, but is that a windows font, or si that OK to include? and if its not, what should I include instead?

Share this post


Link to post
Share on other sites
Good job on the game. It seems to work just fine. The only thing that bothered me was that the background was kind of distracting. It made it difficult to focus on the blocks sometimes. I think you should black out the game board area of you could just put a different image behind the blocks like a gradient effect or something that contrast well against the blocks.

I don't have time to look through the code right now but I'll take a look at that if I get a chance. I'm pretty new myself, I've only made pong and tetris so I'm not sure I will have much to say about the code anyway. :)

Congratulations on finishing your first game!

Share this post


Link to post
Share on other sites


I know, I had some trouble creating good contrast for the blocks... Gray seemed to be the best way to go, but the background is just a bit to crowded I think.

Share this post


Link to post
Share on other sites
just curious, this game allows you to hold the down key and have it "rush" downwards, but you can't hold the left and right key and have it "rush" left and right, what is the reason for this and where would you change it in the code... it looks like all the key presses were done the same... amd I missing something?

Share this post


Link to post
Share on other sites
isn't this a fairly simple concept for SDL, im not sure, but I thought someone would def. be able to answer it... sorry for the double post, but it has me at a standstill trying to modify my own version of tetris... Thanks for any help you can offer me,

-Synt4x

Share this post


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

  • Advertisement