# Space invader barrier implementation algorithm

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

## Recommended Posts

I've been struggling with implementing the space invader bullet to barriers. I wanted right now to blast a circle around, when the bullet hits the barrier and modifies the circle. As shown in the video, the algorithm looks wrong,

I have tried my best to debug it, but I've failed.

here is the algorithm:

// if there is intersection
if (IntersectsWith((*it)->BoundingRect, barrierRect))
{
// subtract (*it) bullet position from barrrier's rect
int normX = (*it)->Position.x - barrierRect.x;
int normY = (*it)->Position.y - barrierRect.y;

// barrier image pixels
uint32* ptr = (uint32*)pixels;
// height of the barrier
int y = 31;

for (int i = 0; i < 31; i++)
{
int pixelOffset = y + normX * 51;
int color = ptr[pixelOffset];
// look up the color if its not black, it should be green
if (color != 0xFF000000)
{
// delete the bullet
Bullet *bullet = *it;
it = ship->Bullets->erase(it);
delete bullet;
ship->Canfire = true;
isCollision = true;

// blast a circle around that bullet hit position
{
{
{
int j = x + normX;
int i = y + normY;
int pixelOffset = j + i * 51;
ptr[pixelOffset] = 0xff000000;
}
}
}
break;
}
// go up
y--;
}


##### Share on other sites

Ahmed, this seems to be the same question you asked on Feb 24th, Feb 19thFeb 15th, and on Feb 9th.

All of these are building on exactly the same basic problem, so instead of constantly reposting what is basically the same question with a few small details changed as you've progressed you should reply again to your older topic so that people can see what you have been doing and what advice has already been given.

I'm closing this topic, and suggesting that you post in the most recent of your previous ones instead.  Let people know which of their suggestions you've already tried, what progress (if any) you've made, and what problems you're still having.

##### Share on other sites

One additional note:  I just found that this post is also on the same topic, and I would probably agree with frob's assessment that this project seems to be above your current skill level.  It might be beneficial to put this aside for now and go back to basics before attempting it again.

##### Share on other sites

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

This topic is now closed to further replies.

1. 1
Rutin
22
2. 2
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633308
• Total Posts
3011294
• ### Who's Online (See full list)

There are no registered users currently online

×