Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (516)
Games in Android Showcase (123)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Entities - Class Design  (Read 3264 times)
0 Members and 1 Guest are viewing this topic.
Offline RongoMatane

Junior Newbie





« Posted 2012-03-24 09:50:37 »

Hi,
i'm currently working on an isometric, tilebased survival game. The landscape is 3D, the objects are pixelart 2D. I can post Screenshots later in this thread, if anyone is curious Wink
My problem atm is, that i'm unhappy of how i implemented entities. My world consists of chunks, 64x64 tiles. Each chunk handles everything on it, for example drawing and updating animals. There are some different kind of entities: some are purely decorative (grass), some are static (a tree) and some are dynamic (an animal). On top of that, some may be animated and most of them have to be pickable (which i use colorpicking for). This classification into 3 parts made the most sense for me: Decoentities won't be permanent or usable in any way, static entities are usable and stay where they are (like a tree) and dynamic entities will move around by themselves, so they have to check if they left their original chunk.
Currently i use inheritance. Here is a generated classdiagram:

http://imagebin.org/204944

I didn't catch the animation aspect with that because there would be too many constellations, it just feels wrong and too complicated. Does anyone know a solution to code this nicely? Is there a nice way to implement such "features" like pickable or animatable?
Should i simplify some aspects, for example just make everything in principle animatable and dynamic (the player will be able to move small static entities around, so they have to answer "did i leave my chunk" too).
I would be very thankful for some advice Smiley
Offline 65K
« Reply #1 - Posted 2012-03-24 10:37:35 »

Some quick thoughts:
StaticEntity seems just like a DynamicEntity with unchanged position. No class for it.
Pickable sounds rather like a simple property or an interface some entities may implement. No class either.
Animation is rather a presentation/view issue. No entity class, but maybe a view/renderer class used as composite object.

Offline sproingie

JGO Kernel


Medals: 202



« Reply #2 - Posted 2012-03-24 17:29:10 »

There's a lot you can factor out of an entity that's truly static and undifferentiated, like a tree or a wall or a rock, to the point where they're not really "entities" at all, being undifferentiated except for their location.  A tree is a tree, maybe you might render one differently than another, but otherwise speaking, it doesn't really have any state.  

So you might just encode these simple "pseudo-entities" as a bit or two in a map layer, and only create entities on the fly when you request one from the map.  This is called a Flyweight pattern, and it's really useful for entities that don't have any state.  Stuff that does have state, such as players and monsters, you don't use flyweights for.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline RongoMatane

Junior Newbie





« Reply #3 - Posted 2012-03-25 09:06:16 »

Thanks for the input Smiley

I've teared down and built up the whole thing. Now i just have a class Entity which will be used for (usable) trees and stones and so on. Then i have an abstract class Animal that inherits from Entity and finally things like Bird, Rabbit or Player that inherit from Animal.
I thought that it doesn't hurt too much to make every entity animatable and pickable.
For the rest, there ist still Decoentity which covers everything with no function or use. I'll implement it just like sproingie suggested, no reason to keep little grassbushes permanent.
Offline Roquen
« Reply #4 - Posted 2012-03-25 10:18:18 »

Note, there's no need to have separate classes for each of these thinker (Animal) types as they only vary by data.  However if the total number is pretty small, then don't worry about it.
Offline RongoMatane

Junior Newbie





« Reply #5 - Posted 2012-03-25 11:00:19 »

Thank you for the hint.
They have different behaviours and different abilities. For example a rabbit can stand up and look around, a bird can't (atm). They have a "currentAction" what can be walk around, eat, look around and so on, and different probabilities for transitions from one state into another. It's really a good idea to generalize this for all animals, it didn't feel to good working with it already because i couldn't really seperate what belongs to all animals and what is special. Thank you Smiley
Offline Roquen
« Reply #6 - Posted 2012-03-25 11:51:30 »

The idea here is to use some method of  "composition instead of inheritance" to build behavior. 
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (33 views)
2014-10-27 03:28:38

TehJavaDev (26 views)
2014-10-27 03:27:51

DarkCart (41 views)
2014-10-26 19:37:11

Luminem (22 views)
2014-10-26 10:17:50

Luminem (27 views)
2014-10-26 10:14:04

theagentd (33 views)
2014-10-25 15:46:29

Longarmx (61 views)
2014-10-17 03:59:02

Norakomi (58 views)
2014-10-16 15:22:06

Norakomi (47 views)
2014-10-16 15:20:20

lcass (43 views)
2014-10-15 16:18:58
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!