Help with my game

Hi, guys.. I'm relatively new to all this so I'll try to be as clear as I can.. I'm making a game in which you control an object that is on the bottom of the screen.. There are objects falling from the top and your goal is to catch them and not let them pass you.. I thought about making a queue of pointers that will point to the objects and going through them in a for loop while substracting from the Y coordinate... Anyway, my original code is not working, so I was wondering can you provide me with some links of code on how it is done ?
Sorry have not done this my self, but would love to see your game when your finished.

I'm also going to assume there are several ways to do what your talking about, but the one that came to my mind is when your falling object arrives at the Y coordinate where the paddle or net is, you should put in a check to see if the paddle/net is between X40-X45 or what ever the size of your object is.

If you want help on your project, post your code.
Try posting your initial code, we'll help you with that.
Well, actually, yes. I thought in that direction as well.. I was thinking about making a queue of circles ( Krug = Circle in Serbian :) ) and whenever an object from queue.front() comes in the Y coordinate of the net ( or a little lower, it drops out ) it's deleted from the queue.. Don't even know is it possible to do this, any help would be appreciated.. Here's the code, but I don't know is it of any good :

So, whenever a period of time passes

sf::Shape* p = new sf::Shape();
Krug.SetPosition( (float)(rand() % 800) , 0.0);

I make a new object and send its refference to the queue.. And

if (p->GetY==Net.Y)
delete p;

p->Move( 0, 100 * ElapsedTime );;

Try checking if the object y is greater than the nets y. if (p->GetY>=Net.Y)
You could consider reusing the same objects instead of re-creating them and deleting them.

SF::shape Krug;
(if red.front()->Gety() >= Net.GetY())

When checking with ==, you are risking the possibility that p->y is never going to be exactly equal to Net.y. For example, if

frame n:   P->y == 150, Net.y == 155
frame n+1: P->y == 160, Net.y == 155

You can set a tolerance how close they can be before considered caught, or like naruku said use >=.

Last edited on
Topic archived. No new replies allowed.