how to organize my game objects in game world

2f5a63c282518b88f1732bdca3b6acc4
0
zydgyy 101 Oct 24, 2011 at 07:24

Hi,guys!
I read about,in my game loop,
while(true)
{
//update states of game objects in the game world
gameworld.update(dt);
physicsEngine.update(dt);
animationEngine.update(dt);
redner();
}
So,how do i organize the game objects in the game world?what kind of data structures should i use to update them quickly?Any suggestions?

2 Replies

Please log in or register to post a reply.

A638aa42130293f319eda7fa4ba121f4
0
fireside 141 Oct 24, 2011 at 10:29

It might be easiest to build a small prototype. Usually the game entity is the smallest object. A world is comprised of entities in a specific situation. The physics engine updates the entities motion.
Also, you can look at some open source engines around and see how they are organized. FlashPunk is a pretty cool little open source engine written in AS3, or find some tutorials on the net.
Mostly just build some small games. It’s just a way of organizing a game loop.

Efb71189a6020a633f1715a6fcdc46cc
0
robobrain 101 Nov 01, 2011 at 15:52

Most of the game engine’s I’ve worked on have a base Entity class that all of the game objects derive from. And usually it looks something like this:

class Entity {
    public: 
    void update();
    void onCollision(Entity e);
    ...
}

that way when you are looping through all of your game objects, you can just call update() and do whatever physics, ai, rendering, etc. you need. Do your collision reactions in onCollision, etc. Just think about what operations you need to do on all of your entities and make sure there is a function for it in the base class.