PART 2: CONTROLLING THE PLAYER
Download tutorial file
Changes from Part 1
- Scaled collision box to better represent the player
- Added enemy sprite to "character" event sheet
- Press 1 to spawn a new enemy
- Organization, made folders for each character
- Moved the code to hide "solids" layer into the "system" event sheet
New Player Variables:
- hbSpawner: used to spawn a hit box when it reaches a certain time
Global Variables:
- hitPause: used for the hit pause effect when you successfully attack an enemy
Layouts and Event Sheets
- FXnStuff Layout: For...effects...and stuff
- Enemy01 Event Sheet: This event sheet contains all of the enemy code
- System Event Sheet: This sheet is for global game systems. Stuff like controlling particle effects, hitpause, camera shake, debug, etc.
Hit Boxes
When you press an attack button, you spawn a hit box. This is the thing that collides with the enemy's mask or collision box to register a hit. Hit boxes store attack data like damage (how much to subtract from enemy health) or force (how much x and y translation). When the hit box collides with the enemy, the hit box is destroyed to prevent hitting multiple times. If you want multiple hits just keep spawning hit boxes like in the punch3 code of the "player" event sheet (Line 41 and 42). The "dir" variable shows its usefulness here as I can use it to scale the hit box width in the negative direction if the player is facing left. Variable "hbSpawner" is used under the animation controls section to create the hit box. I don't usually like to put anything but animation specific code under here, but I made an exception for the hit box code. It just fit neatly in there.
Hit Pause
Hit pause is something most action games use to make attacks feel powerful. When an attack connects, there is a short pause in the game to freeze frame the action. The heavier the attack, the longer the pause. It also offers the player a split second to think about what they want to do next. Try longer hit pause timings for a more dramatic effect.
Hit Effects
I like to make my own particle effect systems in Construct for VRAM optimization and greater control. It's more optimized for VRAM because you can use one sprite for different systems. You also get more control because each particle is an object. All code for the particle effect is in the "system" event sheet.
Again, if there are any questions or something needs to be explained more clearly please let me know and I'll update the post.