Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6993621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:47:16+00:00 2026-05-27T19:47:16+00:00

I’m working on a prototype for a shmup game in C++ using SDL…Right now

  • 0

I’m working on a prototype for a shmup game in C++ using SDL…Right now I’m just trying to get the basics working without using classes. Now, I have it so it shoots multiple bullets, but it behaves strangely which I believe is because of the way the counter is reset…The bullets will appear and disappear, and some will keep blinking in the original spot they were shot at, and there will sometimes be a delay before any can be shot again even if the limit isn’t on the screen…And sometimes the player character will suddenly jump way to the right and only be able to move up and down. How do I fix this so it smoothly shoots? I’ve included all relevent code…

[edit] Please note that I intend on cleaning it up and moving it all to a class once I get this figured out…This is just a simple prototype so I can have the basics of the game programmed in.

[edit2] ePos is the enemy position, and pPos is the player position.

//global
SDL_Surface *bullet[10] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
bool shot[10];
int shotCount = 0;
SDL_Rect bPos[10];

//event handler
case SDLK_z: printf("SHOT!"); shot[shotCount] = true; ++shotCount; break; 

//main function
for(int i = 0; i <= 9; i++)
{
    shot[i] = false;  
    bullet[i] = IMG_Load("bullet.png");
}

//game loop
for(int i = 0; i <= shotCount; i++)
{    
    if(shot[i] == false)
    {
        bPos[i].x = pPos.x;
        bPos[i].y = pPos.y; 
    }
    if(shot[i] == true)
    { 
        bPos[i].y -= 8;
        SDL_BlitSurface(bullet[i], NULL, screen, &bPos[i]);

        if( (bPos[i].y + 16 == ePos.y + 16) || (bPos[i].x + 16 == ePos.x + 16) )
        {
            shot[i] = false;
        }
        else if(bPos[i].y == 0)
        {
            shot[i] = false;
        }
    }
}

if(shotCount >= 9) { shotCount = 0; }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:47:17+00:00Added an answer on May 27, 2026 at 7:47 pm

    Here is something like I was suggesting in the comment. It was just written off the top of my head but it gives you a general idea of what I’m talking about..

    class GameObject
    {
        public:
            int x;
            int y;
            int width;
            int height;
            int direction;
            int speed;
    
        GameObject()
        {
            x = 0;
            y = 0;
            width = 0;
            height = 0;
            direction = 0;
            speed = 0;
        }
    
        void update()
        {
            // Change the location of the object.
        }
    
        bool collidesWidth(GameObject *o)
        {
            // Test if the bullet collides with Enemy.
            // If it does, make it invisible and return true
        }
    }
    
    GameObject bullet[10];
    GameObject enemy[5];
    
    while(true)
    {
        for(int x=0; x<=10;x++)
        {
            bullet[x].update();
            for(int y=0;y<=5;y++)
            {
                if(bullet[x].collidesWith(&enemy[y])
                {
                    // Make explosion, etc, etc.
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.