class CGameObject
{
public:
float xPos; //x position
float yPos; //y position
float xVel; //x velocity
float yVel; //y velocity
RECT shape; //describes shape of bitmap
};
Are there any suggestions on how to implement my bricks?
Programming Alleyway/Breakout
I''m programming my first game right now, it''s an Alleyway/Breakout clone. It''s 65% finished, including physics, hit detetection and a ''lives left'' counter/graphic. My problem is, what''s the best way to display the bricks to break? I could use brute force to get them up there, but that would mean programming each level.
So here''s what I thought, but I can''t figure out how to implement hit detection on it. Create an array using:
int brickArray[ROWS][COLS];
Then I can populate those values using 1 or 0. 1 means the brick is there 0 means it''s not. But where would I go from there? I am wrapping all my game objects in a class which derives from this class:
If you implement your levels as arrays, one method would be to load the array at the beginning of each level and from there create a linked list of brick objects from the array. Then when performing collision detection, you can just iterate through the list. When a collision is detected on a brick, delete the brick form the list.
I''m actually not too great with linked lists. Which kind should I be using for my game objects? ''singly-linked lists'', ''doubly-linked lists''? What data do I store in them? A new CGameObject (something in the game like a bad-guy or something) class?
And do any of you guys know any linked list tutorials?
And do any of you guys know any linked list tutorials?
Well, you don''t *REALLY* need a linked-list, I''m guessing you''re going to have +- 100 bricks.
I think what SiCrane was trying to say was that
At the start of each level, load in your 0/1 array. Then
calculate the bounds of each brick and put it in an array of
brick structures as follows:
I hope that''s helped!
FReY
I think what SiCrane was trying to say was that
At the start of each level, load in your 0/1 array. Then
calculate the bounds of each brick and put it in an array of
brick structures as follows:
struct brick{ int left,right,top,bottom; int hitsleft; char *image;};brick bricks[MAX_BRICKS];[/source]Notice that you''d generate a structure like this for each brick,and then check every structure for collisions. eg.[source] for (count=0;count<numbricks;count++) { if (is_collision(ballx,bally,bricks[count])) { // decrease number of hits. // make ball bounce (change direction) // etc... } }
I hope that''s helped!
FReY
do unto others... and then run like hell.
October 24, 2000 09:44 PM
There''s a Breakout thread in the Java messageboard, source is included
Well, since I just posted a game like this on the Showcase (its called Klunk, go ahead...check it out)...
Ok, all I did was load in the data from a file into a 2D array (level[ROWS][COLS])...then when it came time to draw them...I wrote a function to setup the level and gave each block a seperate structure (in an array...blocks[NUM_BLOCKS]) to contain it's information. This structure included the x & y positions, the height, width, color, etc. When it came time to draw the blocks I just iterated through all the blocks and, if they weren't already hit, drew them.
Hope that helped.
MSkinn99
Edited by - MSkinn99 on October 24, 2000 10:58:04 PM
Ok, all I did was load in the data from a file into a 2D array (level[ROWS][COLS])...then when it came time to draw them...I wrote a function to setup the level and gave each block a seperate structure (in an array...blocks[NUM_BLOCKS]) to contain it's information. This structure included the x & y positions, the height, width, color, etc. When it came time to draw the blocks I just iterated through all the blocks and, if they weren't already hit, drew them.
Hope that helped.
MSkinn99
Edited by - MSkinn99 on October 24, 2000 10:58:04 PM
-MSkinn99What's done is done (Until you hit Undo) :)Two wrongs don't make a right; but 3 lefts do.You'd be paranoid too if everyone was out to get you.
Yet another game programming web page...
Yet another game programming web page...
Awesome. Thanks guys! I now have a full screen of bricks that I can freely break. The only problem I believe is my game loop.
For MSKinn: How did you set up your loop?
Right now, my ball changes velocity, but it can go over 15 pixels per frame, BUT my bricks are 15 pixels high!! So what happens is, the ball goes through them, or they disappear and my ball doesn''t react properly. What should I be doing to counter this? Lower the ball speed?
My game is locked at 30fps.
For MSKinn: How did you set up your loop?
Right now, my ball changes velocity, but it can go over 15 pixels per frame, BUT my bricks are 15 pixels high!! So what happens is, the ball goes through them, or they disappear and my ball doesn''t react properly. What should I be doing to counter this? Lower the ball speed?
My game is locked at 30fps.
You *COULD* reduce your ball speed or you perform 2 collision tests per frame.
ie. the following is called once per frame
move ball (10 to 15) pixels
check for collision
move ball rest of pixels.
check for collision
of course this will double your collision testing, but at least it will be accurate.
FReY
ie. the following is called once per frame
move ball (10 to 15) pixels
check for collision
move ball rest of pixels.
check for collision
of course this will double your collision testing, but at least it will be accurate.
FReY
do unto others... and then run like hell.
Not a problem DJ.
The game loop simply ran through all of the basic functions (i.e. move, draw, etc.), but that is probably not what you wanted...
Ok, so my ball only moved 2 or 3 pixels per frame, but instead of having a fixed frame rate, I used a timing variable (which I created at startup) to use as a modifier. Ok, that was confusing...let me explain.
1) I time how long it takes to do...whatever I felt like doing...i don''t really remember what.
2) I use that timing number as a scaling factor for my movements.
So, the faster the computer, the smoother the movement.
BTW, this is called full decoupling...got it from some book...
Again, hope that helps.
MSkinn99
P.S. *PLEASE* check out Klunk (*MY* breakout clone) if you haven''t already. Feedback is appreciated.
What's done is done (Until you hit Undo) :)
The game loop simply ran through all of the basic functions (i.e. move, draw, etc.), but that is probably not what you wanted...
Ok, so my ball only moved 2 or 3 pixels per frame, but instead of having a fixed frame rate, I used a timing variable (which I created at startup) to use as a modifier. Ok, that was confusing...let me explain.
1) I time how long it takes to do...whatever I felt like doing...i don''t really remember what.
2) I use that timing number as a scaling factor for my movements.
So, the faster the computer, the smoother the movement.
BTW, this is called full decoupling...got it from some book...
Again, hope that helps.
MSkinn99
P.S. *PLEASE* check out Klunk (*MY* breakout clone) if you haven''t already. Feedback is appreciated.
What's done is done (Until you hit Undo) :)
-MSkinn99What's done is done (Until you hit Undo) :)Two wrongs don't make a right; but 3 lefts do.You'd be paranoid too if everyone was out to get you.
Yet another game programming web page...
Yet another game programming web page...
Actually, that sounds like a much better method than what I have. In some cases, my ball jumps 13 pixels, which actually messes up my formula. It can "skip" over bricks, if it''s going at just the right angle. Ok, here''s what my main game loop basically is:
DWORD startFrame = GetTickCount();
DWORD endFrame = startFrame + 33;
MoveBall();
while(GetTickCount() < endFrame){}
MoveBall() runs something like:
{
myBall.xPos += myBall.xVel;
myBall.yPos += myBall.yVel;
HitDetectionOnAllGameObjects();
}
So everyf rame (I have it locked at 30), my ball moves from its current position to the next one, according to velocity, which I allow to reach up to 12.9. So in 1 frame, it can move 12 pixels!
The thing I don''t understand about your method is, how can you control how fast the ball is moving, if you have it set at 2 pixels per frame, yet nothing locking how many frames go by in a second. If someone has 60 frames go by, the ball will fly, but if someone only has 30 frames go by, the ball will be slow.?.? I think.
BTW, I checked out Klunk and it works great.
DWORD startFrame = GetTickCount();
DWORD endFrame = startFrame + 33;
MoveBall();
while(GetTickCount() < endFrame){}
MoveBall() runs something like:
{
myBall.xPos += myBall.xVel;
myBall.yPos += myBall.yVel;
HitDetectionOnAllGameObjects();
}
So everyf rame (I have it locked at 30), my ball moves from its current position to the next one, according to velocity, which I allow to reach up to 12.9. So in 1 frame, it can move 12 pixels!
The thing I don''t understand about your method is, how can you control how fast the ball is moving, if you have it set at 2 pixels per frame, yet nothing locking how many frames go by in a second. If someone has 60 frames go by, the ball will fly, but if someone only has 30 frames go by, the ball will be slow.?.? I think.
BTW, I checked out Klunk and it works great.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement