Page 1 of 1

[Help] I need help with melee combat

Posted: Tue Sep 26, 2017 12:00 pm
by jonthums
How would I go about doing melee combat for a side scrolling sword fighting game, I want it so let's say if isAttacking = true, the enemy gets damaged how would I go about doing damage? An example code would also help greatly (I self teach myself a lot, looking at code is sort of how I learn!) Thanks in advance :D

Re: [Help] I need help with melee combat

Posted: Tue Sep 26, 2017 1:08 pm
by grump
Generally, you probably would play animations according to player/AI input, check for collision at the right time to detect hits, and update your game state accordingly.

You're asking very broad questions and the answers depend on a lot factors, what exactly you mean by "doing damage", and the game design goals in general. It would help if you could describe the parts you have problems with. If you don't even know where to start, I'd recommend reading a book or online articles about game design and programming.

Code: Select all

-- do damage
enemy.hitpoints = math.max(0, enemy.hitpoints - damage)