Can a taste in music be nurtured, or is it an innate talent like the sense of rhythm?
Sound effects and music can do wonders with elevating your gaming experience. Alongside noise assets, collision detection simulates believable interactions between game objects. By striking a balance between reality and fantasy, one can develop alluring immersion within their video games.
The MP3 sound effect files used today were borrowed from Pixabay and converted into WAV format via CloudConvert.
Pygame's mixer function grants developers the ability to import and load sound files to play during runtime. The Sound() command allows them to control the sound's playback, volume, and other attributes.
If you need to play a sound and do not care about controlling its playback, you can use load() and play() sequentially instead. If you fill the latter's bracket with a positive integer, it will play that many times. A negative integer will make it play indefinitely until it is stopped manually.
The index of a blank play() is set to 1 by default, meaning it will play once per trigger.
The game Tetris provides its players the challenge to stack full rows of square blocks to remove them and earn points, all the while avoiding stacking them tall enough to reach a line that ends the game when exceeded. This engagement keeps players engaged with the game by providing them a loss condition to avoid.
The loss condition of our game will be our player hitbox colliding with the enemy hitbox. When that occurs, a line of text describing our loss (and loss of score) will be printed…
And after that, our scoreboard and player position will also be reset to what they were at the start of the game's runtime.
Every time I do not open my coding files frequently, my brain forgets what each line means and does. Acknowledging my forgetfulness and limited headspace, I add notes so long as they do not feel 'naggingly remindful.'
Pygame's quit() function does not close the game window without sys.exit(), only resetting the class' internal state. This logic can be used to reset player progress as a punishing challenge.
A video with music will be available in the future. Stay tuned!