Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (686)
Games in Android Showcase (198)
games submitted by our members
Games in WIP (758)
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  
  Effect Architecture  (Read 1144 times)
0 Members and 1 Guest are viewing this topic.
Offline penguin_buddha

Senior Newbie

« Posted 2013-08-23 15:11:39 »

I've been working on a roguelike game for a few months now and I've gotten to the hardest part yet, effects! I'm talking about everything from an effect that represents fire by continuously damaging an object to an effect that summons a creature, to an effect that modifies the stats of an object. So obviously there are a lot of potential effects. The question is how to go about implementing effects in an object oriented manner.

My current approach is to have an Effect class that is really broad. It contains multiple hashmaps that can contain game objects, simple values, locations, and other effects. Most instances of the class won't utilize all of these hashmaps. Each effect also has a list of types. These define how the game interprets the effect.

Examples Types: damage, healing, armorModifier, summon, etc.

For example, when an agent suffers damage the game will look for effects on that agent of the type "armorModifier". If an effect with that type exists on the agent, the game knows there should be a key/value pair in one of the hashmaps that tells how much armor should be added/subtracted. This would be for a passive effect, however many effects are active. Such effects have an activate() method that is called. The Effect class then acts based on the types of the effect. So if its a damage effect it will look for a key/value pair for how much damage, what targets to damage, what damage type it is and so on.

So if it wasn't complex enough for you already, there are also effects that really only modify other effects. For example, the activateOverTime type of effect just activates another effect at a certain frequency. The onHit type of effect applies a new effect to whatever an Agent attacks.

Here are some examples of effects and what types they would have:

  • Fireball: damage, aoeBurst
  • Vampirism: damage, healing
  • Alien Parasite: damage, activateOverTime, onTargetDeath (would create the Summon Parasite effect)
  • Summon Parasite: summon

So, I'd like your input on how to best implement this system. My current method can work, but its getting more and more complicated. I've considered creating a child class for each "type" of effect, though that would be a lot of child classes.

Thanks for any help,
Offline 65K
« Reply #1 - Posted 2013-08-23 15:40:01 »

My current approach is to have an Effect class that is really broad.  Most instances of the class won't utilize all of these hashmaps.
That sounds like missing design. One class for all ? Do you mean instances or inherited classes ?
Create separate effect classes.

Each effect also has a list of types. These define how the game interprets the effect.
Let each effect handle itself or create according effect handlers but "the game" should not interprete them all.
Ideally, adding new effects should not require to modify other parts of the game but only add the new effects classes.
Offline HeroesGraveDev

JGO Kernel

Medals: 382
Projects: 11
Exp: 4 years

┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻

« Reply #2 - Posted 2013-08-23 23:17:10 »

For each entity in-game, store a list of their effects.

Then each frame, call a "tick" function in each effect that does: a) check that it's active, and b) if it's active, apply its changes to the entity/world.

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

roseslayer (494 views)
2016-08-06 11:43:29

roseslayer (451 views)
2016-08-06 09:43:11

xTheGamerCodes (525 views)
2016-08-04 15:40:59

xTheGamerCodes (519 views)
2016-08-04 15:40:24

orrenravid (866 views)
2016-07-16 03:57:23

theagentd (945 views)
2016-07-11 14:28:54

Hydroque (1039 views)
2016-07-06 05:56:57

Hydroque (1026 views)
2016-07-03 08:52:54

GrandCastle (842 views)
2016-07-01 09:13:47

GrandCastle (640 views)
2016-07-01 09:09:45
Rendering resources
by Roquen
2016-08-08 05:55:21

Rendering resources
by Roquen
2016-08-08 05:52:42

Rendering resources
by Roquen
2016-08-08 05:50:38

Rendering resources
by Roquen
2016-08-08 05:49:53

Rendering resources
by Roquen
2016-08-08 05:32:39

Making a Dynamic Plugin System
by Hydroque
2016-06-25 00:13:25

Java Data structures
by BinaryMonkL
2016-06-13 21:22:09

Java Data structures
by BinaryMonkL
2016-06-13 21:20:42 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!