Game design layout

So, I have many objects with materials, each of which has different properties (brick, glass, etc.), and each of them affects elementary effects in different ways. For example, a brick material will be exposed to fire or acid differently than a cement material. A brick that burns or melts will have a different effect when a different burning / melting effect is applied.

At this point in my game I have FSM, but it is very simple. If I remove the fire element on the brick, it will go into the Burning state. However, if I then dropped the water element onto the brick, I might want the fire to go out, take / add health and change the texture (or not depending on the current combination).

The bottom line is that I have many combinations without commonality between them, so I can not create something monotonous. Sometimes I need to change the texture, and sometimes not. Do damage sometimes, and in other cases add health. Sometimes I just need to do nothing in a function. For now, I can only create a global mapping, for example:

FunctionMap [ObjectMaterial] [CurrentObjectState] [ElementBeingApplied]

(those.

Function Map [Brick] [Burning] [Acid]
FunctionMap [Brick] [melting] [acid]

)

The problem is that this is obviously a ton of features due to the number of combinations available with materials and types of effects. Can anyone recommend a route to take or a pattern to look at?

Although this is not entirely relevant for discussion, this is done in AS3 and Away3D.

Here are some of my classes for one example:

public class Brick extends AbstractBlock implements IFireable { public function Brick() { super(this); this.material = new BitmapMaterial(_spriteManager.GetBlockMaterial(BlockUtilities.GetMaterialMap["brick_new"])); _type = "Brick"; /* RulesManager.StateMap["Brick"]["OnFire"]["Water"] = some function; RulesManager.StateMap["Brick"]["OnFire"]["Fire"] = some function; RulesManager.StateMap["Brick"]["OnFire"]["Acid"] = some function; RulesManager.StateMap["Brick"]["OnFire"]["Ice"] = some function; RulesManager.StateMap["Brick"]["OnWater"]["Water"] = some function; //and so on...there are nine different materials so I'm not liking this way */ } public override function render():void { super.render(); } } public class OnFire extends AbstractDamage { protected var _timeStart:Number = 0; private var _damageAccumulated:Number = 0; public function OnFire(block:AbstractBlock,bombType:String) { super(block,bombType); } public override function enter():void { super.enter(); } public override function exit():void { super.exit(); } public override function update(time:Number):void { super.update(time); if(_timeStart == 0) _timeStart = time; var time_delta:Number = (time - _timeStart)/_waitTime; var damageToSubtract:Number = (time_delta * _damageDone); _damageAccumulated += damageToSubtract; _self.Integrity = _self.Integrity - _damageAccumulated; } } 

}

Thus, the element of fire can be applied to a combination of applications. One of these blocks, currently frozen, has now fallen and is now entering the OnFire state. Each block has its own state machine, and the states themselves are objects that you can see.

 block.FSM.changeState(new OnFire(block)); 
+4
source share
3 answers

So, your problem is that you have 9 * 5 * 4 combinations of effects, right? Separate functions for each of them would not be easy to manage. But, even if you have a lot of data, you need it. I would make this data as simple as possible and then analyze it. Sort of:

 var materialProperties = { brick: { fire: { normal: {damage: 10, image: 'brick_fire.jpg'}, } water: { fire: {damage: 0, image: 'brick_smoking.jpg'} } }, //... a lot more of this ... } class Material { public var damage:int = 0; public var image:String = ''; private var properties:Object; private var state:String; public function Material(properties) { this.properties = properties; } public function apply(effect:String):void { if(properties[effect]) { if(properties[effect][state]) { update(properties[effect][state]); } else if(properties[effect]['normal']) { update(properties[effect]['normal']); } } state = effect; } private function update(properties):void { damage += properties.damage; image = properties.image; } } var brick = new Material(materialProperties.brick); brick.apply('fire'); brick.apply('water'); 
+1
source

Do you have custom class settings? It sounds like the perfect solution to me. Once you define the properties and abilities of each class, object management should be trivial.

those. Brick class, which has certain states [burning, melting] and reacts differently [function calls] when it interacts [collides] with another class [Water class].

I hope I will not bark the wrong tree .... If you can provide a little more than what you are looking for, I am sure that someone will be smarter than me;)

+1
source

The short answer is because I think Mr. Linkwist does a great job of this, but it sounds to me like a job for a template. In short, your elements (brick, concrete, etc.) Allow visitors (fire, ice, acid, etc.) to come and "visit" them and apply their effects.

Hope this helps!

+1
source

All Articles