Allegro help-o

This is a discussion on Allegro help-o within the Game Programming forums, part of the General Programming Boards category; Josh, Sorry if you are offended by any of that. At first I started to think why would anybody be ...

  1. #91
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    Josh,

    Sorry if you are offended by any of that.
    At first I started to think why would anybody be offended by what you said. I couldn't find anything that might be offending to me or anybody else. Then I realized about the part about the joints how it might be offending to some people (aka people who are way overly sensitive ).

    That sounds like a pretty cool game, though.

    Thanks for the ctrl key info.

    About the scrolling I read somewhere that you would just create an array. In certain parts of the array you load different bitmaps. One reasoning for doing that is because "you can't create a bitmap the size of the world".

    If the screen is at array[0] and the character moves completely to the right then you would display array[1] and if the character moves completely to the right you would display array[2] or if the character moved back to the left you would display array[0]. At least that seems like a logical way to do it. And of course the array[] would be the background.

    Vicious,

    I'm not going to do a game exactly like Asteroids because that wouldn't be original. I think I'm going to have it somewhat like Asteroids but with scrolling. So once you get done with a set of enemies then you would move up to go onto a next set of enemies. So since it's a little more complex than Asteroids I'm going to need controls that are a little more complex than Asteroids.

    Then again this is all speculation, and I have no idea whether I can do a game like this or not.

    Here is a good site for you guys to go to if you need free sound effects.

  2. #92
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    Hey, Josh, here is a site that offers free sprites

  3. #93
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    i made my "game" where when you hit the enemy with a laser... it makes the enemy go down beneath the screens viewing area...

    so i have movement.... lasers... col. detection....

    but it still stinks
    What is C++?

  4. #94
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    Why did you make it draw off screen? If it is hit, why not quit drawing it?

  5. #95
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    couldnt figure it out
    What is C++?

  6. #96
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    My game is pretty cool right now. The only problem I'm having is that when I move my plane and I'm shooting bullets and the bullets hit the enemy the enemy won't die. So right now the only way you can kill the enemy is if the bullets are alligned straight with the plane. But I'm sure I'll be able to take care of that problem.

    My game, also, has sound pretty cool sound effects as well.

    Vicious, here is what I did to make sure my enemy didn't go off the screen:

    Code:
    else if(x < 320 && key[KEY_LEFT] && enemy[i].x > 5)        {
          enemy[i].x -= 5;
          i = MAX_BULLETS;                                         }
         else if(x < 320 && key[KEY_RIGHT] && enemy[i].x < 555)   {
          enemy[i].x += 5;
          i = MAX_BULLETS;                                       }
         else if(x > 319 && key[KEY_RIGHT] && enemy[i].x < 555) {
          enemy[i].x +=5;
          i = MAX_BULLETS;                                     }
         else if(x > 319 && key[KEY_LEFT] && enemy[i].x > 5)  {
          enemy[i].x -=5;
          i = MAX_BULLETS;                                    }
           }
    As you can see I took a lot of the ideas from Josh. Well, I have my enemy as an 80x80 bitmap so change accordingly. Such as if the bitmap was a 25x25 I would change the 555 to 610. Because the x coord is on the left side of the bitmap. Make sense?

  7. #97
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    I think Vicious means he draws the enemies off screen when they are hit, just don't draw them. Take the code where you draw them off screen, and don't put anything. Or are you just changing the x and y to some place offscreen when they are hit?

  8. #98
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    Oh ok I see know.

    Btw, I just finally found the problem with my game. The enemy would only die if it was bullet[0] hitting him. I had been testing it out many many times and recoding things and it took me this long. Before I thought it might have something to do with me moving and shooting but nope.

  9. #99
    Registered User
    Join Date
    Sep 2001
    Posts
    305
    if you are doing what JoshG said, than your prog is a bit inefficient, isnt it? are you still drawing it when its off the screen?

  10. #100
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    Try doing this within your code that draws the enemies, put this where you have the part that draws the enemy:

    Code:
    if(enemy[x].exists == 1)
    {
      draw_sprite(...);
    }
    That way if the enemy does not exist, you don't draw him. This is assuming you have an enemy structure that has a interget (or bool) member named exists.

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

    besides the bad guys drawing off screen crap i have basically acomplished what i wanted... i dont think i will make this a complete game... ive figured out that im just not ready for such a project. ( omg, i just realized how much i use `...' )

    I would have to make options and power ups and bosses and score keeping and on and on and on.

    I want to takle something smaller b4 i go into this again.

    here is my current code

    Code:
    #include <allegro.h>
    
    #define max_laser 1
    #define max_baddies 9
      
    int counter, dir = 0;
    BITMAP *buffer = NULL;
    BITMAP *laser = NULL;
    BITMAP *baddy = NULL;
    BITMAP *boom = NULL;
    BITMAP *bg = NULL;
    BITMAP *title = NULL;
    
    void updatelasers();
    void enemypos();
    void enemymov();
    void checkcol();
    
    int bb_col ( int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2 )
    {
        if(y1 + h1 <= y2) 
            return 0;
        if(y1 >= y2 + h2) 
            return 0;
        if(x1 + w1 <= x2) 
            return 0;
        if(x1 >= x2 + w2) 
            return 0;
        return 1;
    } 
    
    
    struct laser
    {
       int x, y;
       bool exists;
    }lasers[max_laser];
    
    struct baddy
    {
       int x, y;
       bool exists;
    }baddies[8];
      
    class player  
    {  
       public:  
           int x, y, left, right, fire;
           BITMAP* ship;  
      
           player(): x(300), y(425), left(0), right(0) { ship = load_bitmap ( "ship.bmp", NULL ); }  
          ~player() { destroy_bitmap(ship); }  
      
           void  getmove()  
           {  
               if ( x > 0 && key[KEY_LEFT] )  
               {  
                  left = 1;  
               }  
      
               else  
               {  
                  left = 0;  
               }  
      
               if ( x < 600 && key[KEY_RIGHT] )  
               {  
                  right = 1;  
               }  
      
               else  
               {  
                  right = 0;  
               }
    
               if ( key[KEY_SPACE] )
               {
                  for ( int i = 0; i < max_laser; i++ )
                  {
                      if ( lasers[i].exists == 0 )
                      {
                          lasers[i].exists = 1;
                          lasers[i].x = x + 17;
                          lasers[i].y = y;
                          break;
                       }
                   }
               }
               updatelasers();
    
               if ( left == 1 ) x -= 10;  
               if ( right == 1 ) x += 10;  
            }  
      
            void draw(BITMAP* b)  
            {  
                draw_sprite ( b, ship, x, 425 );  
            }  
    };
      
    void update_counter()  
    {  
         counter++;  
    }END_OF_FUNCTION(update_counter);  
      
    int main()  
    {  
       allegro_init();  
       install_keyboard();  
       set_color_depth(32);  
       set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0);  
       buffer = create_bitmap( 640, 480 );
       laser = load_bitmap ( "laser.bmp", NULL );
       baddy = load_bitmap ( "Baddy.bmp", NULL );
       boom = load_bitmap ( "Baddy2.bmp", NULL );
       bg = load_bitmap ( "bg.bmp", NULL );
       title = load_bitmap ( "title.bmp", NULL );
       enemypos();
      
       LOCK_VARIABLE(counter);  
       LOCK_FUNCTION(update_counter);  
       install_int_ex( update_counter, BPS_TO_TIMER(60));  
      
       player *player1 = new player;
    
       do{  
           while ( counter > 0 )  
           {  
               player1->getmove();  
               counter--;  
           }  
      
           clear(buffer);
           player1->draw(buffer);
           enemymov();
    
           for(int a = 0 ; a < 8 ; a++)
           {
             if ( baddies[a].exists = 1 )
               draw_sprite ( buffer, baddy, baddies[a].x, baddies[a].y);
           }
    
           for(int i = 0; i < max_laser; i++)
               draw_sprite(buffer, laser, lasers[i].x, lasers[i].y);
    
    
    
           checkcol();
    
           blit( buffer, screen, 0, 0, 0, 0, 640, 480);  
      
       }  
       while ( !key[KEY_ESC] );  
     
       delete player1;
       destroy_bitmap(buffer);
       destroy_bitmap(laser);
       destroy_bitmap(baddy);
       destroy_bitmap(boom);
       allegro_exit();  
       return 0;  
    }  
    END_OF_MAIN();
    
    void updatelasers()
    {
    
      for(int j = 0; j < max_laser; j++)
      {
        if( lasers[j].exists == 1 )
        {
          if( lasers[j].y <= 0 )
            lasers[j].exists = 0;
        }
      }
    
      for(int i = 0; i < max_laser; i++)
      {
        if( lasers[i].exists == 1 )
        {
          lasers[i].y -= 10;
        }
      }
    }
    
    void enemypos()
    {
       baddies[0].x = 100;
       baddies[0].y = 20;
       baddies[1].x = 150;
       baddies[1].y = 20;
       baddies[2].x = 200;
       baddies[2].y = 20;
       baddies[3].x = 250;
       baddies[3].y = 20;
       baddies[4].x = 300;
       baddies[4].y = 20;
       baddies[5].x = 350;
       baddies[5].y = 20;
       baddies[6].x = 400;
       baddies[6].y = 20;
       baddies[7].x = 450;
       baddies[7].y = 20;
       baddies[8].x = 500;
       baddies[8].y = 20;
    }
    
    void enemymov()
    {
       if ( baddies[0].x > 10 && dir == 0 )
       {
           baddies[0].x--;
           baddies[1].x--;
           baddies[2].x--;
           baddies[3].x--;
           baddies[4].x--;
           baddies[5].x--;
           baddies[6].x--;
           baddies[7].x--;
           baddies[8].x--;
        }
    
        else if ( baddies[8].x < 600 )
        {
           dir = 1;
           baddies[0].x++;
           baddies[1].x++;
           baddies[2].x++;
           baddies[3].x++;
           baddies[4].x++;
           baddies[5].x++;
           baddies[6].x++;
           baddies[7].x++;
           baddies[8].x++;
       }
    
       else if ( baddies[8].x == 600 )
       {
           dir = 0;
       }
    }
    
    void checkcol()
    {
      for(int b = 0; b < max_baddies; b++)
        for(int c = 0; c < max_laser; c++)
           if(bb_col(baddies[b].x, baddies[b].y, 35, 41, lasers[c].x, lasers[c].y, 7, 10))
           {
             while ( baddies[b].y != 500 )
               baddies[b].y++;
           }
    
     }
    i owe everything to josh and ppl at the allegro.cc forums.

    When i make a whole game i want it to be enjoyable and i dont want to have other ppl make it for me (like this little "game" ).



    [edit]
    sorry if my code is crappy, im not flippin prelude or anything
    [/edit]
    What is C++?

  12. #102
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    Vicious, I came to the same conclusion as you last night. I don't feel that I'm ready for a game like this either. Trying to learn the API, while still learning C++ as well (I'm not that experienced yet), and making a 'big' game at the same time has become rather difficult. To ease the process of learning the API, I think I'm going to transform my Escape to Safety (maze) game into Allegro. This will be much simpler, because most of the hard work is already done.

    However, before I do that I need to fix up the shooter game first. It still has a few bugs in it, and I still want to have a playable version of the game.

    And I feel the sameway about most of the game wasn't even created by myself...in large part it's thanks to Josh.

  13. #103
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    Cool, I am stilla noob at this game programming stuff myself. I am working on a RPG engine, which I will probably never complete, but if I do it will be cool. I never finish anything I start, oh well.

  14. #104
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    lol, i can never think of anything to make.

    Anyideas? (of sometin ez?)
    What is C++?

  15. #105
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    I now understand when programmers say that once you fix one thing another bug appears. I swear I can testify for that, especially from the last few hours. Everytime I would fix one problem a new and totally unexpected problem would arise. Once my last problem occurred I gave up, and said this is the end of this game for now (well except maybe my words exact words were more vulgar). Not to mention I find the game so incredibly bornig now...but it might be cool to others.

    So now it's time to transform my maze game.

    That sounds cool Josh. Hopefully you get it to a "playable" version so I could try it out.

    Vicious, you could make a pong game, tetris, checkers, chess, etc...

    EDIT: If you wanna try out my game click here. It's a zip file and once you extract that file you are going to get a folder. Inside the folder there are 3 more .zips. Extract each of those inside the folder. The file size is still at 500k even with all of the compressing. I guess I need to learn how to use Allegro datafiles, eh. Oh and by the way, I'm using your (Josh) background for the game, is that okay? I think it looks awesome.

Page 7 of 8 FirstFirst 12345678 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Allegro in C for a newb
    By Ideius in forum C Programming
    Replies: 5
    Last Post: 12-29-2005, 03:36 PM
  2. Game Programming FAQ
    By TechWins in forum Game Programming
    Replies: 5
    Last Post: 09-29-2004, 02:00 AM
  3. double buffering for allegro
    By Leeman_s in forum C++ Programming
    Replies: 6
    Last Post: 09-12-2002, 02:45 PM
  4. Special Allegro Information
    By TechWins in forum Game Programming
    Replies: 12
    Last Post: 08-20-2002, 11:35 PM
  5. Allegro programming in a window
    By Person Man in forum Windows Programming
    Replies: 0
    Last Post: 11-16-2001, 02:23 PM

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