kyleconroy/hawkthorne-journey — pull request #337 by campadrenalin (2012-09-23 01:20:21+00:00)
Title: Fall damage.

The fall damage mechanism is pretty simple. Any time you're falling at the game's "terminal velocity", you are accumulating potential damage in self.fall_damage. When you hit the ground, this value is rounded down to an integer, so if you have less than 1 in self.fall_damage when you hit, you will incur no damage at all.

Player:die() has been modified to handle floating-point and 0 damage in a reasonable fashion, doing the round-down stuff for you, so you can just throw any crazy number into it now. This makes the new Player:impactDamage() function very concise, which calls self:die(self.fall_damage) and sets self.fall_damage to 0. I also had to dip into the platform, floor, and bouncer nodes to make sure they called Player:impactDamage() at the appropriate times (and only then), and in the case of the bouncer, harmlessly reset Player.fall_damage.

The amount of damage that falling does is configurable in game.lua as the "fall_dps" variable. A fall_dps of 1 means "for every second of terminal velocity, do 1 damage." 2 fall_dps = 2 damage per second. Because this only gets counted when you're at terminal velocity, not total airtime, it ends up being a pretty fair measurement. I've committed with fall_dps=2 because it can be demonstrated in the game in taller levels like the Village Forest, without screwing up existing levels. Basically, if you can see your landing spot before you jump, you'll incur no damage.

This won't really have any impact on the game until we start having intentionally tall levels like Treeline.