Jump to content

  • Log In with Google      Sign In   
  • Create Account

Gabriel Grom

Member Since 24 Aug 2012
Offline Last Active Sep 02 2012 08:40 AM

Posts I've Made

In Topic: Making Screen follow the player?

28 August 2012 - 09:54 AM

One thing I've used (with Swing/AWT) to handling level scrolling is Graphics.translate: http://docs.oracle.c...l#translate(int, int).

The rest is just arithmetic (calculating a centered position) and handling level boundaries.


Yeah, this seems a lot simpler than translating every object you create, which might have an impact on performance.

What you do is just translate the graphics so that the rendering is done with the player in the middle.

Almost every 2D library has a translate function for graphics or a camera class which you can use.

In Topic: Composition heavy OOP vs pure entity component systems?

24 August 2012 - 02:36 PM


I would like to say this is a great topic so far, with lots and lots of info contained and a lot of opinions. I was wondering if this is a good example of what would be a good entity architecture so that I see if I should go ahead with it or not: http://obviam.net/in...ategies-part-1/
http://obviam.net/in...-state-pattern/


Gabriel, that's kind of the beginning of the idea of Composition, but it's only partial IMO. It limits some because, what if you have a droid that you can ride on? Is it a droid? or a vehicle?

Using a true entity/component system, it can be both easily. Instead of having a is-a droid relation ship, and it would go into the droid list, you have a generic entity, built with a graphics component, physics component, droid component, and weapon component.

Then you have systems that act on these components. ie, the droid system handle entities with the droid component, and it handles the AI and movement (depending if droid component was built with wheels or track, or nothing), as well as attempting to shoot it's weapon.

If you add a vehicle component, then the vehicle system can work on that entity, and allows a player to ride on the droid, and shoot from the back of the droid.

That's the general idea. My dev journal has some articles about it, and there's plenty of other data too.


Hey BeerNutts!

You make a good point. I might be missing the actual point though, but wouldn't just adding a Riding component solve the problem?

The reason why I feel the need to have predefined entities, and also to have tightly coupled components, such as for example the texture and rendering component, or the collision and movement component, like some people here mentioned is because of the two concepts I'm having trouble with, which are the layering of the game that Hodgman and Ryuu talked about, as well as inter component communication.

Also I'm having trouble with how I will differentiate between entities, such as player and AI or vehicle and person.

Things like updating the components also come to mind. Should I make a system for each type of component that updates the components of the same type, in which case should l iterate the types in order? For example iterate over the physics components and update them first, after which I iterate over the rendering components?

What I mean by that, and most of the above is, let's say that there is a vehicle or droid which players can ride. How will I be able to differentiate the players from the other vehicle components such as the collision component? If things are made as generic as you say, and perhaps here I misunderstood you, in that I understood you said that we should make the entities only have a reference to the generic Component class, rather than manually hardcode that a vehicle will have armor, characters, wheels so as to gain maximum flexibility.

If it is hardcoded, then the vehicle will be able to directly manage the characters' updates. What I have in mind is, that when a character is added to a vehicle, the player's control, or that of the AI is stripped, and given to the vehicle, which in turn has a controller, player or AI. I would have addCharacter() method in the vehicle entity or in the Riding component which will do what I just described.

If however, the vehicle only knows generic components, and vehicle is generic in its self, then how will I be able to know that the component being added is a character, and how will I know that the vehicle has a Riding component? Don't get me wrong, I'm not asking how to do those things, but the solution I am imagining in my head entails a lot of boilerplate and messy code, which is essentially a massive Component class to accommodate for every possible action or scenario in the game.

public void addComponent(Component Receiving, Component Attaching)
{
......
	if(Receiving.has(RidingComponent)
	   if(Attaching.is(CharacterComponent)
		   RidingComponent.addComponent(Attaching, type CharacterComponenet);
.........
}

And that's just a small snippet of the method, where other lines would test for rendering, collision, animation, etc...

My opinion is that for small-medium sized games, something akin to say.. the size of Warcraft 2 or Red Alert like game, over-engineering by going completely generic and flexible at the cost of code complexity does not really pay off.

Then again I've never done a component system before.

In Topic: Composition heavy OOP vs pure entity component systems?

24 August 2012 - 11:42 AM

I would like to say this is a great topic so far, with lots and lots of info contained and a lot of opinions. I was wondering if this is a good example of what would be a good entity architecture so that I see if I should go ahead with it or not: http://obviam.net/index.php/design-in-game-entities-object-composition-strategies-part-1/
http://obviam.net/index.php/design-in-game-entities-object-composition-strategies-part-2-the-state-pattern/

PARTNERS