   Untitled
  how do i create different powers in a brick breacker game made in c++ using allegro  ??what is the logic of the code for it ??n also where do i get midi sounds brick collision ,rebound etc??   
Quote:Original post by mona27how do i create different powers in a brick breacker game made in c++ using allegro  ??what is the logic of the code for it ??What do you mean with "powers"?Quote:n also where do i get midi sounds brick collision ,rebound etc??Google. Although I believe MIDI sounds for this don't exist. I think you'll need to look for audio files.   ;  powers the objects that fall down aftr a broken brick and the player get advantages like additional life or the paddle get broader   ;  1. create a class (nothing fancy could even just be a POD type) that represents 'powers' in your breakout game.2. create a vector (or some other container type) of power objects with initial size 0 (i.e. no powers instanced yet)3. in the collision code of the ball/blocks make sure to 'push' a power onto the vector under some circumstance such as hitting a special type of block or a randomly generated event.4. create collision code with the paddle/powers and make sure to erase the power you collide with in a vectorpsuedo (C/C++) code step 4:for (std::vector<PowerUp>::iterator it = powersVec.begin( ); it != powersVec.end( ); ++it){    if (collision between currently pointed to power and paddle occured)    {    // apply your powers here anyway you wish example, player.Health += it->HealthBonus   powersVec.erase(it);    }}// ... dont think ive missed anything...thats a simple way of doing it. hope it helps.(damn im rusty, college work gets in the way to much)   ;  i dont know how to use vectors,so far im using double buffering and looping for movements,can you please give the logic for that here's the code i have so far //////////////////////////////////////////////////////////////////////////////////////   ////////////  POWER FILE ////////////   //////////////////////////////////////////////////////////////////////////////////////Power::Power(){ x1=0;  y1=0;}Power::~Power(){ }void Power::init(){x1 = rand_ex_i(0,SCREEN_W);y1 = rand_ex_i(0,SCREEN_H/3);dy1 = rand_ex_f(POWER_MAX_SPD,POWER_MIN_SPD );}// updates power ... returns true if the ball was lost (we lose a life) void Power::update(Paddle &paddle, GameField &game_field){    x1 = rand_ex_i(0,SCREEN_W);y1 = rand_ex_i(0,SCREEN_H/3); int up=0;    if ((game_field.ball_hit_brick(x1,y1)) ||( game_field.ball_hit_brick(x1,y1))||(game_field.ball_hit_brick(x1,y1)) || (game_field.ball_hit_brick(x1,y1)))   p= rand_ex_i(1,4);if(  (y1 > SCREEN_H -(SCREEN_H * 0.02))&& (!( (paddle.x==x1)&&(paddle.y==y1) ))  ) {   y1 += dy1;}    if((paddle.x==x1)&&(paddle.y==y1)){  up=1;}    if(up==1){ if(p==1)    game_field.score +=10;   else if(p==2) kernel.player_life++; else if(p==3)    { if(paddle.w > 15)    paddle.w--; }else if(p==4)    { if(paddle.w < SCREEN_W)    paddle.w++;}}}void Power::render(BITMAP * bmp){    DATAFILE *pow = NULL;  pow = load_datafile("power.dat");   if(pow == NULL)raise_error("Could not load datafile!");    draw_sprite(bmp, (BITMAP*)pow[1].dat, x1, y1);    unload_datafile(pow);};  I cannot tell you how to cconstruct your game thats something you have to do yourself (to learn) but I can provide you with a brief on what I know about vectors:have you ever used an array? if your making games you should be atleast comfortable with those before proceeding. If you are then vectors are basically managed-dynamic arrays (I personally think the name choice for this type of container is stupid, but thats just me and hey im not Bjarne, so yeah).They act in mostly the same way as regular arrays do except from the fact that these dynamic arrays can be resized at any point, plus they contain operators and methods to iterate, insert, erase, append elements and so on. the managed part comes from the fact that they manage the memory alloc/dealloc internally so you dont have to get your hands dirty with that (that is ofcourse if your like me and tend to be curious about the inner workings of third party libraries).the above code I posted uses objects called iterators, to traverse the vectors elements, you can however (and in this case probably should) use the array subscript operator ( this thing -> [] ) just like you would for normal arrays.Heres an example you can compile/run to get you started:#include <iostream>#include <vector>int main(int argc, char** argv){/*create an empty vector that stores integer types.the angular brackets with the type inside describe to the compilerwhat type of data this particular vector should hold, it can be anythingthat qualifies as a type, such as the built in types; int, char, double, float, etc..a struct or a class for your purposes you will need to construct a vector 'of' Power typeslike so:std::vector<Power> vecPower;*/std::vector<int> v; /* to append a vector you can call std::vector::push_back(...) accompanied bya value that is either of the same type of can be legally cast into the same typesuch as a float casted into an integer (I not sure if it is good practice to cast a floating pointvalue into an integer because of loss of data, even so, as long as you understand thats all that matters).In you case you may want to pass it a tempory Power object, something along the lines of:vecPower.push_back(Power());*/v.push_back(1);/*here I use a for loop to 'push_back' a number of integer types,since you will be creating/destroy Power objects at different stages of the gameprobably not what you want but is here to help convey the example.*/for (int i=1; i < 10; ++i) // push back another 9 elements to give a total of 10 elementsv.push_back(i+1);/*Yet another for loop, this time we are printing the individual elements of the array using the array subscriptoperator as opposed to an iterator like the last example. as you can see its is very similar to how you mightindex a regular C array.*/for (int i=0; i < v.size( ); ++i)std::cout << v << std::endl;// once the vector goes out of scope it will automatically be destroyed and destroy all its elements with it (this// is the 'managed' part i mentioned earlier), unless you dynamically allocate a vector which would just be silly imo.return 0;}You are probably also going to want to remove elements/objects from the vector so you should look into the std::vector methods pop_back, pop_front and eraseThe bottom line is, learn-practice-apply, learn-practice-apply, *voice fading* learn-practice-apply, learn-practice-apply, *fading* learn-practice-apply, learn-practice-apply, *gone* ...[Edited by - CodeCriminal on May 6, 2010 1:08:47 PM];  thanks a lot for your help,i get ur point learn-practice-apply,but the problem is that this is the first time i've actually tried to make a game n believe me its not that easy.I'm a undergrad in comp science,i have to give a game in c++ as a project. So far i've been taught c++ in theory which doesn't deal with third part libraries like you've mentioned or even allegro.Since i don't have much time to learn more on this as for now i was looking for logic which deals with basic c++ functions.   