SDL with a Physics engine

Hey guys,
Recently I learned the basics of SDL (surfaces, video mode, events...) and I wanted to put SDL with a physics engine in order to make a simple platformer.
I was thinking of using Box2D or whatever you recommend. My main question is how I would go about putting the two together in order to just make, for example : An image falling and hitting a ground.
If you have an answer or links, your help would be greatly apreciated.

mindoo
An image falling and hitting a ground.
This is a wrong approach. Image should not fall. There should be an abstract object which will fall/move/etc. and its movement should be calculated by physics engine. Graphic engine should take those objects and draw their representation on screen.
Hi,
What I mean by an image falling and hitting a ground is what we will see. It would be a surface that has an image loaded onto it. That's how I thought it would work...
Tell me what you think...
Object itself should not know that it is drawn on screen. Roughtly you should have an object which represents an entity in the world (with coords, bounding box, physics calcultion an all that) and object which represents drawable entity (stores image sprite, reference to represented object to get some needed info and other graphics related stuff).
I don't understand everything that you are talking about. Would you mind to just provide a piece of code that does what I described previously. It would be the simplest approach to help me and then you could explain what is what.
thanks,

mindoo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
struct GameObject //Intended to be base class for game entities
{
    int x, y; //coords
};

std:vector<GameObject*> objects; //Contains pointers to all game objects. 
//Each tick you will go over all objects and udate their state. (moving, etc.)

struct ScreenRepresentation
{
    Sprite sprite; //what is drawn on screen
    GameObject& entity; // What we draw

    //.. constructors, etc
};

std:vector<ScreenRepresentation*> sprites; //Contains all stuff which is drawn on screen.
//Each frame you will go over vector and draw stuff contained in it.

void draw(ScreenRepresentation& drawable)
{
    draw(drawable.sprite, drawable.entity.x, drawable.entity.y); //Translates to the call to graphic library draw function
}
I'm still confused, what part is SDL and what part is Box2D ?
Sorry if I have a hard time understanding.
GameObject and objects vector are part of the game itself. It interacts with Box2D, but do not know anything about how it is represented on screen (if it is represented at all), so it does not know anything about SDL.

ScreenRepresentation (and sprites vector) contains information about what and how something should be drawn. It heavily relies on SDL, but never encounters box2D (as it does not do any physics calculations, it is completely separate part of the code)

Topic archived. No new replies allowed.