[SOLVED]Engine question

Anything related in any way to game development as a whole is welcome here. Tell us about your game, grace us with your project, show us your new YouTube video, etc.

Moderator: PC Supremacists

Post Reply
like80ninjas
Chaos Rift Regular
Chaos Rift Regular
Posts: 101
Joined: Thu Dec 09, 2010 2:13 am

[SOLVED]Engine question

Post by like80ninjas »

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.
User avatar
adikid89
Chaos Rift Cool Newbie
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

Post by adikid89 »

Code: Select all

//EntityManager::Draw() .. or something similar
for(int i=0; i<entities.size();i++) {
  entities[i]->Draw();
}
For the collision... I'd recommend separating sprites from bodies(which will interact in the physics world). Look into a physics engine like box2d or something similar. I find that it's a great way to implement collision testing and physics in general.
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
==============================================================
Image
User avatar
GroundUpEngine
Chaos Rift Devotee
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

Post by GroundUpEngine »

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 ;)

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;
}
like80ninjas
Chaos Rift Regular
Chaos Rift Regular
Posts: 101
Joined: Thu Dec 09, 2010 2:13 am

Re: Engine question

Post by like80ninjas »

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.
User avatar
GroundUpEngine
Chaos Rift Devotee
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

Post by GroundUpEngine »

like80ninjas 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.
Sweet, let us know if it works ok 8-)
like80ninjas
Chaos Rift Regular
Chaos Rift Regular
Posts: 101
Joined: Thu Dec 09, 2010 2:13 am

Re: Engine question

Post by like80ninjas »

Yeah the method groundupengine gave me was flawless. It works very well for my uses, thanks!
User avatar
GroundUpEngine
Chaos Rift Devotee
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

Post by GroundUpEngine »

Awesome!
+1 to e-peen 8-)
Post Reply