I am designing a simple "Plant vs Zombies"-like game, but without graphics (just polygons) for class homework.

I came to the point where I need to calculate damage to different entities. Por example, the zombie can kill the shooting turret in 3 bites, but would instantly kill the "engineer" that puts the towers if it touches him.

I was thinking on a List approach, where the Engineer always takes damage, from turret, zombie, land mine, etc, but he knows how much damage takes from any of those entities. It is not really realistic though, and if new entities are added, if I forget to add them to the engi or other entity's damage list, it would not get damaged at all.

Any help would be very appreciated.


2 Answers 2


The usual simple approach is to have attacks do X points of damage and creatures to have Y amount of hit points. An attack subtracts damage from hit points and the creature dies when it has 0 hit points left. Then you need only basic arithmetic and no weird data structures or explicit coupling between creature definitions.

An extension of this is to then add damage types and resistances. This is just another mathematical extension. In this setup, an attack might do X bullet damage or X fire damage, or so on. Creatures then have resistances or weaknesses to a set of types, which is just a multiplier (so a creature might take half damage from bullets and double damage from fire). A creature can also have a default resistance so that e.g. it might take 0% damage from all types except the one or two that it's vulnerable to.

Damage, hit points, and resistances can model a very huge variety of situations, including the one you outline. A direct port of your design to this model would be to give each attacking creature its own damage type; then you can explicitly set a creature's damage resistances to only accept the damage types of a specific set of attacking creatures.

I wouldn't necessarily recommend going that way, though, as it makes your game harder for a player to understand. Remember, humans are all about pattern recognition, and games tend to play into that. If a shooting turret kills a zombie in 3 hits and an tank in 6 hits, the player will want to extrapolate that experience into knowing that a strong turret that kills a zombie in 2 hits will kill the tank in 4 hits or less. Breaking that expectation will make your game impossible to predict, hard to understand, and ultimately unsatisfying to play.

Also, of course, coupling the creatures will make it harder to iterate on your design, as you pointed out. You should be able to drop in a new creature and just have it "work" without needing to go back and modify every single other creature.


iYou need maximum flexibility for your self.

Meaning you need config values for each damage dealer and damage receiver. Two types of damage cover for most of your situations. A flat amount (say 10) and a % amount say (20%). Obviously you need hit points for the damage.

This is for you however. Maybe you want damage overtime too.

Relaying this the players is an entirely another matter. You may not show any damage numbers at all. You may choose to show "Monster dies/in 3-5 hits from your selected creature" Or you may show only health bars and damage effects without the actual numbers.

What you want to have is good configure-ability, so when you do decide to fiddle with numbers it can be easy.

Most people hate excel but i really recommend it for configurations of the sort, when you don't have the time and patience for coding really dynamic configs.

I have a whole subset of units that have a whole lot of values to each one, I've linked all damage calculations for them to single cells. I start with a base damage number say 50 - every unit starts with it.

When you run past your logical considerations on what is how strong etc. You decide that X unit will have 5 times the base damage. Except in my case the unit has damage vs every kind of other unit. If you have to calculate these one by one each time you change them its a headache. Instead if you tied them all up, all you need to do is change 1 number and everything auto calculates.

Specifying damage vs each unit is a bit easier to manage than having one damage and assigning resistances to all other entities. You can have the machine translate that to you in terms of resistance. What do I mean? If your BASE damage is 200. And you say this unit has 150 damage vs rocks. It means the rock has 50 resistance to this unit's damage.

The more complicated damage you have the more precise planning you need to make to organize it. Obviously configuring resistances individually becomes much more convenient dependent on what you have/want/need to work with. It doesn't take rocket science. Even if you are not big at math, you just need a good plan/design. You need to understand what you want to achieve in the end, the rest is for the computer to calculate once you set the rules.

If you know your swordsman has to be 3 times stronger than your unarmed guy. and has to cost N times a much, the rest is just grinding it out into existence.

Balancing is much easier if you can translate everything to a universal value. But that takes some effort. A lot of designers just go blind in balancing stuff and fiddle with numbers manually until the game seems playable. Few have the will to go ahead and calculate everything, Its one of the reasons why many virtual economies fail. People have no idea how much comes into them and how much goes out. They think that some rudimentary concepts can do the work of exact math. But they can't.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .