Code Optimization: Combat


I took a month long break. This was semi-imposed but I then took a week-long crunch to iron out this point of development as it's the last major roadblock I have before release, not counting the last two or three big features like a day/night system or a weather/temperatures system.

Enemies now have proper metadata stored in JSON and dictionaries. This includes enemy stats and loot-tables. Enemies also now have health bars, to assist in telling how much HP a particular enemy has.

Damage is now done via a calculation using player and enemy stats and both player-side and enemy-side damage calls the same function for this. It also decides what weapons or tools certain enemies are immune to. Item dropping calculations were also overhauled, with modifiers allowed to worsen or increase a player's luck in item drops.

Bows were tweaked to be better. Arrows only despawn after a minute and can be retrieved to reup one's arrow count. You can now move/strafe when firing a bow and can hold down the item-use button/key to charge the bow, which increases its damage. While it's mostly cosmetic at the moment, secondary arrows were also implemented. Pressing P when on the Bow in the inventory will change the arrow type.

Status effects have been introduced. There are currently three kinds: Paralysis (from Viscovolts), Regen and Focus. Status effects take priority based on which status-effect slots are empty, i.e if status-effect-1 is already occupied, then the next inflicted status effect will be assigned to status-effect-2 and the same status effect cannot occupy more than one slot. It may need to be tweaked later.

Abilities have been introduced as a last minute feature. Two example abilities are included, which are Focus (boosts player's damage by +2 for 30 seconds, cooldown of 1 minute) and Regen (restores health over 10 seconds). Abilities have timer-based cooldowns and can be activated via hotkeys or clicking an ability icon. The player can also change which ability is assigned to which slot, via clicking a gear icon to enable slot-edit mode, click an icon to enable it's edit-flag and then press numpad <-- or --> to change the assigned ability then click the slot again to lock the ability to said slot. Then click the gear once more to exit slot-edit mode.

Enemies now have a 80x80 square pinned to them. This acts as an aggro-zone/in combat zone. A switch deciding if the player is in combat is set to true if the player overlaps them. A timer of eight seconds is set as soon as the player exits an aggro zone completely and the switch is then turned off when the timer hits zero seconds. This is mostly used to prevent skill-slot editing in potentially dangerous situations but may be utilized later for other things, such as enemies that aggro via a general range instead of a line of sight to the player.

Lastly but not least, combat gamefeel has been majorly adjusted. Knockback from both player-damage and enemy-damage is much larger, if the player is knocked back; they now stop if they hit a solid object, sword-swing speed was increased, a 'helper-box' was added to the end of player line of sight to make hit detection a bit easier and enemies were made slower.

Get A-RPG Gamekit

Download NowName your own price

Leave a comment

Log in with itch.io to leave a comment.