Throat still hurts and itches, but Chinese cough syrup did wonders for it…
A game environment without dynamic audio and interactive elements can only provide so much immersion, even with a richly detailed setting. By incorporating a responsive weapon system and realistic sound effects, we can create a more action-packed Pygame environment. Furthermore, building a robust class structure to handle various weapon types and sound effects will provide long-term ease in expanding the game's arsenal and audio capabilities.
To build a weapon class, we can borrow the animated sprite class's properties: game initializer, path container, image scale, and animation time (in milliseconds).
While building the animation deque, the tutorial introduces a new function in transform: smoothscale() which scales a surface to an arbitrary size smoothly.
To be precise, the output pixels for smoothscale() shrinkage are area averages of the colors they cover. For smoothscale() expansion, a bilinear filter is used instead.
As it was in Classic Doom and 'old-school' shooter games, each weapon will be positioned in the middle of the screen.
Right now, we have a placeholder weapon that cannot be fired yet.
To make our weapon shoot, we need the program to register the action of firing.
Heading back to the player class, we can keep track of our weapon-firing status with a Boolean variable. To swap it, we can simply build a constantly updated method that checks if we pressed the left mouse button (1) has been clicked while we are not in the middle of shooting.
With weapon interactions out of the way, our weapon needs an extra set of variables to represent reloading, sprite image count, current image frame index, and sweet DAMAGE.
Doom is a game with zero reload mechanics, all weapons have no clip mechanic and can be fired anytime so long as players have ammo for it. However, it creates a sense of weapon diversity not just by giving them different looks and firepower, but also their fire rates. Doing so preserves game immersion without making it look too unbelievable, leading to loss of immersion instead.
With the extra condition in weapon state, our first weapon is complete!
My firing animations are a little off, but the firing animation works.
Sound file source: https://pixabay.com/sound-effects/laser-14792/
Pygame has its own class and methods for playing waveform audio (wav) files.
In the audio mixer, the sound class is responsible for playing wav files.
Please stay tuned for a sound-recorded demo in the future!