Slick Forums

Discuss the Slick 2D Library
It is currently Mon May 20, 2013 2:31 pm

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Fri Aug 10, 2012 2:36 pm 
Offline

Joined: Sat Jun 02, 2012 7:41 am
Posts: 67
I was wondering, is it possible to obtain an ImmutableBag of entites by specifying a component (or some components) the entities should have? I tried implementing a method by myself because I didn't find anything. It would be pretty useful to me. E.g., let's say I have a crate (on which you can walk) that contains some bonuses. I should check for collisions both in the CollisionSystem (which simply stops the player on the crate, like a floor) and in the BonusCollisionSystem, because the crate contains bonuses. So I'd make 2 components, one called Walkable (which has some fields such as solidity and will be applied to every floor-like entity) and another called BonusContainer (which contains infos about the amount of score the entity contains, and so on, and so will be applied to every bonus-like entity), and I'd look for entities which has that kind of components in the corresponding system. I don't know if there's some other way to do this, expecially because an entity can only be assigned to one group.


Top
 Profile  
 
PostPosted: Fri Aug 10, 2012 3:56 pm 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
Alessandro wrote:
I was wondering, is it possible to obtain an ImmutableBag of entites by specifying a component (or some components) the entities should have?

Actually, that's exactly what a system does, it "obtains an immutablebag of entities by specifying a component or components the entities should have", and that is the bag of entities each system processes.

Alessandro wrote:
I tried implementing a method by myself because I didn't find anything. It would be pretty useful to me. E.g., let's say I have a crate (on which you can walk) that contains some bonuses. I should check for collisions both in the CollisionSystem (which simply stops the player on the crate, like a floor) and in the BonusCollisionSystem, because the crate contains bonuses. So I'd make 2 components, one called Walkable (which has some fields such as solidity and will be applied to every floor-like entity) and another called BonusContainer (which contains infos about the amount of score the entity contains, and so on, and so will be applied to every bonus-like entity), and I'd look for entities which has that kind of components in the corresponding system. I don't know if there's some other way to do this, expecially because an entity can only be assigned to one group.


So, you have component Walkable that indicates a player can walk on that box, and a BonusContainer component that stores information about the bonus given to the player that walks on that box. Simple enough.
If collision occurs between player and a Walkable box, then in the handling of that collision you can check if the box entity also has a BonusContainer component, and if so then add the defined bonus to the player. I think that's the easiest design than trying to have multiple collision systems.


Regarding GroupManager, if GroupManager doesn't cut it, you can easily add your own manager to the world instance, e.g. world.setManager(new MyMultiGroupManager());
Or any other manager you wish to create.


You can explain better your situation for a better answer.


Top
 Profile  
 
PostPosted: Fri Aug 10, 2012 5:44 pm 
Offline

Joined: Sat Jun 02, 2012 7:41 am
Posts: 67
Ok, but what if in the system I also want to select a list of entities with the gravity component (the player and maybe some of the enemies, but not all of them)? I can make the System select the walkable entities, but then what do I do to select alla the entities with the gravity component in that system?


Top
 Profile  
 
PostPosted: Fri Aug 10, 2012 6:14 pm 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
Alessandro wrote:
Ok, but what if in the system I also want to select a list of entities with the gravity component (the player and maybe some of the enemies, but not all of them)? I can make the System select the walkable entities, but then what do I do to select alla the entities with the gravity component in that system?


You can use grouping to get list of entities that belong to certain groups.


A system processes a single aspect of entities in your world. An aspect comprises of a single component or a certain combination of components. You should not select different aspects inside a system, because the system is already processing its aspect.

Code:
System(Walkable.class, Gravity.class) // processes all walkables entities with gravity
System(Walkable.class) // processes all walkable entities


Consider a entity with Position.class and Movement.class.
Position is an aspect, and you can define a system that processes that aspect to ensure no entity goes off bounds in your game world.
Position+Movement is a different aspect, where movement contains the trajectory vectors in which direction the entity is moving, so a system processing that aspect would move the entity according to it.
Then Movement could be a different aspect, where you'd have a system making sure no entity exceeds maximum velocity.
Then you could create another system processing Position+Movement, to make sure entities are slowed down in certain areas of the map, or receive a speed boost.

You can define almost endless systems processing the same components but with different purpose.


Quote:
A good rule of thumb when deciding on a new system is to think in terms of what "it can do". E.g. a system can move entities around, a system can damage entities, a system can spawn new entities, a system can play audio.

http://gamadu.com/artemis/

So, "Walkable" has information about walking speed and such, and "Gravity" information about how much weight or gravity the character has? Entity system paradigm has a close relation to RDBMS, so would you create a database table called "Walkable" and "Gravity"? If your terms as not well defined it may be difficult to define systems for them.

What could you do with a Walkable+Gravity aspect? Why is there no Physics? Or Velocity? Or Walker component?

Try to think of components as pure data, not as abilities. Abilities are given to entities by the systems that process them.


Top
 Profile  
 
PostPosted: Fri Aug 10, 2012 6:44 pm 
Offline

Joined: Sat Jun 02, 2012 7:41 am
Posts: 67
I probably didn't express myself well (my fault, english is not my mother tongue, sorry :( ), by saying "walkable" I mean "something you can walk on" (I was trying to give a translation from italian of a word which actually doesn't exists, so it was quite a problem xD), like a floor. Let's call it Floor then. Every Entity that has a Floor component behave like a floor, even if it is a bonus (like a box), so you can simply walk on it. The problem is: I want the system (that processes the entities with Floor component) to check for collisions with other kind of entities that have a Gravity component (I already have systems that updates gravity, speed and position), and stop them if they fall on the entity with Floor object. What should I do is get all the entities in the world that have that Gravity component (they can belong to different groups maybe)? If the system processes the aspect of "entities being floor", how can I also obtain a list of entities that have the Gravity component (and so "entities that can fall") to check for collisions?


Top
 Profile  
 
PostPosted: Fri Aug 10, 2012 7:34 pm 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
It is difficult to understand why you've modeled your game like this, so it's difficult to give answers.

Most would make a physics system with collision checks, so that when a player entity collides with a "bonus box" entity then that collision will be handled accordingly.


Top
 Profile  
 
PostPosted: Sat Aug 11, 2012 1:15 am 
Offline

Joined: Sat Jun 02, 2012 7:41 am
Posts: 67
I'll try to explain better. First of all, it is a platformer, just to let you understand better. Now, I have these components:

- Floor -> indicates that entities falling upon this entity will stop on top of it (they behave like a floor, nothing more)
- Gravity -> indicates that this entity can fall down

What the system should do is only stop the entities with the Gravity component on top of the entities with the Floor component. Only this.
But, not only "real floor" (terrain) entities have the Floor component: also bonus boxes have it, they are solid and they COMPLETELY behave like a floor until the player breaks them to obtain the bonus (and I'd manage this in another system). And maybe also other entities in the world would behave like floors, even though they are not proper floors. I can't make a group "floors", because bonus boxes would also belong to the "bonus" group, and it would be a mess...
And, also, not only the player has gravity: there are also some enemies that have gravity. So I can't make a group "gravity entities", because some of them would also belong to the "enemies" group, and so on... It would be dificult to use groups, because a single entity would belong to 2, 3, 4 groups maybe...
So I thought that the easiest way to handle this was to get a list of ALL entities that have the Gravity component (player, enemies... all of them), then a list of ALL the enetites that have a Floor component (proper floors, solid bonus boxes, etc...), and then check for collisions. Nothing changes if the entity is a player or an enemy, it just have to stop on top of the floor/box/whatever. So there should be only one system for all of them, right?
What's the problem? I could make a system like:
Code:
System(Gravity.class);

which will obtain all the entites with the Gravity component. That's ok, but now how can I get the list of all the entities with the Floor component (so that I can check for collisions with ALL of that entities, not only floors, or only boxes, but all of them)? And if I make a system like:
Code:
System(Floor.class);

how can I get a list of ALL the entities with a Gravity component to check for collisions?
Of course I'd want to check for this kind of collision only the entities that have the Gravity component because it doesn't make sense to perform the check on an entity that doesn't have that component, it just wouldn't fall down... The same for the Floor component. So, what could be a way of handling this kind of collision?


Top
 Profile  
 
PostPosted: Sat Aug 11, 2012 3:19 am 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
I'm not quite sure why you're doing this like this.

If it's a platformer, like super mario bros, then why don't you look into using physics systems, like Fizzy.

Tankz uses phys2d:
http://code.google.com/p/gamadu-tankz/s ... ystem.java


Top
 Profile  
 
PostPosted: Sat Aug 11, 2012 8:48 am 
Offline

Joined: Sat Jun 02, 2012 7:41 am
Posts: 67
Mmmh, maybe you're right, I'd look into fizzy then. Thanks :) and sorry for wasting your time...


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group