Jump to content

  • Log In with Google      Sign In   
  • Create Account


collision question


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 20 May 2012 - 06:37 PM

I am making a game where a space ship shoots bullets at bricks at the top of the screen.I have got the bricks to flash on and off quickly when hit by a bullet.I want the brick to turn off permanently.let me know if you need some code.I have done a great deal of research on this topic of collision detection.I just need a hint as to what to do next.I will continue to work on this problem.Thanks for all your help in advance.

Sponsor:

#2 McGrane   Members   -  Reputation: 827

Like
0Likes
Like

Posted 20 May 2012 - 08:12 PM

Im not sure i fully understand what your asking, is it just to destroy the block? If you have the collision part working, just change where you have the flashing code, to remove the brick from whatever way you are displaying them, not knowing what language your using or how your implementing this, maybe just add a bool, say ... bool isAlive = true;
if( isAlive ) { RenderBlock() }; .... if( hitTest(Block) ) isAlive = false; Im sure someone can give a more detailed reply if you give more details ;)

#3 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 20 May 2012 - 08:51 PM

here is some code
sprite sprite1;
sprite sprite2;
sprite1.x = 360+move;
sprite1.y = 510-ball_move;
sprite1.width = 5;
sprite1.height = 5;
sprite2.x = 0;
sprite2.y = 50;
sprite2.width = 0;
sprite2.height = 25;
if(Sprite_Collide(&sprite1,&sprite2)==1)
{
 render_blank();
}


#4 codeToad   Members   -  Reputation: 142

Like
0Likes
Like

Posted 20 May 2012 - 08:54 PM

Are you asking how to detect the collision, or how to make a block invisible?

To detect a collision, just check whether the bullet's coordinates are within the blocks coordinates. (i.e. (block.top >= bullet.y && block.bottom <= bullet.y && block.left <= bullet.x && block.right >= bullet.x)). Just do that for each bullet. (The ">=" and "<=" operators might need to be switched depending on what coordinate system you're using).

As for how to make a block invisible, I second McGrane. But you will have to have something a bit more complex since you want the blocks to flash before they disappear. So you will probably need an enum called BlockState that has 3 values - visible, flashing, and invisible. I don't know how you're currently keeping track of your blocks and making them flash, but I would imagine you need some sort of data structure like this:

class Block
{
    Vertex vertices[4];
    Index indices[2];
    Texture* texture;
    BlockState state;
    int flashTimeLimit;
    int elaspsedFlashingTime;
}

So when you detect a collision, you set that block's state to Flashing. Then on each frame, you update elapsedFlashingTime and check if it is greater than flashTimeLimit. If so, set the block's state to invisible. And of course, when rendering you would check the block's state and make the block flash or disappear accordingly.

#5 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 20 May 2012 - 09:16 PM

thanks codetoad let me chew on this for a while. actually I dont want the brick to flash just to turn off permanently.

#6 Endurion   Crossbones+   -  Reputation: 3332

Like
0Likes
Like

Posted 21 May 2012 - 12:09 AM

The main problem here seems to be that you have rendering and game logic intertwined.

You should separate those two. In your game loop check for collisions, and if the ball and brick collide, set a flag in the brick object that it's gone or completely remove it from the list (you do have a list of game/brick objects?)

If you choose the flag way (a bool would suffice) check the flag, and if it's set, skip the brick drawing code for that particular brick.
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

#7 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 22 May 2012 - 05:33 PM

thanks endurion ,I am doing research on vectors and lists.I am probably going to use vectors.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS