Jump to content
  • Advertisement
Sign in to follow this  

Space invader barrier implementation algorithm

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

If you intended to correct an error in the post then please contact us.

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 radius = 9;
                for (int y = -radius; y <= radius; y++)
                {
                    for (int x = -radius; x <= radius; x++)
                    {
                        if (x*x + y*y <= radius*radius)
                        {
                            int j = x + normX;
                            int i = y + normY;
                            int pixelOffset = j + i * 51;
                            ptr[pixelOffset] = 0xff000000;
                        }
                    }
                }
                break;
            }
            // go up
            y--;
        }

 

Share this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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 this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!