Game Development Reference
In-Depth Information
Behaviors for the common game object
As we have an existing class for common game objects ( Entity ), we can start to define
some behaviors that are common to all the characters in our RPG game, namely, the fol-
lowing objects:
TakeDamage : This is an object where a character can be damaged. Keeping this
object as common ensures that the calculation of damages is the same for all.
Attack : This is an object where a character can attack another character; if suc-
cessful, it deals with damage, or in rare occurrences, it makes characters hurt
themselves. Again, having one way to calculate this helps in battle games so that
attacks are balanced.
So, if we add these behaviors to our Entity object, we get something that looks like the
following screenshot:
The behaviors shown in the preceding screenshot would add the following to the Entity
class code (just an example):
public void TakeDamage(int Amount) { Health -=
Mathf.Clamp((Amount - Armor),0,int.MaxValue);}
Search WWH ::




Custom Search