Sign in to follow this  
nullsquared

My new cApp, but how can I store images???

Recommended Posts

nullsquared    126
Ok, so I made a class cApp to handle input, events, initialization, deinitialization, and handling the screen including refreshing it and fliping it. I also made a class cApp_Sprite which can load an image, set a color key, set the x/y coordinates, and draw itself to the screen. For now I use GetVideoSurface() for it since m_Screen is private in cApp. My question: how do you suggest that I store all my cApp_Sprite's in my cApp dynamically? I mean removing them, adding them, etc. Now you can do something like this:
#include <SDL.h>

#include "cApp.h"
#include "cApp_Sprite.h"

#include <ctime>
#include <cstdlib>

int main(int argc, char *argv[])
{
    cApp theApp;

    srand(time(NULL));

    theApp.Init(SDL_INIT_VIDEO);
    theApp.InitWindow(350, 600, SDL_DOUBLEBUF | SDL_HWSURFACE);

    cApp_Sprite sprite1;

    sprite1.SetSprite("box.bmp");
    sprite1.SetColorKey(7, 7, 7);
    sprite1.Setxy(76, 54);

    while(true)
    {
        if (theApp.EventOn())
        {
            if (theApp.GetEvent().type == SDL_QUIT)
                break;
        }

        theApp.RefreshScreen((rand() % 0xFFFFFFFF) - (rand() % 0xabcdef12));

        theApp.UpdateKeys();
        if (theApp.GetKeys()[SDLK_ESCAPE])
        {
            break;
        }

        sprite1.Draw(SDL_GetVideoSurface());

        theApp.FlipScreen();
    }

    theApp.DeInit();

    return 0;
}

That code is pretty much self explanatory. But I would like something like this:
theApp.AddImage("box.bmp"); // this is not implamented because I dont know how

How would I go about doing something like this? Dynamically? Here is cApp:
#ifndef C_APP_H
#define C_APP_H

#include <SDL.h>

#include <vector>
#include <string>

#include "cApp_Input.h"
#include "cApp_Event.h"
#include "cApp_Sprite.h"

class cApp: public cApp_Event, public cApp_Input
{
    private:
        std::vector<std::string> m_Errors;

        SDL_Surface *m_Screen;

    public:
        cApp();
        ~cApp();

        bool Init(unsigned int flags);
        bool InitWindow(int w, int h, unsigned int flags);
        bool DeInit();

        void PrintErrors();

        void RefreshScreen(int color = 0x00000000);
        void FlipScreen();
};

#endif /* C_APP_H */

Thanks to all. P.S. I forgot something: Compiler: MingW IDE: Code::Blocks API: SDL Language: C++

Share this post


Link to post
Share on other sites
EmperiorRune    138
Generally.. when you load a image, you have it located in the project directory, the one where your main.cpp is located.

There are some more sophisticated ways to store your files, for example, you could make a .rc, and hold your files internally. (Inside of the exe) Or you could make some sort of packfile system, and compress all your game files into a seperate file.

If you are adding a image for a sprite we sorta need to know what the sprite has in it. If it's a bunch of frames for a sprite then you'll need to clip the render of the sprite to create the illusion of a animation.

In any case, something like 'theApp.AddImage("box.bmp");' sounds a little out of place. I'd have a sprite object, and then a spritelist object that manages them on the screen. Really more of a how complicated you want it to be thing :P

Share this post


Link to post
Share on other sites

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