17 Video Views·Apr 22, 2025
In Honor of HALO Infinite Releasing this week and celebrating 20 years of playing Halo this series of Python and Pygame Tutorials covers how to create your very own Halo themed space invaders style game!
We start the video by demoing the end result full functionality of the game and then dive into this video's specific content!
Episode 6 is where we use the pygame built in mixer to load .mp3 and .wav files into our game, set the volumes, and determine when to start them! This is the final step in really feeling like we've created a fun full game, and good game music and sound effects make a huge difference. Then we discuss the different ways to make this game your own, modify it for possible improvements down the line, and what sort of other applications the things learned in this series can teach us!
Episode 5 covers checking if the player's health is gone or if all the available lives have been used and ends the game based on those conditions. However we implement a restart menu to allow for replaying even after dying and that requires separating the main menu functionality into a separate functional loop from the main game functionality. This allows for a start menu/restart menu between runs of the game. We also add collision detection between the player and enemies!
Episode 4 shows how to handle the shooting action for the player, as well as setting up collision detection between the enemies and the player's bullets and then we create randomly generated enemy firing to attack the player, followed by collision detection set up to check if the player was hit, at which point we decrement his health by 10%, and if an enemy unit goes off screen left we lose a life!
Episode 3 shows how to spawn waves of randomly generated enemies off the screen to the right and have them come across the screen during attacks. This includes using the random module with the rand range operation as well as the random choice from our list of possible enemy units! We load in the images of two different 8-bit Elites and a pixelated Grunt for our enemies and assign them to different colored projectiles as well.
Episode 2 covers how to pull in a player graphic, which in this case will be master chief, and then setting up four directional controls for the player! Additionally we set up bounds so the player cannot move their character off the screen in any direction! This is essentially creating edge collision detection and we do a deep dive into some of the themes of pygame as well as how to create and call classes and subclasses!
Episode 1 covers how to pull in outside images for your game to set up a full screen background, how to initialize pygame and how to draw lives and level text labels onto the screens using f strings to format strings with variables!
This game will be rolling out in a six-part tutorial series so be sure to check back over the next five days for the entire series! Leave a like sub or comment if you like what you see here and be sure to check out the channel for tons of other great content!
https://www.youtube.com/channel/UCV5Ab39YnXvTZ6Grar9URxQ
Thanks for watching, good luck with your code, and give the covenant back their bomb!
what's going on you guys welcome back to
the channel and i have a super unique
one for you today uh as a lot of you
probably know halo infinite uh early
released their multiplayer recently this
past week marking the 20th anniversary
of halo and if you're like me you
probably grew up playing these games you
know on this channel we do typically
python and other software tutorial
series we've done apps we've done
widgets and we've done just base python
programming as well as a few games and i
thought what would be super fun in honor
of the halo release as if we did a
little bit of a
halo kind of space invaders style game
i'm gonna start every video in the
series by kind of demoing the game
so that you guys see what the end goal
is and hopefully think that that's
something worth building to
so i'm gonna demo the game that we built
here a little bit and i am pretty proud
of it you can hear just kind of the epic
soundtrack in the background i've left
instructions for how to play and said
you know click anywhere to begin so
let's get into it we've got a little uh
some soundtrack playing in the
background i've got some sound effects
the enemies in each wave are
automatically spawned in
and they kind of randomly pick heights
to spawn in from and i've set them up
with a specific speed to come in at
and i've added some impact sound effects
that maybe aren't the greatest
i've also made it to where each wave
increases the number of enemies so you
can see we're on level two now and we
should have more enemies
i got these little uh 8-bit halo
icons from the internet
and in the series in the actual
tutorials i'll talk through kind of how
to grab images how to scale them all to
the size that you want
as well as there's a free tool on the
internet for removing the background
from images so
if you've dealt with kind of the super
annoying like you pull in an image you
want to use and you have that like white
rectangle around it no worries uh we'll
go over how to do that too
all right so there we go so that's the
game demo and whatever stage of the
project you're at and following along
with uh hope you're enjoying it be sure
to leave a like on the channel a
subscribe to the channel if you are
enjoying it and good luck with your code
all right so the final part in this halo
space invaders tutorial series that
we're going to throw in is going to be
adding music and adding sounds
level up game over start
background music all that stuff and
that's it's also a great bit of pie game
tutorial as well so just like we loaded
in all of our images for our player and
our background and everything we're
going to load in the sounds and
so to use music you want to use
pygame.mixer and just like with fonts
you initialize it when you start the
program up and that's going to
allow you to use all the pi game mixer
functions later on
so then uh we're gonna go ahead and load
in the music first and it's
mixer.music.load
i have this audio folder just like i had
an image folder and it's a uh it's got
all of my
files that i need in it
so it's pygame.mixer.music.load
and then point it in your
file path audio
halo
song.wav and full disclosure guys don't
use copyrighted music if you want to
make any money off of your games if
you're trying to build something that
could be
like put on a website or played without
having to pay royalties this is just for
a tutorial it's just for me to play at
home and so i'm using an actual halo
song
you're going to want to get some
royalty-free music or make your own
music if you want to be able to use it
in a commercial setting
but uh then uh after you load in the
file you want to set the volume so
that's not overbearing and so for the
music i'll say 0.7 that's um it's on a
zero to one scale and point seven is
pretty good for music it's okay to have
that as kind of the loudest
thing in your game because it it is uh
kind of the continuous playing in the
background thing
so
then it's a little bit different to pull
in sound effects so pygame.mixer.sound
and then
we'll say that's in audio
forward slash and i think i called it
start.mp3
okay
and i'll get uh i'll get this going just
with the start and the game over and
then the uh and then the background
music and we'll play it with that and
then i'll kind of talk about how you
could add in um additional sound effects
like level up or shooting or lasers or
enemies and how to kind of incorporate
those as well
but so i've got um
a like a british male voice saying start
and then game over
at the beginning and at the end
and so you want to grab those files
there are places on the internet that'll
let you
have free mp3 files
and so just
you know a little bit of light googling
and you can get yourself some
some pretty good sound effects for free
youtube also has a sound library for
creators so if you're not sure where to
get stuff that you're allowed to use
for free then check that out as well i
recommend even if you don't actually
make youtube videos
you can create like a you can go to
youtube studio and their sound library
and have access to royalty free music so
that's just nice to know and then uh
what we're doing here we're just loading
in the files all three of the files and
uh this one i called the game over
gotta spell it right
there it is
okay and then i'm setting volume for all
of them as well just so none of them
absolutely blow out the speakers
gameovervoice.set
volume
0.7
alrighty so the last thing you do with
your music
and you could make it to where this
executes at the start of your run loop
i'm just gonna
drop it right here so the music starts
playing at the very beginning of the
game but you could put this same line
this music.play you could put it inside
of your running loop and not until you
clicked start on the uh
on the start menu would that play
but uh let's stick the start voice and
the game over voice where they're gonna
go and then we'll play the game and
we'll actually hear if our sound effects
are working or not
so
down in the start menu which is the last
thing we made in the previous video
we said this is when we're going to
start the main loop when the mouse
button down is clicked and so we're
going to add one more thing we're going
to say start voice dot play and this is
how you call a sound effect i'm going to
copy it when we use game over
okay so we're saying when you click
start on the menu after dying or at the
very beginning of the game that's when
we want start voice to play
and then what when we want game over to
play is uh when we first
have this negative health condition
so if lives is less than or equal to
zero or player health is less than or
equal to zero we want to have
start.voice.play but the problem is this
is true for a few seconds because the
way we have it linger on that screen and
we only want this to play once so to
avoid having it say game over over and
over and over again while we're waiting
in that five seconds
let's just do something that's only
going to run the first time
if game over is equal to false then we
want to run game over voice
right so we're just checking
and this should only execute the first
time it notices that you're dead
hopefully
so let's go ahead and run that hopefully
the music now is working and starting
game over
all right and this song gets me hyped
stop so there we go start
we'll add a little bit of sound for
these bullets that'll be cooler a little
impact sound
um
and let's see if i can
die real quick and let's listen for game
over
game over
yeah
that's pretty sweet i'm gonna hit start
again play a second time stop there we
go we hear the same sound works multiple
times
and the game over voice
and this is uh starting to be like an
actual game that's just like
awesome to play
[Music]
all right so let's uh let's go ahead and
take a look at just a few things that
could take this i think just uh over the
top um
you could get a library of songs like if
you had different songs and you wanted
it to pick one you could use that rand
range that we used for like spawning the
enemies and you could uh pick any
integer from like a list of songs if you
want it to change or you want it to
change with each level or anything like
that
those are totally the sorts of things to
just um
just sort of play around with and make
it your own game in time
i'm gonna go ahead and grab a impact
sound and i'm just gonna
overuse it like you probably would want
a different sound for the enemy bullets
and the player's bullets i have audio we
could
split it out and use a different one for
like each shot but i'm just gonna use
one impact for now
just to show
like where you would put it how you
would incorporate that
and that's another thing i just think
you should like play around with and
make it kind of customized to whatever
you're picturing for your game so let me
grab impact.mp3
we're going to set it a little bit
quieter because impact happens quite a
bit more often
so set volume and we'll say 0.3 should
be plenty loud for it 0.4 that'll work
okay and now we're going to come down
and we're going to say like when we
shoot an enemy
so when the player collides with an
enemy that's when we want impact to play
we'll say when the enemy hits us we'll
play that sound as well
it's not like a particularly cool sound
like it's not
like a good alien dying or person
getting hit noise um but that's kind of
the beauty of playing around with the
sounds here at the end um
so let's take a look at this if the
enemy and the player collide then we'll
play
the impact sound
let's copy this
if the enemy goes off screen we'll play
the impact sound
we'll say if the player hits an enemy
we'll play impact so let's take a look
where does that occur
impact impact collide
well that's that's probably enough i
mean you um
you guys are gonna get the idea and
you're gonna be really sick of this
sound already um i believe it's probably
inside of the checking for collision
inside the player's uh shooting function
but let's just go ahead here and run it
real quick stop and see
[Music]
if we run into these guys
yeah
okay and if they run into the screen and
you can set it to where
it when they shoot you we have that
sound occur as well so that would be
inside of the
collision for the projectile class let's
see here
character move shots if it hits the
player we'll take 10 health away and
then let's go inside the players move
shots and if it collides let's do that
okay so this
should probably now that little like
it kind of sound i think it's actually
called like arrow in target but like
anytime anything collides now it should
make that little noise all right you
hear that
it's when we hit the player when when
that we hit the enemies when the enemies
hit us
when we run into the enemies
you'd probably want more than one impact
sound you might want a shooting sound
like a laser or a bullet or something
but
now you have the tools to be able to do
that on your own and honestly this
tutorial series has taken a lot out of
me so i'm gonna call it there i hope you
found this entire series super useful i
had a ton of fun making this game
obviously halo had a huge impact on me
at growing up it's been out for 20 years
now and it just keeps getting more fun
to play so
i hope you found this useful i hope you
found it fun if you did please leave a
like on the video subscribe to the
channel that helps me out a ton i hope
you've been enjoying everything i've
been rolling out
you know if there's a specific tutorial
or subject that you want to see more of
just let me know about in the comments
below i'll do my best to make videos on
what you guys really want to see and uh
as always good luck with your code
thanks for checking out the series
thanks for checking out the channel and
i'll see you next time alright bye