Attack / HP system?

What would be the best way to create an HP and attack system? How would I make a unit hit an enemy, and reduce the hp by the attack power they have? Should I create tables for this? I will be trying things as well, just wondered if there were other ways.

Personally upon creating an object I’d give it a power field (object.power or object.damage) to determine how much HP the enemy loses, with the enemy object having an HP field (object.hp) when it is created. This can be reduced in a collision event and if it is less than or equal to 0 you treat the enemy as dead. Remember that you can store values in object’s tables that don’t by default have a value. I frequently add a type field, etc. to each object I create as it makes collisions really easy to manage. Hope this helps!

A lot depends on the complexity. In a game like Dungeons & Dragons, each weapon has an amount of damage it does with some randomness factored in. Then attributes like strength and magic can add to the total amount done. D&D doesn’t really factor skill with the weapon into things (at least not the last time I played). But other games let your character build up skills by using certain weapons and those skills affect the amount of damage done. Or in my game if you’re in ship type 1, you have one gun and it does 1 point of damage. My enemies have an amount of damage they take before they blow up. From 1 point to really high numbers for boss fights.

So what you do is really up to you and your goals.

Rob

Hmmm, the only factors that will affect hp/atk in my game is the level upgraded that the character is. 

I love these types of questions!

Personally I would, extend @Rob’s answer to add even more randomness into your calculations.  

Let’s say your sword does 50 damage.  Now if the sword hits the head that will do much more damage than hitting a foot so I’d modify it like this

damageDone = sword.damage + mrandom(-sword.damage/4, sword.damage/4)

This will give you a random damage between 37.5 and 62.5.

Now to take this a stage further, not all sword strikes will hit (or enemy will dodge your hit) so more randomness is added

if mrandom(1,10) \<= 8 then &nbsp; damageDone = sword.damage + mrandom(-sword.damage/4&nbsp;sword.damage/4) else &nbsp; damageDone = 0 end

This gives the weapon an 80% chance of a hit.  Randomness makes games feel “less scripted” IMHO

Actually, that’s really interesting. I have been thinking of adding random critical hits to my game, plus abilities like freezing, crippling (slowing), knockback.

I’m just not sure as to how I would manage all of this. Right now, my main problem is having the unit stop when its range comes within an enemy, and once its dead, it marches on to the enemy base.

Then, I have to figure out how I am going to add the sprites to each character. I have the settings in a separate file, but I don’t know how I would access them via a require statement.

Personally upon creating an object I’d give it a power field (object.power or object.damage) to determine how much HP the enemy loses, with the enemy object having an HP field (object.hp) when it is created. This can be reduced in a collision event and if it is less than or equal to 0 you treat the enemy as dead. Remember that you can store values in object’s tables that don’t by default have a value. I frequently add a type field, etc. to each object I create as it makes collisions really easy to manage. Hope this helps!

A lot depends on the complexity. In a game like Dungeons & Dragons, each weapon has an amount of damage it does with some randomness factored in. Then attributes like strength and magic can add to the total amount done. D&D doesn’t really factor skill with the weapon into things (at least not the last time I played). But other games let your character build up skills by using certain weapons and those skills affect the amount of damage done. Or in my game if you’re in ship type 1, you have one gun and it does 1 point of damage. My enemies have an amount of damage they take before they blow up. From 1 point to really high numbers for boss fights.

So what you do is really up to you and your goals.

Rob

Hmmm, the only factors that will affect hp/atk in my game is the level upgraded that the character is. 

I love these types of questions!

Personally I would, extend @Rob’s answer to add even more randomness into your calculations.  

Let’s say your sword does 50 damage.  Now if the sword hits the head that will do much more damage than hitting a foot so I’d modify it like this

damageDone = sword.damage + mrandom(-sword.damage/4,&nbsp;sword.damage/4)

This will give you a random damage between 37.5 and 62.5.

Now to take this a stage further, not all sword strikes will hit (or enemy will dodge your hit) so more randomness is added

if mrandom(1,10) \<= 8 then &nbsp; damageDone = sword.damage + mrandom(-sword.damage/4&nbsp;sword.damage/4) else &nbsp; damageDone = 0 end

This gives the weapon an 80% chance of a hit.  Randomness makes games feel “less scripted” IMHO

Actually, that’s really interesting. I have been thinking of adding random critical hits to my game, plus abilities like freezing, crippling (slowing), knockback.

I’m just not sure as to how I would manage all of this. Right now, my main problem is having the unit stop when its range comes within an enemy, and once its dead, it marches on to the enemy base.

Then, I have to figure out how I am going to add the sprites to each character. I have the settings in a separate file, but I don’t know how I would access them via a require statement.