• 12
• 12
• 9
• 10
• 13

Untitled

This topic is 2875 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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??

Share on other sites
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.

Share on other sites
powers the objects that fall down aftr a broken brick and the player get advantages like additional life or the paddle get broader

Share on other sites
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 vector

psuedo (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)

Share on other sites
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)
{
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);

{ y1 += dy1;}
{ up=1;}
if(up==1)
{ if(p==1)
game_field.score +=10;
else if(p==2)
kernel.player_life++;
else if(p==3)

}
else if(p==4)
}
}

}

void Power::render(BITMAP * bmp)
{
DATAFILE *pow = NULL;
if(pow == NULL)

draw_sprite(bmp, (BITMAP*)pow[1].dat, x1, y1);
}

Share on other sites
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 compiler		what type of data this particular vector should hold, it can be anything		that 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 types		like so:		std::vector<Power> vecPower;	*/	std::vector<int> v; 	/* 	to append a vector you can call std::vector::push_back(...) accompanied by	a value that is either of the same type of can be legally cast into the same type	such as a float casted into an integer (I not sure if it is good practice to cast a floating point	value 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 game	probably 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 elements		v.push_back(i+1);	/*	Yet another for loop, this time we are printing the individual elements of the array using the array subscript	operator as opposed to an iterator like the last example. as you can see its is very similar to how you might	index 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 erase

The 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]