[SOLVED]Engine question
Moderator: PC Supremacists
-
- Chaos Rift Regular
- Posts: 101
- Joined: Thu Dec 09, 2010 2:13 am
[SOLVED]Engine question
Hey, I have a game engine started and it's come along pretty far. They only issue I have is implementing a kind of global entity list for drawing and collision, and I was wanting to get some suggestions on how you guys handle the drawing and collision of all the entities or objects in your engines/games. Any help would be great, thanks!
Last edited by like80ninjas on Fri Dec 17, 2010 4:07 am, edited 1 time in total.
- adikid89
- Chaos Rift Cool Newbie
- Posts: 94
- Joined: Tue Apr 27, 2010 6:59 am
- Current Project: small tiny-mini projects
- Favorite Gaming Platforms: PC I guess...
- Programming Language of Choice: c++
Re: Engine question
Code: Select all
//EntityManager::Draw() .. or something similar
for(int i=0; i<entities.size();i++) {
entities[i]->Draw();
}
So the bodies interact in a world, they collide, change pos accordingly etc, and all you do in the Entity class is update the pos of where you'll draw the sprite to match that of the body.
My first game C++/SDL Yoshi Combat! = http://www.youtube.com/watch?v=HQ9mMBEWSZg
==============================================================
==============================================================
- GroundUpEngine
- Chaos Rift Devotee
- Posts: 835
- Joined: Sun Nov 08, 2009 2:01 pm
- Current Project: mixture
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++
- Location: UK
Re: Engine question
Agreed with above
I personally use Managers too... but its similar to this. Heres an aproach that is more simple than say.. a Entity manager (excuse the messy code)
But to turn this into a Manager class, the Manager class would handle the 'stack' and 'All()' style functions... Entity class would just handle the core functions. Making the Manager style easier and cleaner code
I personally use Managers too... but its similar to this. Heres an aproach that is more simple than say.. a Entity manager (excuse the messy code)
But to turn this into a Manager class, the Manager class would handle the 'stack' and 'All()' style functions... Entity class would just handle the core functions. Making the Manager style easier and cleaner code
Code: Select all
#include <iostream>
using namespace std;
#include <vector>
class Entity
{
public:
static vector<Entity*> Entitys; // Shared stack of Entity's
Entity()
{
Entitys.push_back(this); // Now on the Entitys stack...
}
~Entity()
{
}
void Update()
{
// Check collision for this Entity
cout << "Updating" << endl;
}
void Draw()
{
// Draw this Entity
cout << "Drawing" << endl;
}
static void UpdateAll()
{
for(vector<Entity*>::iterator iter = Entitys.begin(); iter != Entitys.end(); iter++)
(*iter)->Update();
}
static void DrawAll()
{
for(vector<Entity*>::iterator iter = Entitys.begin(); iter != Entitys.end(); iter++)
(*iter)->Draw();
}
};
vector<Entity*> Entity::Entitys;
int main()
{
Entity bob; // Now on the Entitys stack...
while(true) // Game loop
{
// Think
// Update
Entity::UpdateAll();
// Render
Entity::DrawAll();
}
cin.get();
return 0;
}
-
- Chaos Rift Regular
- Posts: 101
- Joined: Thu Dec 09, 2010 2:13 am
Re: Engine question
Hey, thanks for the reply guys. I don't want to use box2d or anything like that, my collision code is written from scratch and works very well, however, you did answer my question on how to manage my entities. I like the idea of the static functions more than the extra class, I think i'll try implementing that.
- GroundUpEngine
- Chaos Rift Devotee
- Posts: 835
- Joined: Sun Nov 08, 2009 2:01 pm
- Current Project: mixture
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++
- Location: UK
Re: Engine question
Sweet, let us know if it works oklike80ninjas wrote:Hey, thanks for the reply guys. I don't want to use box2d or anything like that, my collision code is written from scratch and works very well, however, you did answer my question on how to manage my entities. I like the idea of the static functions more than the extra class, I think i'll try implementing that.
-
- Chaos Rift Regular
- Posts: 101
- Joined: Thu Dec 09, 2010 2:13 am
Re: Engine question
Yeah the method groundupengine gave me was flawless. It works very well for my uses, thanks!
- GroundUpEngine
- Chaos Rift Devotee
- Posts: 835
- Joined: Sun Nov 08, 2009 2:01 pm
- Current Project: mixture
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++
- Location: UK