Took a short break to celebrate Chinese New Year with close relatives. That said, happy Chinese New Year to my readers!
Text
Now that our NPCs can locate the player and move through the map smartly to get them within sight, the next step is to program the former to attack the latter.
Sound file link: https://pixabay.com/sound-effects/laser-shot-ingame-230500/
The tutorial's logic for attacking animatedly runs like this: if an NPC's distance from the player is lower than the NPC's attack distance, the NPC will be able to attack and damage the player. In this NPC class iteration, I think the attack distance is randomized (between 3 and 6) to keep players moving, maybe push them to be more aware of their surroundings and promote better positioning.
Take cover!
Action games commonly demand tip-top performance from players, and they would give players limited health to encourage dodging instead of reckless shooting Leeroy Jenkins-style. That would get boring pretty fast by default.
Another mechanic from the tutorial is NPC accuracy. Every time the player enters an NPC's attack distance, if the system's random number generator (RNG) returns an integer lower than NPC accuracy, the player will take no damage from that attack during its animated lifespan. Otherwise, the game might be too challenging by default. Again, you can tinker with your mechanics however you want.
In the meantime, I also imported another sound effect file to go with the brief player pain state.
Sound file link: https://pixabay.com/sound-effects/young-man-being-hurt-95628/
Doom Classic had this blink-and-you-miss-it red filter effect that is draw on players' screens when they take damage. While the tutorial went all its way to download a faded red rectangle image, why not simply draw it with Pygame's built-in fill() function at a lower alpha value (transparency)?
What I can tell you from this GIF is that my Pygame cannot play more than 1 to 2 sound effects at once before muting some of them. Will explore more on this later.
Text
Font source link: https://www.1001fonts.com/toxigenesis-font.html
Text
Text
Yeah, programs that do not know what to do after a step crash. This logic is why standard websites have their own 404 page to catch the program before they drive themselves off a cliffside crash course.
Back to our Pygame, the crash occurs when player health goes beneath zero, and sine both the tutorial and I do not have negative digit images in our files, the program becomes confused and crashes.
What we need to get rid of this blemish is a game over screen, a method that draws it over the screen, and a fetch request for the new game method.
Text
Text
Text
Text
Text