[Progress] Melee Combat Tutorial 1/2 (Patreon)
Content
I'm going to use a platformer just so that this is based around code most of you will recognize, and I'm going to split the video into two parts. Part 1 is going to talk about setting up "An attack". Auto-combos will follow in Part 2.
I've had to do some rare Art™ing for this one and was inspired by Kris' hot new combat sprite idle pose in Deltarune, so I based the idle on that and went from there, creating a run, idle and attack!
The way this is all planned to work is actually fairly elegant. The idea whenever I make a tutorial is to find the best balance of simplicity (a method that can fit in a video) and flexibility (viable extension and edge case coverage). The "Best method" is almost always out of the running and this is no exception. But the method we're using is actually pretty comprehensive in this case and could very easily support a whole game built around it.
1. A state machine governs the player and whether or not they're attacking (This is important for Auto-Combos later, mostly)
2. When pressing attack, we swap to the attack animation + state. We also create/clear a DS_LIST that tracks enemies that have been hit by the attack.
3. When playing the attack animation, each frame we swap out the player's sprite for a precise-per-frame hitbox sprite that is matched up to the attack animation. (Unfortunately, only precise hitboxes have a per-frame option in GameMaker currently.)
4. We check for collisions with this new sprite, using the collision list function.
5. We compare the IDs of anything we hit to a DS_LIST of previously hit enemies. This is to make sure we don't hit the same enemy twice with a single attack (over two frames for example). This means we can use multiple players, multiple enemies, various different combos and multi-hitting attacks with ease!
6. Anything we can hit, we add to the DS_LIST and process accordingly. We then swap back to our regular sprite before actually rendering! Smoke and mirrors complete.
I have a bit more Art™ing and coding to do today but then it's on to recording. The code etc will as always be available to $5 patrons when the video releases.