My Allegro Program will not run...

This is a discussion on My Allegro Program will not run... within the Game Programming forums, part of the General Programming Boards category; uh.. i spent all night on this and when i run it its a blank screen and it will not ...

  1. #1
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200

    My Allegro Program will not run...

    uh.. i spent all night on this and when i run it its a blank screen and it will not let you exit... plaese help...

    Code:
    #include <time.h>
    #include <allegro.h>
    #include <stdio.h>
    
    volatile int dropdelay = 0;
    
    int counter;
    int board[20][10];
    int boardx = 220, boardy = 40;
    short blockx = 3;
    short blocky = 0;
    short current_rotation = 0;
    
    short (*current_piece)[4][4];
    short (*next_piece)[4][4];
    
    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}
                                  }
                                  };
    short Jblock[4][4][4] = {
                       {
                       {0, 1, 0, 0},
                       {0, 1, 0, 0},
                       {0, 1, 1, 0},
                       {0, 0, 0, 0}
                                  },
    
                       {
                       {0, 0, 0, 0},
                       {0, 1, 1, 1},
                       {0, 1, 0, 0},
                       {0, 0, 0, 0}
                                  },
    
                       {
                       {0, 0, 0, 0},
                       {0, 1, 1, 0},
                       {0, 0, 1, 0},
                       {0, 0, 1, 0}
                                  },
    
                       {
                       {0, 0, 0, 0},
                       {0, 0, 1, 0},
                       {1, 1, 1, 0},
                       {0, 0, 0, 0}
                                  }
                                  };
    short Lblock[4][4][4] = {
                       {
                       {0, 0, 0, 0},
                       {0, 1, 1, 0},
                       {0, 1, 0, 0},
                       {0, 1, 0, 0}
                                  },
    
                       {
                       {0, 0, 0, 0},
                       {1, 1, 1, 0},
                       {0, 0, 1, 0},
                       {0, 0, 0, 0}
                                  },
    
                       {
                       {0, 0, 1, 0},
                       {0, 0, 1, 0},
                       {0, 1, 1, 0},
                       {0, 0, 0, 0}
                                  },
    
                       {
                       {0, 0, 0, 0},
                       {0, 1, 0, 0},
                       {0, 1, 1, 1},
                       {0, 0, 0, 0}
                                  }
                                  };
    short Oblock[4][4][4] = {
                       {
                       {0, 0, 0, 0},
                       {0, 1, 1, 0},
                       {0, 1, 1, 0},
                       {0, 0, 0, 0}
                                  },
    
                       {
                       {0, 0, 0, 0},
                       {0, 1, 1, 0},
                       {0, 1, 1, 0},
                       {0, 0, 0, 0}
                                  },
    
                       {
                       {0, 0, 0, 0},
                       {0, 1, 1, 0},
                       {0, 1, 1, 0},
                       {0, 0, 0, 0}
                                  },
    
                       {
                       {0, 0, 0, 0},
                       {0, 1, 1, 0},
                       {0, 1, 1, 0},
                       {0, 0, 0, 0}
                                  }
                                  };
    short Tblock[4][4][4] = {
                       {
                       {0, 1, 0, 0},
                       {0, 1, 1, 0},
                       {0, 1, 0, 0},
                       {0, 0, 0, 0}
                                  },
    
                       {
                       {0, 0, 0, 0},
                       {1, 1, 1, 0},
                       {0, 1, 0, 0},
                       {0, 0, 0, 0}
                                  },
    
                       {
                       {0, 1, 0, 0},
                       {1, 1, 0, 0},
                       {0, 1, 0, 0},
                       {0, 0, 0, 0}
                                  },
    
                       {
                       {0, 1, 0, 0},
                       {1, 1, 1, 0},
                       {0, 0, 0, 0},
                       {0, 0, 0, 0}
                                  }
                                  };
    short Sblock[4][4][4] = {
                       {
                       {0, 0, 0, 0},
                       {0, 0, 1, 0},
                       {0, 1, 1, 0},
                       {0, 1, 0, 0}
                                  },
    
                       {
                       {0, 0, 0, 0},
                       {1, 1, 0, 0},
                       {0, 1, 1, 0},
                       {0, 0, 0, 0}
                                  },
    
                       {
                       {0, 0, 0, 0},
                       {0, 0, 1, 0},
                       {0, 1, 1, 0},
                       {0, 1, 0, 0}
                                  },
    
                       {
                       {0, 0, 0, 0},
                       {1, 1, 0, 0},
                       {0, 1, 1, 0},
                       {0, 0, 0, 0}
                                  }
                                  };
    short Zblock[4][4][4] = {
                       {
                       {0, 1, 0, 0},
                       {0, 1, 1, 0},
                       {0, 0, 1, 0},
                       {0, 0, 0, 0}
                                  },
    
                       {
                       {0, 0, 0, 0},
                       {0, 1, 1, 0},
                       {1, 1, 0, 0},
                       {0, 0, 0, 0}
                                  },
    
                       {
                       {0, 1, 0, 0},
                       {0, 1, 1, 0},
                       {0, 0, 1, 0},
                       {0, 0, 0, 0}
                                  },
    
                       {
                       {0, 0, 0, 0},
                       {0, 1, 1, 0},
                       {1, 1, 0, 0},
                       {0, 0, 0, 0}
                                  }
                                  };
    
    
    BITMAP *buffer;
    BITMAP *block;
    BITMAP *block_change;
    BITMAP *back;
    BITMAP *bg;
    
    void setup();
    void load_bitmaps();
    
    void update_counter()  
    {  
         counter++;  
    }END_OF_FUNCTION(update_counter);
    
    void rotate_c( short blocks[4][4][4] )
    {
        int next_rotation = current_rotation - 1;
        if ( next_rotation == -1 )
        next_rotation = 3;
    
        for ( int x = 0; x < 4; x++ )
            for ( int y = 0; y < 4; y++ )
                if ( blocks[current_rotation][x][y] )
                    if ( blockx + x - 1 < 0 )
                    {
                        if(( blockx + x < 0) || (blockx + x > 9) || (blocky + y > 19))
                        return;
                        if( board[x + blockx][y + blocky] )
                        return;
                    }
    
        current_rotation = next_rotation;
    
    }
    
    void rotate_cc( short blocks[4][4][4] )
    {
        int next_rotation = current_rotation + 1;
        if ( next_rotation == 4 )
        next_rotation = 0;
    
        for ( int x = 0; x < 4; x++ )
            for ( int y = 0; y < 4; y++ )
                if ( blocks[current_rotation][x][y] )
                    if ( blockx + x - 1 < 0 )
                    {
                        if(( blockx + x < 0) || (blockx + x > 9) || (blocky + y > 19))
                        return;
                        if( board[x + blockx][y + blocky] )
                        return;
                    }
    
        current_rotation = next_rotation;
    
    }
    
    void move_L( short blocks[4][4][4] )
    {
       for( int y = 0; y < 4; y++ )
       {
           if ( y + blocky < 0 )
               continue;
    
           for( int x = 0; x < 4; x++ )
               if ( blocks[current_rotation][x][y] )
                   if ( blockx + x - 1 < 0 )
                       return;
                   else if ( board[x + blockx - 1][y + blocky] )
                       return;
        }
    
        blockx--;
    }
    
    void move_R( short blocks[4][4][4] )
    {
       for( int y = 0; y < 4; y++ )
       {
           if ( y + blocky < 0 )
               continue;
    
           for( int x = 0; x < 4; x++ )
               if ( blocks[current_rotation][x][y] )
                   if ( blockx + x + 1 > 9 )
                       return;
                   else if ( board[x + blockx + 1][y + blocky] )
                       return;
        }
    
        blockx++;
    }
    
    void draw_to_board( short blocks[4][4][4], int xend, int yend )
    {
        xend = boardx + ( blockx * 20 );
        yend = boardy + ( blocky * 20 );
    
        for ( int x = 0; x < 4; x++ )
            for ( int y = 0; y < 4; y++ )
                if ( blocks[current_rotation][x][y] && ( y + blocky >= 0 ) )
                    blit ( block, buffer, 0, 0, xend + ( 20 * x ), yend + ( 20 * y), 20, 20 );
    }
    
    void draw( short blocks[4][4][4], int xend, int yend )
    {
        for ( int x = 0; x < 4; x++ )
          for ( int y = 0; y < 4; y++ )
             if ( blocks[0][x][y] && (y + blocky >= 0) )
                blit ( block, buffer, 0, 0, xend + ( 20 * x ), yend + ( 20 * y ), 20, 20 );
    }
    
    bool fall( short blocks[4][4][4] )
    {
       for(int y = 0; y < 4; y++)
       {
          if(y + blocky < 0)
             continue;
    
          for(int x = 0; x< 4; x++)
             if(blocks[current_rotation][x][y])
                if( blocky + y + 1 > 19 )
                   return 0;
                else if( board[x + blockx][y + blocky + 1] )
                   return 0;
       }
    
       blocky++;
       return 1;
    }
    
    bool game_over( short blocks[4][4][4] )
    {
        for ( int x = 0; x < 4; x++ )
            for ( int y = 0; y < 4; y++ )
               if ( blocks[current_rotation][x][y] )
                   if ( board[x + blockx][y + blocky] )
                       return 1;
    
        return 0;
    }
    
    
    
    ////////////////////////////////////MAIN////////////////////////////////////////
    
    int main() 
    { 
       setup();
       load_bitmaps();
    
       short lineclear[10][20];
       short clearline[20];
    
       int level = 0;
       int dropd = 0;
       int score = 0;
       int linenum = 0;
    
       bool quit = 0;
    
       short moveleft = 0;
       short moveright = 0;
       short rotate_c_ = 0;
       short rotate_cc_ = 0;
       short drop = 0;
    
       switch ( rand() % 7 )
       {
           case 0: current_piece = Oblock; break;
           case 1: current_piece = Iblock; break;
           case 2: current_piece = Lblock; break;
           case 3: current_piece = Jblock; break;
           case 4: current_piece = Sblock; break;
           case 5: current_piece = Zblock; break;
           case 6: current_piece = Tblock; break;
       }
    
       switch ( rand() % 7 )
       {
           case 0: next_piece = Oblock; break;
           case 1: next_piece = Iblock; break;
           case 2: next_piece = Lblock; break;
           case 3: next_piece = Jblock; break;
           case 4: next_piece = Sblock; break;
           case 5: next_piece = Zblock; break;
           case 6: next_piece = Tblock; break;
       }
    
       int speed[10] = { 30, 25, 20, 15, 10, 6, 5, 4, 3, 1 };
    
       for ( int y = 0; y < 20; y++ )
           for ( int x = 0; x < 10; x++ )
               board[x][y] = lineclear[x][y] = 0;
    
       while ( !quit )
       {
           clear(buffer);
    
           draw_sprite ( buffer, bg, 210, 30 );
    
           for ( int y = 0; y < 20; y++ )
             for ( int x = 0; x< 10; x++ )
                if ( board[x][y] )
                   blit( back, buffer, 0, 0, boardx + 20 * x, boardy + 20 * y, 20, 20);
    
           draw_to_board ( current_piece, boardx, boardy );
           draw ( next_piece, 500, 100 );
    
           textprintf ( buffer, font, 5, 10, makecol16(255,255,255), "Score         = %d",  score);
           textprintf ( buffer, font, 5, 20, makecol16(255,255,255), "Lines Cleared = %d",  linenum);
           textprintf ( buffer, font, 5, 30, makecol16(255,255,255), "Level         = %d",  level);
           textprintf ( buffer, font, 5, 50, makecol16(255,255,255), "Drop Distance = %d",  dropd);
    
           blit(buffer, screen, 0, 0, 0, 0, 640, 480);
    
           while ( counter > 0 )
           {
               if ( key[KEY_LEFT] && ( !moveleft || moveleft == 15 ) )
               {
                   move_L ( current_piece );
                   if ( !moveleft ) moveleft = 1;
               }
               else if(key[KEY_LEFT])
                   moveleft++;
               else if(!key[KEY_LEFT])
                   moveleft = 0;
    
               if ( key[KEY_RIGHT] && ( !moveright || moveright == 15 ) )
               {
                   move_R ( current_piece );
                   if ( !moveright ) moveright = 1;
               }
               else if(key[KEY_RIGHT])
                   moveright++;
               else if(!key[KEY_RIGHT])
                   moveright = 0;
    
               if ( key[KEY_Z] && !rotate_cc_ )
               {
                   rotate_cc ( current_piece );
                   rotate_cc_ = 1;
               }
               else if ( !key[KEY_Z] )
                   rotate_cc_ = 0;
    
               if ( key[KEY_X] && !rotate_c_ )
               {
                   rotate_c ( current_piece );
                   rotate_c_ = 1;
               }
               else if ( !key[KEY_X] )
                   rotate_c_ = 0;
    
               if(key[KEY_DOWN] && !drop)
               {
                  dropd++;
                  dropdelay = 200;
               }
               else if(!key[KEY_DOWN])
                  dropd = drop = 0;
    
               if ( key[KEY_ESC] ) quit = 1;
    
               if ( dropdelay > speed[level] )
               {
                   if ( !fall( current_piece ) )
                   {
                       for ( int y = 0; y < 4; y++ )
                           for ( int x = 0; x< 4; x++ )
                               if ( current_piece[current_rotation][x][y] )
                                   board[x + blockx][y + blocky] = current_piece[current_rotation][x][y];
    
                   current_piece = next_piece;
    
                   switch ( rand() % 7 )
                   {
                       case 0: next_piece = Oblock; break;
                       case 1: next_piece = Iblock; break;
                       case 2: next_piece = Lblock; break;
                       case 3: next_piece = Jblock; break;
                       case 4: next_piece = Sblock; break;
                       case 5: next_piece = Zblock; break;
                       case 6: next_piece = Tblock; break;
                   }
    
                   blockx = 3;
                   blocky = 0;
                   current_rotation = 0;
    
                   if ( game_over( current_piece ) )
                   {
                       clear(buffer);
                       draw_sprite ( buffer, bg, 210, 30 );
    
                       for ( int y = 0; y < 20; y++ )
                         for ( int x = 0; x < 10; x++ )
                            if ( board[x][y] )
                               blit( back, buffer, 0, 0, boardx + 20 * x, boardy + 20 * y, 20, 20);
    
                       draw_to_board ( current_piece, boardx, boardy);
                       draw (next_piece, 500, 100);
    
                       blit( buffer, screen, 0, 0, 0, 0, 640, 480 );
    
                       quit = 1;
                    }
    
                    int count = 0;
                    int linescleared = 0;
    
                    for ( int y = 0; y < 20; y++ )
                    {
                        count = 0;
                        clearline[y] = 0;
    
                        for ( int x = 0; x < 10; x++ )
                            if ( board[x][y] )
                                count++;
    
                        if ( count == 10 )
                        {
                            clearline[y] = 1;
                            linenum++;
                        }
                     }
    
                     for(int y = 0; y < 20; y++)
                        for(int x = 0; x < 10; x++)
                           lineclear[x][y] = 0;
    
                     for( int y = 19, count = 19; y >= 0; y-- )
                     {
                         for(int x = 0; x < 10; x++)
                         lineclear[x][count] = board[x][y];
    
                         if(!clearline[y])
                         count--;
                     }
    
                     for(int y = 0; y < 20; y++)
                        for(int x = 0; x < 10; x++)
                           board[x][y] = lineclear[x][y];
    
    
    
              }
            }
         }
       }
    
       destroy_bitmap(block);
       destroy_bitmap(buffer);
       destroy_bitmap(block_change);
       allegro_exit();
       return 0;
    }     
    END_OF_MAIN();
    
    ///////////////////////////////////////////////////////////////////////////////
    
    void setup()
    {
       allegro_init();
       install_keyboard();  
       set_color_depth(32);  
       set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0);
    
       LOCK_VARIABLE(counter);  
       LOCK_FUNCTION(update_counter);  
       install_int_ex( update_counter, BPS_TO_TIMER(60));
    
       text_mode ( -1 );
    
       srand(time(NULL));
    }
    
    void load_bitmaps()
    {
       block = load_bitmap( "block.bmp", NULL );
       block_change = load_bitmap( "block2.bmp", NULL );
       buffer = create_bitmap( 640, 480 );
       bg = load_bitmap( "bg.bmp", NULL );
       back = load_bitmap( "backing.bmp", NULL );
    }
    What is C++?

  2. #2
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    1. The load_bitmap() function should not have the "NULL" value, but screen.

    2. Instead of allegro_exit(), use readkey() by installing the keyboard() routine.

  3. #3
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    Actualy load_bitmap can have NULL for the second parameter if you are using true color mode.

  4. #4
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Oh...sorry. But you should still use the readkey() function instead of the allegro_exit() function. That might be the problem. If not, then I'll try to see what else I can do for ya

  5. #5
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    nope i found out that i was using load_bitmap for the back bitmap when i should have create_bitmap

    but know the program runs shows the graphics but does absolutely nothing unless you hit down and the it goes all crazy...
    What is C++?

  6. #6
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Try changing your moveleft, moveright, etc... stuff and see what happens.

  7. #7
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    change it t what?...
    What is C++?

  8. #8
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Try taking them out....I'm not to sure on what to do with this, but I think if you take those functions out, it might work.

  9. #9
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    uh.. then how will i move left and right?
    What is C++?

  10. #10
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    the KEY_LEFT and the KEY_RIGHT.

  11. #11
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    but why... just humor me ... would these funcs (move_L and R ??? )

    be causing the program to do this?
    What is C++?

  12. #12
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    Do it the way I was doing the shooter game, it is simple.


    Code:
    while(!key[KEY_ESC])
    {
      if(key[KEY_LEFT])
      ...
    
      else if(key[KEY_RIGHT])
      ...
    
      updatescreen();
    }

  13. #13
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    true... i was tryin to be too fancy i guess :P

    Ill go try to figure this stuff out

    I need to make it fall by itself and collision stuff... and control the speed for rotation and movement

    [edit]
    see you all next year
    [/edit]
    What is C++?

  14. #14
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    Ill go try to figure this stuff out
    That's exactly what you should do. Instead of always posting what you're problems are and that you don't know what to do next, you should go figure it out for yourself. You'd be much better off trying things out on your own on a more consistent basis. I'm not saying that you don't try, but many times you write that you have a problem. So do what you said and go try things out for yourself. If you truly can't figure out the problem, then do ask a question. But more often than not you should try to figure it out by yourself.

    I'm not trying to be rude or offend you in any way, either.

  15. #15
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    >> I'm not trying to be rude or offend you in any way, either.

    yah, sure tech

    Well im quit the impatient one... i tend to run into a prob and immediately post it... alot of times ill figure it out right after i post...

    i gotta quit that
    What is C++?

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

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 02:30 PM
  2. Re-doing a C program to run in Win2000 or XP
    By fifi in forum C Programming
    Replies: 5
    Last Post: 08-17-2007, 05:32 PM
  3. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  4. Replies: 3
    Last Post: 07-11-2005, 03:07 AM
  5. program won't run standalone
    By richard in forum C++ Programming
    Replies: 2
    Last Post: 07-20-2002, 06:21 PM

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