Tetris Help

This is a discussion on Tetris Help within the Game Programming forums, part of the General Programming Boards category; Here's a quick program for you that will play sound. Code: #include <allegro.h> SAMPLE *name; int main() { allegro_init(); install_keyboard(); ...

  1. #16
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    Here's a quick program for you that will play sound.

    Code:
    #include <allegro.h>
    
    SAMPLE *name;
    
    int main()
     {
    
      allegro_init();
      install_keyboard();
      
      install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, 0);
    
      set_color_depth(32);
      set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0);
    
      name     = load_sample("filename.wav");
    
      play_sample(name, 128, 128, 100, FALSE);
      
      while(!key[KEY_ESC]);
      ;
      
    
      allegro_exit();
      return 0;
    }
    END_OF_MAIN();
    If you copy that word for word and use Dev it will work. Plus you have to come up with your own .wav and replace "filename.wav" with your own .wav. It works; trust me.

  2. #17
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    I need help on the script, I can't seem to fix these four errors I have. Here's the script:
    Code:
    #include <stdio.h>
    #include <time.h>
    #include <allegro.h>
    #include <math.h>
    #define border 30
    #define GAME_DELAY 170 // Delay in milliseconds
    #define SPEEDUP_DELAY 80000 // Speedup delay in milliseconds
    #define DELAY_DECREMENT 1 // Amount to decrement speed by after speedup delay
    
    BITMAP *bmp;
    BITMAP *bmp2;
    BITMAP *sideframe;
    BITMAP *numbers;
    BITMAP *gameover;
    int block_array[20][10];
    int current_block[4][4];
    int rotated[4][4];
    int next_block, next_sprite, current_sprite, bx, by, ox, oy, score;
    volatile int timer_flag;
    volatile int timer_flag2;
    int possible_blocks[6][4][3]={ 0,1,0,  // 0
                                   0,1,0,
                                   0,1,0,
                                   0,1,0,
                                   0,1,0,  // 1
                                   0,1,0,
                                   0,1,1,
                                   0,0,0,
                                   0,0,0, // 2
                                   1,1,1,
                                   0,1,0,
                                   0,0,0,
                                   0,0,0, // 3
                                   0,1,1,
                                   0,1,1,
                                   0,0,0,
                                   0,1,0, // 4
                                   0,1,1,
                                   0,0,1,
                                   0,0,0,
                                   0,0,1, // 5
                                   0,1,1,
                                   0,1,0,
                                   0,0,0 };
    void setupscreen( void );
    int return_random(int min, int max);
    void draw_next(int next_block, int n);
    void initialise_new_block();
    void draw_current(int a, int b, int n);
    void move_down();
    int check_bottom(int hit);
    int set_block();
    void move(int lastkey);
    void set_up_timer(int delay);
    int check_lines();
    void plot_score();
    
    void interrupt_handler(void) { timer_flag = 1; };
    void interrupt_handler2(void) { timer_flag2 = 1; };
    
    int main(int argc, char *argv[])
    {
    int n, endgame, move_skip, hit, lastkey, mdelay, line;
    int init_x, init_y;
    char ch;
    allegro_init();
    install_timer();
    set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0);
    do {
      mdelay = GAME_DELAY;
      srand(time(NULL));
      score = 0;
      setupscreen();
      install_int(interrupt_handler, mdelay);
      install_int(interrupt_handler2, SPEEDUP_DELAY);
      set_up_timer(mdelay);
      next_block = return_random(0, 5);
      next_sprite = return_random(0, 5);
      initialise_new_block();
      draw_current(bx, by, current_sprite);
      endgame = 0; n=0; move_skip = 2; hit = 0; lastkey = 0; timer_flag2 = 0;
      for (init_x=0; init_x<10; init_x++)
        for (init_y=0; init_y<20; init_y++)
          block_array[init_y][init_x] = 0;
      do {
        lastkey = 0;
        do {
          lastkey = check_move(lastkey);
        } while (!timer_flag);
        if (lastkey == 5) move_skip = 1;
        timer_flag = 0;
        if (timer_flag2 == 1) {
          mdelay-=DELAY_DECREMENT;
          if (mdelay<1) mdelay = 1;
          set_up_timer(mdelay);
          timer_flag2 = 0;
        }
        move_skip --;
        if (lastkey>0) move(lastkey);
        if (move_skip == 0) {
          hit = check_bottom(hit);
          if (hit==1) {
            if (by<1) endgame = 1; // Reached top
            set_block();
            hit = -1;
            line = check_lines();
          }
          else move_down();
          move_skip = 2;
        }
        if (line==0) {
          draw_current(ox, oy, 6);
          draw_current(bx, by, current_sprite);
        }
        line = 0;
        if (hit==-1) initialise_new_block();
        hit = 0;
        ox = bx; oy = by;
        if (lastkey == 4) endgame = 1; // Quit Game (esc pressed)
      } while (!endgame);
    
      for (n=160; n>0; n--) {
        masked_blit(gameover, screen, 0, n, 150, n+20, 80, 160-n);
        delay(5);
      }
      
    return (0);
    }
    END_OF_MAIN();
    
    void set_up_timer(int delay)
    {
      float percent;
      int height;
      remove_int(interrupt_handler);
      install_int(interrupt_handler, delay);
      percent = (float)delay / (float)GAME_DELAY;
      percent = 1 - percent;
      height = 140 - (int)(100.0 * percent);
      if (height<52) height = 52;
      rectfill(screen, 112, 140, 124, height, 50);
    }
    
    void move(int lastkey)
    {
      int max_x, min_x, x, y, collide;
      collide = 0;
      // Move left
      if (lastkey == 1) {
        for (y=0; y<4; y++) {
          min_x = 5;
          for (x=3; x>=0; x--)
            if (current_block[y][x] == 1)
              min_x = x-1;
          if (min_x != 5)
            if (min_x+bx < 0)
              collide = 1;
            else if (block_array[y+by][min_x+bx] == 1)
              collide = 1;
        }
        if (collide == 0) bx--;
      }
      // Move right
      else if (lastkey == 2) {
        for (y=0; y<4; y++) {
          max_x = 5;
          for (x=0; x<4; x++)
            if (current_block[y][x] == 1)
              max_x = x+1;
          if (max_x != 5)
            if (max_x+bx > 9)
              collide = 1;
            else if (block_array[y+by][max_x+bx] == 1)
              collide = 1;
        }
        if (collide == 0) bx++;
      }
      // Rotate
      else if (lastkey == 3) {
        for (x=1; x<4; x++) {
          rotated[0][x] = current_block[3-x][0];
          rotated[3][3-x] = current_block[x][3];
          rotated[x][3] = current_block[0][x];
          rotated[3-x][0] = current_block[3][3-x];
        }
        rotated[1][1] = current_block[2][1];
        rotated[1][2] = current_block[1][1];
        rotated[2][2] = current_block[1][2];
        rotated[2][1] = current_block[2][2];
        for (y=0; y<4; y++)
          for (x=0; x<4; x++)
            if (rotated[y][x] == 1) {
              if (block_array[by+y][bx+x] == 1)
                collide = 1;
              if (bx+x < 0)
                collide = 1;
              if (bx+x > 9)
                collide = 1;
              if (by+y > 19)
                collide = 1;
            }
        if (collide == 0) {
          draw_current(bx, by, 6);
          for (y=0; y<4; y++)
            for (x=0; x<4; x++)
              current_block[y][x] = rotated[y][x];
        }
      }
    }
    
    int check_move(int lastkey)
    {
      int c;
      if (readkey()) {
         c = readkey();
         if (c==0) c = readkey();
         if (c==75) lastkey = 1; //Left
         if (c==62) lastkey = 1; //Left (Remote)
         if (c==77) lastkey = 2; //Right
         if (c==64) lastkey = 2; //Right (Remote)
         if (c==72) lastkey = 3; //Up
         if (c==27) lastkey = 4; //Esc
         if (c==80) lastkey = 5; //Down
      }
      return lastkey;
    }
    
    void draw_current(int a, int b, int n)
    {
      int x, y;
      for (y=0; y<4; y++)
        for (x=0; x<4; x++)
          if (current_block[y][x] == 1)
            if (n<6)
              blit(bmp, screen, 0, n*8, 150+(x*8)+(a*8), 20+(y*8)+(b*8), 8, 8);
            else
              rectfill(screen, 150+(x*8)+(a*8), 20+(y*8)+(b*8), 157+(x*8)+(a*8), 27+(y*8)+(b*8), 0);
    }
    
    void move_down()
    {
      by++;
    }
    
    int set_block()
    {
      int x, y;
      for (x=0; x<4; x++)
        for (y=0; y<4; y++)
          if (current_block[y][x] == 1)
            block_array[y+by][x+bx] = 1;
    }
    
    void plot_score()
    {
      int n, m, digit;
      //blit(numbers, screen, 6*8, 0, 5*8+10, 80, 8, 8);
      m = score;
      n=5;
      do {
        digit = (int)fmod((double)m, (double)10);
        blit(numbers, screen, digit*8, 0, n*9+3, 65, 8, 8);
        m=m/10;
        n--;
      } while (n>0);//while ((m > 0.1) && (n>0));
    }
    
    int check_lines()
    {
      int x, y, line, lines, firstline, n;
      lines = 0; firstline = 1;
      for (y=by; y<by+4; y++) {
        line = 1;
        for (x=0; x<10; x++)
          if (block_array[y][x] == 0)
            line = 0;
        if (line == 1) {
          for (x=0; x<10; x++)
            for (n=y; n>0; n--)
              block_array[n][x] = block_array[n-1][x];
          lines=1;
          score++;
          plot_score();
          if (firstline == 1) {
            draw_current(ox, oy, 6);
            draw_current(bx, by, current_sprite);
            firstline = 0;
          }
          for (n=7; n>=0; n--) {
            hline(screen, 150, 20+(y*8)+n, 229, 0);
            delay(30);
          }
          bmp2 = create_bitmap(80, (y*8)+17);
          clear(bmp2);
          blit(screen, bmp2, 150, 10, 0, 0, 80, (y*8)+10);
          for (n=0; n<9; n++) {
            blit(bmp2, screen, 0, 0, 150, 10+n, 80, (y*8)+10);
            delay(30);
          }
        }
      }
      return lines;
    }
    
    int check_bottom(int hit)
    {
      int max_y, x, y, collide;
      collide = 0;
      for (x=0; x<4; x++) {
        max_y = -1;
        for (y=0; y<4; y++)
          if (current_block[y][x] == 1)
            max_y = y+1;
        if (max_y != -1)
          if (max_y+by > 19)
            collide = 1;
          else if (block_array[max_y+by][x+bx] == 1)
            collide = 1;
      }
      if (collide == 1)
        return 1;
      else
        return hit;
    }
    
    void initialise_new_block()
    {
      int x, y;
      bx = 3;
      by = 0;
      for (y=0; y<4; y++) {
        for (x=0; x<3; x++)
          current_block[y][x] = possible_blocks[next_block][y][x];
        current_block[y][3] = 0;
      }
      current_sprite = next_sprite;
      next_block = return_random(0, 5);
      next_sprite = return_random(0, 5);
      draw_next(next_block, next_sprite);
      draw_current(bx, by, current_sprite);
    }
    
    void draw_next(int next_block, int n)
    {
      int a, b;
      for (b=0; b<4; b++)
        for (a=0; a<3; a++)
          if (possible_blocks[next_block][b][a] == 1)
            blit(bmp, screen, 0, n*8, 270+(a*8), 88+(b*8), 8, 8);
          else
            rectfill(screen, 270+(a*8), 88+(b*8), 277+(a*8), 95+(b*8), 0);
    }
    
    int return_random(int min, int max)
    {
      int range, value;
      range = max - min + 1;
      value = (int)((float)rand() / (float)RAND_MAX * range) + min;
      return value;
    }
    
    void setupscreen()
    {
    
       PALETTE read_palette, def_palette;
       int x, y;
       bmp = create_bitmap(8, 48); // Create bitmap in memory
       sideframe = create_bitmap(135, 200);
       numbers = create_bitmap(80, 8);
       gameover = create_bitmap(80, 160);
       clear(bmp);
       clear(sideframe);
       clear(numbers);
       clear(gameover);
       bmp = load_bmp("blocks.bmp", read_palette);
       sideframe = load_bitmap("sframe.bmp", read_palette);
       numbers = load_bitmap("numbers.bmp", read_palette);
       gameover = load_bitmap("gameover.bmp", read_palette);
       //set_palette( read_palette );
       blit(sideframe, screen, 0, 0, 0, 0, 135, 200);
       plot_score();
       for (x=14; x>=0; x--) {
          //Main Area
          vline(screen, 149-x, 20, 180+x, border-x);
          vline(screen, 230+x, 20, 180+x, border-x);
          hline(screen, 149-x, 180+x, 230+x, border-x);
          for (y=14; y>=0; y--)
            if (border-y-x>15) {
              putpixel(screen, 149-x, 30-y, border-y-x);
              putpixel(screen, 230+x, 30-y, border-y-x);
            }
            else {
              putpixel(screen, 149-x, 30-y, 0);
              putpixel(screen, 230+x, 30-y, 0);
            };
          //Next Block Area
          vline(screen, 269-x, 87-x, 120+x, border-x);
          vline(screen, 294+x, 87-x, 120+x, border-x);
          hline(screen, 269-x, 120+x, 294+x, border-x);
          hline(screen, 269-x, 87-x, 294+x, border-x);
       }
       rectfill(screen, 150, 20, 229, 179, 0);
    
       //save_bmp("scdump.bmp", screen, def_palette);
    }
    I get these errors:
    Code:
    88 C:\Dev-C++\Tetris\Tetris.c
    implicit declaration of function `int check_move(...)'
    
    124 C:\Dev-C++\Tetris\Tetris.c
    implicit declaration of function `int delay(...)'
    
    128 C:\Dev-C++\Tetris\Tetris.c
    parse error before string constant
    I am using Dev-C++ 4.9.3.0 (Beta 5.3) and Allegro 4.1 with everything linked right.

  3. #18
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    You never declared int check_move() to be a function. That's where at least one error is coming from. But I'm not sure if it will solve all of your errors.

    Also, why are you using readkey() when key[KEY_KEY] is much easier.

    Here is an example of what you would do instead of using readkey()

    Code:
    if(keypressed() )
     {
      if(key[KEY_RIGHT]
      x++;
      else if(key[KEY_LEFT)
      x--;
      else if(key[KEY_UP]
      y--;
      else if(key[KEY_DOWN]
      y++;
     }
    see how much easier that is than using readkey().

    looking over your code i didn't see anywhere where you used
    rest(). you should use that function when you want to pause your program. to pause your program for one second you would go rest(1000). however, you may have rest() and i just overlooked it; i don't know.

    hope all that helps.

  4. #19
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Ok, thanks. I'll modify it and see what happens

  5. #20
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Nope, didn't work. I fixed the check_move() problem, but I get a delay() error and a problem with the END_OF_MAIN(); function now.
    PHP Code:
    #include <stdio.h>
    #include <time.h>
    #include <allegro.h>
    #include <math.h>
    #define border 30
    #define GAME_DELAY 170 // Delay in milliseconds
    #define SPEEDUP_DELAY 80000 // Speedup delay in milliseconds
    #define DELAY_DECREMENT 1 // Amount to decrement speed by after speedup delay

    BITMAP *bmp;
    BITMAP *bmp2;
    BITMAP *sideframe;
    BITMAP *numbers;
    BITMAP *gameover;
    int block_array[20][10];
    int current_block[4][4];
    int rotated[4][4];
    int next_blocknext_spritecurrent_spritebxbyoxoyscore;
    volatile int timer_flag;
    volatile int timer_flag2;
    int possible_blocks[6][4][3]={ 0,1,0,  // 0
                                   
    0,1,0,
                                   
    0,1,0,
                                   
    0,1,0,
                                   
    0,1,0,  // 1
                                   
    0,1,0,
                                   
    0,1,1,
                                   
    0,0,0,
                                   
    0,0,0// 2
                                   
    1,1,1,
                                   
    0,1,0,
                                   
    0,0,0,
                                   
    0,0,0// 3
                                   
    0,1,1,
                                   
    0,1,1,
                                   
    0,0,0,
                                   
    0,1,0// 4
                                   
    0,1,1,
                                   
    0,0,1,
                                   
    0,0,0,
                                   
    0,0,1// 5
                                   
    0,1,1,
                                   
    0,1,0,
                                   
    0,0,};
    void setupscreenvoid );
    int return_random(int minint max);
    void draw_next(int next_blockint n);
    void initialise_new_block();
    void draw_current(int aint bint n);
    void move_down();
    int check_move(int lastkey);
    int check_bottom(int hit);
    int set_block();
    void move(int lastkey);
    void set_up_timer(int delay);
    int check_lines();
    void plot_score();

    void interrupt_handler(void) { timer_flag 1; };
    void interrupt_handler2(void) { timer_flag2 1; };

    int main(int argcchar *argv[])
    {
    int nendgamemove_skiphitlastkeymdelayline;
    int init_xinit_y;
    char ch;
    allegro_init();
    install_timer();
    set_gfx_mode(GFX_AUTODETECT32020000);
    do {
      
    mdelay GAME_DELAY;
      
    srand(time(NULL));
      
    score 0;
      
    setupscreen();
      
    install_int(interrupt_handlermdelay);
      
    install_int(interrupt_handler2SPEEDUP_DELAY);
      
    set_up_timer(mdelay);
      
    next_block return_random(05);
      
    next_sprite return_random(05);
      
    initialise_new_block();
      
    draw_current(bxbycurrent_sprite);
      
    endgame 0n=0move_skip 2hit 0lastkey 0timer_flag2 0;
      for (
    init_x=0init_x<10init_x++)
        for (
    init_y=0init_y<20init_y++)
          
    block_array[init_y][init_x] = 0;
      do {
        
    lastkey 0;
        do {
          
    lastkey check_move(lastkey);
        } while (!
    timer_flag);
        if (
    lastkey == 5move_skip 1;
        
    timer_flag 0;
        if (
    timer_flag2 == 1) {
          
    mdelay-=DELAY_DECREMENT;
          if (
    mdelay<1mdelay 1;
          
    set_up_timer(mdelay);
          
    timer_flag2 0;
        }
        
    move_skip --;
        if (
    lastkey>0move(lastkey);
        if (
    move_skip == 0) {
          
    hit check_bottom(hit);
          if (
    hit==1) {
            if (
    by<1endgame 1// Reached top
            
    set_block();
            
    hit = -1;
            
    line check_lines();
          }
          else 
    move_down();
          
    move_skip 2;
        }
        if (
    line==0) {
          
    draw_current(oxoy6);
          
    draw_current(bxbycurrent_sprite);
        }
        
    line 0;
        if (
    hit==-1initialise_new_block();
        
    hit 0;
        
    ox bxoy by;
        if (
    lastkey == 4endgame 1// Quit Game (esc pressed)
      
    } while (!endgame);

      for (
    n=160n>0n--) {
        
    masked_blit(gameoverscreen0n150n+2080160-n);
        
    delay(5);
      }
      
    return (
    0);
    }
    END_OF_MAIN();

    void set_up_timer(int delay)
    {
      
    float percent;
      
    int height;
      
    remove_int(interrupt_handler);
      
    install_int(interrupt_handlerdelay);
      
    percent = (float)delay / (float)GAME_DELAY;
      
    percent percent;
      
    height 140 - (int)(100.0 percent);
      if (
    height<52height 52;
      
    rectfill(screen112140124height50);
    }

    void move(int lastkey)
    {
      
    int max_xmin_xxycollide;
      
    collide 0;
      
    // Move left
      
    if (lastkey == 1) {
        for (
    y=0y<4y++) {
          
    min_x 5;
          for (
    x=3x>=0x--)
            if (
    current_block[y][x] == 1)
              
    min_x x-1;
          if (
    min_x != 5)
            if (
    min_x+bx 0)
              
    collide 1;
            else if (
    block_array[y+by][min_x+bx] == 1)
              
    collide 1;
        }
        if (
    collide == 0bx--;
      }
      
    // Move right
      
    else if (lastkey == 2) {
        for (
    y=0y<4y++) {
          
    max_x 5;
          for (
    x=0x<4x++)
            if (
    current_block[y][x] == 1)
              
    max_x x+1;
          if (
    max_x != 5)
            if (
    max_x+bx 9)
              
    collide 1;
            else if (
    block_array[y+by][max_x+bx] == 1)
              
    collide 1;
        }
        if (
    collide == 0bx++;
      }
      
    // Rotate
      
    else if (lastkey == 3) {
        for (
    x=1x<4x++) {
          
    rotated[0][x] = current_block[3-x][0];
          
    rotated[3][3-x] = current_block[x][3];
          
    rotated[x][3] = current_block[0][x];
          
    rotated[3-x][0] = current_block[3][3-x];
        }
        
    rotated[1][1] = current_block[2][1];
        
    rotated[1][2] = current_block[1][1];
        
    rotated[2][2] = current_block[1][2];
        
    rotated[2][1] = current_block[2][2];
        for (
    y=0y<4y++)
          for (
    x=0x<4x++)
            if (
    rotated[y][x] == 1) {
              if (
    block_array[by+y][bx+x] == 1)
                
    collide 1;
              if (
    bx+0)
                
    collide 1;
              if (
    bx+9)
                
    collide 1;
              if (
    by+19)
                
    collide 1;
            }
        if (
    collide == 0) {
          
    draw_current(bxby6);
          for (
    y=0y<4y++)
            for (
    x=0x<4x++)
              
    current_block[y][x] = rotated[y][x];
        }
      }
    }

    int check_move(int lastkey)
    {
      
    int c;
      if (
    readkey()) {
         
    readkey();
         if (
    c==0readkey();
         if (
    c==75lastkey 1//Left
         
    if (c==62lastkey 1//Left (Remote)
         
    if (c==77lastkey 2//Right
         
    if (c==64lastkey 2//Right (Remote)
         
    if (c==72lastkey 3//Up
         
    if (c==27lastkey 4//Esc
         
    if (c==80lastkey 5//Down
      
    }
      return 
    lastkey;
    }

    void draw_current(int aint bint n)
    {
      
    int xy;
      for (
    y=0y<4y++)
        for (
    x=0x<4x++)
          if (
    current_block[y][x] == 1)
            if (
    n<6)
              
    blit(bmpscreen0n*8150+(x*8)+(a*8), 20+(y*8)+(b*8), 88);
            else
              
    rectfill(screen150+(x*8)+(a*8), 20+(y*8)+(b*8), 157+(x*8)+(a*8), 27+(y*8)+(b*8), 0);
    }

    void move_down()
    {
      
    by++;
    }

    int set_block()
    {
      
    int xy;
      for (
    x=0x<4x++)
        for (
    y=0y<4y++)
          if (
    current_block[y][x] == 1)
            
    block_array[y+by][x+bx] = 1;
    }

    void plot_score()
    {
      
    int nmdigit;
      
    //blit(numbers, screen, 6*8, 0, 5*8+10, 80, 8, 8);
      
    score;
      
    n=5;
      do {
        
    digit = (int)fmod((double)m, (double)10);
        
    blit(numbersscreendigit*80n*9+36588);
        
    m=m/10;
        
    n--;
      } while (
    n>0);//while ((m > 0.1) && (n>0));
    }

    int check_lines()
    {
      
    int xylinelinesfirstlinen;
      
    lines 0firstline 1;
      for (
    y=byy<by+4y++) {
        
    line 1;
        for (
    x=0x<10x++)
          if (
    block_array[y][x] == 0)
            
    line 0;
        if (
    line == 1) {
          for (
    x=0x<10x++)
            for (
    n=yn>0n--)
              
    block_array[n][x] = block_array[n-1][x];
          
    lines=1;
          
    score++;
          
    plot_score();
          if (
    firstline == 1) {
            
    draw_current(oxoy6);
            
    draw_current(bxbycurrent_sprite);
            
    firstline 0;
          }
          for (
    n=7n>=0n--) {
            
    hline(screen15020+(y*8)+n2290);
            
    delay(30);
          }
          
    bmp2 create_bitmap(80, (y*8)+17);
          
    clear(bmp2);
          
    blit(screenbmp2150100080, (y*8)+10);
          for (
    n=0n<9n++) {
            
    blit(bmp2screen0015010+n80, (y*8)+10);
            
    delay(30);
          }
        }
      }
      return 
    lines;
    }

    int check_bottom(int hit)
    {
      
    int max_yxycollide;
      
    collide 0;
      for (
    x=0x<4x++) {
        
    max_y = -1;
        for (
    y=0y<4y++)
          if (
    current_block[y][x] == 1)
            
    max_y y+1;
        if (
    max_y != -1)
          if (
    max_y+by 19)
            
    collide 1;
          else if (
    block_array[max_y+by][x+bx] == 1)
            
    collide 1;
      }
      if (
    collide == 1)
        return 
    1;
      else
        return 
    hit;
    }

    void initialise_new_block()
    {
      
    int xy;
      
    bx 3;
      
    by 0;
      for (
    y=0y<4y++) {
        for (
    x=0x<3x++)
          
    current_block[y][x] = possible_blocks[next_block][y][x];
        
    current_block[y][3] = 0;
      }
      
    current_sprite next_sprite;
      
    next_block return_random(05);
      
    next_sprite return_random(05);
      
    draw_next(next_blocknext_sprite);
      
    draw_current(bxbycurrent_sprite);
    }

    void draw_next(int next_blockint n)
    {
      
    int ab;
      for (
    b=0b<4b++)
        for (
    a=0a<3a++)
          if (
    possible_blocks[next_block][b][a] == 1)
            
    blit(bmpscreen0n*8270+(a*8), 88+(b*8), 88);
          else
            
    rectfill(screen270+(a*8), 88+(b*8), 277+(a*8), 95+(b*8), 0);
    }

    int return_random(int minint max)
    {
      
    int rangevalue;
      
    range max min 1;
      
    value = (int)((float)rand() / (float)RAND_MAX range) + min;
      return 
    value;
    }

    void setupscreen()
    {

       
    PALETTE read_palettedef_palette;
       
    int xy;
       
    bmp create_bitmap(848); // Create bitmap in memory
       
    sideframe create_bitmap(135200);
       
    numbers create_bitmap(808);
       
    gameover create_bitmap(80160);
       
    clear(bmp);
       
    clear(sideframe);
       
    clear(numbers);
       
    clear(gameover);
       
    bmp load_bmp("blocks.bmp"read_palette);
       
    sideframe load_bitmap("sframe.bmp"read_palette);
       
    numbers load_bitmap("numbers.bmp"read_palette);
       
    gameover load_bitmap("gameover.bmp"read_palette);
       
    //set_palette( read_palette );
       
    blit(sideframescreen0000135200);
       
    plot_score();
       for (
    x=14x>=0x--) {
          
    //Main Area
          
    vline(screen149-x20180+xborder-x);
          
    vline(screen230+x20180+xborder-x);
          
    hline(screen149-x180+x230+xborder-x);
          for (
    y=14y>=0y--)
            if (
    border-y-x>15) {
              
    putpixel(screen149-x30-yborder-y-x);
              
    putpixel(screen230+x30-yborder-y-x);
            }
            else {
              
    putpixel(screen149-x30-y0);
              
    putpixel(screen230+x30-y0);
            };
          
    //Next Block Area
          
    vline(screen269-x87-x120+xborder-x);
          
    vline(screen294+x87-x120+xborder-x);
          
    hline(screen269-x120+x294+xborder-x);
          
    hline(screen269-x87-x294+xborder-x);
       }
       
    rectfill(screen150202291790);

       
    //save_bmp("scdump.bmp", screen, def_palette);

    Sorry for reposting the code, but that is the modified. Here's the errors I get now:
    Code:
     C:\Dev-C++\Tetris\Tetris.c
    [Warning] In function `int _mangled_main(int, char **)':
    
    125 C:\Dev-C++\Tetris\Tetris.c
    implicit declaration of function `int delay(...)'
    
    129 C:\Dev-C++\Tetris\Tetris.c
    parse error before string constant
    Last edited by Quantrizi; 06-15-2002 at 05:58 PM.

  6. #21
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    uh not sure but isnt you "3d array" actually a 1d array?
    What is C++?

  7. #22
    Unregistered
    Guest
    int possible_blocks[6][4][3]

    [6]=first array, [4]=second, [3]=third

    right?

  8. #23
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    i've never seen return(0) used. shouldn't it just be return 0? maybe either way works; i don't know.

  9. #24
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Originally posted by TechWins
    i've never seen return(0) used. shouldn't it just be return 0? maybe either way works; i don't know.
    Either way works.

  10. #25
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    a 3d array is like this...

    it is like... a 2d array except with multipel arrays for each...

    like this is a 3d array...

    Code:
    short Iblock[4][4][4] = {
                       {
                       {0, 0, 1, 0},
                       {0, 0, 1, 0},
                       {0, 0, 1, 0},
                       {0, 0, 1, 0}
                                  },
    
                       {
                       {0, 0, 0, 0},
                       {0, 0, 0, 0},
                       {1, 1, 1, 1},
                       {0, 0, 0, 0}
                                  },
    
                       {
                       {0, 0, 1, 0},
                       {0, 0, 1, 0},
                       {0, 0, 1, 0},
                       {0, 0, 1, 0}
                                  },
    
                       {
                       {0, 0, 0, 0},
                       {0, 0, 0, 0},
                       {1, 1, 1, 1},
                       {0, 0, 0, 0}
                                  }
                                  };
    What is C++?

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Game Idea (Tetris Maze)
    By SlyMaelstrom in forum Game Programming
    Replies: 13
    Last Post: 06-07-2006, 05:48 PM
  2. how to write a Tetris [newbie]
    By lifeisendless4m in forum C Programming
    Replies: 2
    Last Post: 10-12-2004, 09:38 PM
  3. ARGHARHGAHRHGH Help with Tetris
    By KneeGrow in forum Tech Board
    Replies: 3
    Last Post: 09-09-2004, 11:40 PM
  4. Test my new tetris game
    By PJYelton in forum Game Programming
    Replies: 6
    Last Post: 04-19-2003, 05:21 PM
  5. AGS Tetris Clone
    By Damascus in forum Game Programming
    Replies: 1
    Last Post: 03-07-2003, 04:17 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21