How can I create a generic Damageable family? [Solved]

  • Hi there!

    How could I go about creating a generic Damageable family?

    For instance, both a wooden crate and enemies are damageable, but they react differently to being hit with a weapon.

    The crate emits a "broken" sound effect, plays a break animation, destroys after its animation has finished and then drops loot.

    Enemies do one thing if they're damaged and then another if they're destroyed.

    Right now I have a Damageable family that gives a family member the "Health" instance var.

    When the player hits a Damageable family member, I run a function called TakeDamage(UID, damageAmount)

    I'd like for similiar objects to share basic functionality but implement their own events specific to they're behavior.

    Construct doesn't really support any sort of virtual function overriding, so what do you all think would be a good approach to this? Or can it even be done with Construct?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Add a family instance variable called type. Set any crate on created to be type "crate", any enemy on created to be type "enemy". Run it through the same function so TakeDamage(UID,damageamount,type). Then say if type/function.param(2) = "crate" do such a thing, if type/function.para(2) = "enemy" do another thing.

  • Great suggestion!

    I do hope that Scirra decides to add object type functions and virtual family functions in the future, but this definitely works for now!

    Thanks!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)