Sign in to follow this  

Practical help on making a simple bullet hell

This topic is 1508 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

Hi gamedev, 

I have been bored on the programming lessons recently, so

i decided to make a bullet hell in c++ with sdl2.

 

The problem is, I don't know how to structure the code

so that it would work properly. Problems such as how to

control the bullets, how to spawn a enemy at the right time

needs to be solved.

Here is what i have come up with so far (psudoish);

class player
{

    SDL_Texture * P_Texture; 
    SDL_Texture * Col_texture;
    
    double mx; //x,y movement
    double my; 
    
    SDL_Rect P_pos; 
    
    int hp;
    int power;
    int points;


    void loop(double delta_time);

    void render(SDL_Renderer * renderer);
    
};


class Enemy
{
    int type;
    SDL_Texture * texture;
  
    int helth;

    SDL_Rect pos;
    SDL_Rect col;
    
    
    void loop();
    
    void render(SDL_Renderer * renderer);
    
};


struct Bullet       
{
    int type;
    
    SDL_Texture * texture;
    float rotation;
    
    int helth;
    
    SDL_Rect pos;
    SDL_Rect col;
    
  
    void render(SDL_Renderer * renderer);
    
    void loop(double delta_time);
};

class game
{
    player Player;
      
    std::vector<Enemy> enemies;
    std::vector<Bullet> bullets;

  
    void even(SDL_Event * event)
    {
        // Handle events and
        //  Pass on events to underlaying code   
    }

    void render(SDL_Renderer * renderer)
    {
        //Render 
    }
    
    void loop()
    {
        /*
         Update positions

         Handle collisions
         */
    } 
};

So where do I go from here? I would like to be able to control the bullets

using different equations and spawn allot of them. The game doesn't have

to be advanced at all just spawn a bunch of enemies and bullets flying

in different directions.

 

 

Thanks for any help and sorry for my bad English smile.png
 

Share this post


Link to post
Share on other sites

You'll probably want to make a 'schedule' file for each stage, which the program will load and then proceed through in order to play the stage events at their correct times. For instance, a stage file can start with information about what music to play, what the background is, what enemies are present (so you can start caching resources), etc. You load that information from the file, then start a timer. The rest of the file will have simple commands (at the 30 second mark, spawn enemy type E at position X,Y - or things like that). Make sure those are all in chronological order, then as the stage plays it can just check to see if it's reached the time of the next command, and if so it executes it and moves to the next one.

 

As for 'controlling' bullets and such, that's usually simple deterministic AI. Just make an abstract Bullet class and then derive each bullet type from that. give each bullet type its own logic, and update each of them every frame.

Share this post


Link to post
Share on other sites

Thank you. Ultra late reply, but i have been working on the game ever since you replied.

The command idea worked well, the only problem is that ifstream whont work on xcode sad.png
So i cant load the commands from a file, instead i store them in a string :
 

    std::string   line =
    "Begin 10 2 100 0 5 5"
    "N 70 2 700 0 5 5"
    "N 120 2 100 0 5 5"
    "N 130 3 200 0 2 50"
    "N 130 3 550 0 2 50"
    "Cos(v) 140 100 550 0 5 4"
    "N 190 100 550 0 5 4"
    "N 250 3 200 0 1 0"
    "N 250 3 550 0 1 0"
    "v=t 260 101 550 0 60 1"
    "N 300 3 500 0 1 0"
    "N 300 3 350 0 1 0"
    "N 300 3 150 0 1 0"
    "sin(y) 330 102 550 0 40 1"
    .....;

The Polymorfism also worked great for the first time i understand how abstract classes

and pointers work together.

 

Her is a samall gif of the game:

 

 9eb970806b184ae808fc08a640ad449d.gif

Share this post


Link to post
Share on other sites

This topic is 1508 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this