Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (778)
Games in Android Showcase (231)
games submitted by our members
Games in WIP (856)
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 6098 times)
0 Members and 1 Guest are viewing this topic.
Offline RongoMatane

Junior Newbie

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

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:

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.

Lethal Running - a RPG about a deadly game show held in a futuristic dystopian society.
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

JGO Kernel

Medals: 518

« 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

JGO Kernel

Medals: 518

« 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  

hadezbladez (362 views)
2018-11-16 13:46:03

hadezbladez (194 views)
2018-11-16 13:41:33

hadezbladez (363 views)
2018-11-16 13:35:35

hadezbladez (91 views)
2018-11-16 13:32:03

EgonOlsen (2193 views)
2018-06-10 19:43:48

EgonOlsen (2229 views)
2018-06-10 19:43:44

EgonOlsen (1386 views)
2018-06-10 19:43:20

DesertCoockie (2024 views)
2018-05-13 18:23:11

nelsongames (1677 views)
2018-04-24 18:15:36

nelsongames (2313 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46 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‑
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!