Learn to create an idle click style game in the model of the classic and popular adventure capitalist style of app by using python and pygame! This is episode 1 in a 4 part series that covers start to finish how to create this entire game from scratch! We cover the basics of python and pygame code creation while also diving into more advanced programming concepts in this series!
Episode 1 covers the basics of defining the board game space, as well as importing the module, defining screen dimensions and creating a library of colors. Additionally we create a function to draw the tasks onto the screen rather than defining each individually. We then cover conditions for exiting out of the game as well as displaying text for the value of each event onto the buttons.
Episode 2 in the series handles the actions from the player of actually clicking on each button and updating the money or score the player has accumulated so far! This includes getting the position of the mouse upon clicking and checking if the coordinates are aligned with any of the defined event buttons.
Episode 3 includes the drawing of the buttons for purchasing more of each event commodity and displaying the manager buttons that would allow the player to automate each task. Additionally we block transfer (blit) text onto the screen showing the cost of each element and round all numerical value to only two decimal places.
Episode 4 concludes the series by handling the actual purchase and automation of each task when the managers are purchased, as well as increasing the value of each event and the cost of purchasing more of each event.
Be sure to like, subscribe, and leave a comment on what you found useful or what you'd like to see next! Thanks!
what's going on you guys welcome back to
the channel in today's video be part one
in recreating the kind of adventure
capitalist classic idol clicker style
game and we're going to do it using
python and pygame so before i get
started if you do find this or anything
else on the channel useful feel free to
leave a like on the video subscribe to
the channel it helps me out a ton and
without any further ado let's get into
it
so anytime you're going to build a new
game in python you want to import the pi
game module right away and then do the
pygame dot init
function and then
i always start by creating my game loop
so i create a variable called running
and then i'm going to put all of kind of
the action
um i'm gonna put all of the action for
the game inside this like wall running
equals true logic and this is basically
um handling your exit and your quit
conditions
so then you just go down and say for
event in
pygame dot
wow that is some bad typing
for event in
pygame dot event dot get
and then the first one you always want
to put in here is just if
event dot type
equals
pi game dot quit
and then we're going to use the pi game
built in
just running equals false
and then we're gonna come down outside
of the event circle and we're gonna uh
just do pi game dot quit
okay and so this is the bare minimum to
create a game loop you're essentially
saying wall running is true do whatever
it is we put inside the game loop but
then once running is false go ahead and
close out the app this is just what's
required to
make the x button that auto populates in
the top right close your app when you're
done
and
then
to actually just have a screen let's go
ahead and
come up here where we initialized it and
let's go ahead and create a screen and
that's going to be screen equals pi game
dot display
dot set mode
okay and let's define some variables uh
we're making something that's kind of
like mobile phone size so let's do 300
450
and then
set the caption so that's pygame dot
display
dot set caption
okay and then we're going to call this
not
adventure capitalist so i can't get in
any trouble
legally
okay and then um i'm gonna do something
this is something i like to do at the
beginning of like every game
i like to make a color library so that
the whole game i'm not just dropping in
um like rgb values you totally can if
you want but i pull in this um this sort
of set of colors for every game and i'll
usually just select from these so if you
want all these same colors as we go
through i recommend just pause the video
copy these down real quick they're rgb
values you can pull them off of the web
if you want
you can play around with the settings if
you want but i'm going to be calling
these colors fairly regularly throughout
the app so i recommend making yourself a
color library
and then we're going to create a few
more variables so i'm going to say
that for this the background is going to
be black you don't have to do that with
a variable if you don't want um and then
i'm going to say frame rate equals
60
frame
rate equals 60 and we'll call that in
the clock and then we're going to use
text a few times during this game
so i like to start by just calling out a
pie game font ahead of time as well
so we'll do that here
i pretty much always use free sands bold
until i'm
pretty much done with the game and i
just want to play around with settings
like changing fonts and seeing how that
changes things around
and then
let's go ahead and create a pie game
timer so this is actually how we're
going to control the speed of the game
to run it at 60 frames per second
so then you come back down into your
game loop your wall running and we're
gonna do timer.tick
at our frame rate okay so if you're
completely
baffled on where all of this is coming
from and you don't just want to blindly
follow through there is a very like
introduction to pygame course on my
channel
you can definitely check that out first
if you want to get some background or
you can just follow along and if you
have specific questions let me know
about in the comments
below and i'll get back to you as soon
as i can
but okay so the last couple things we
need to do just to get
something on the screen we'll do screen
dot fill
with the background color that we
defined
and then a zero for some reason
and then the last thing we'll do is
we'll flip it so pygame dot display
dot flip
and uh that's just
that's just actually writing everything
onto the screen
and let's see that's probably all we
need to do to just get a black screen
yep there we go you see we've got our
title it's black it's 300 pixels by 450
and the little x button in the top right
closes out of the code so that's pretty
good now let's actually start drawing
some objects onto the screen that'll be
i think a little bit
more clear and a little bit more fun
towards like what we're actually doing
so um i think since we're gonna create
five tasks um and we're essentially
going to
have them all be pretty much the same
let's go ahead and create a function
called draw task and that'll sort of
tell us what we need to pass in as we're
defining it here um
so i'm picturing like a button on the
left side of the screen let me just pass
this real quick and then let's talk
about it i'm picturing like a circular
button that you'll click on the left
side of the screen and when you click it
it'll kind of have like a progress bar
on the right side of the screen as it's
loading
and once it finishes that's what
actually gets you like points and money
so as we get more and more into the game
we'll add the functionality that
actually makes it playable but let's
start by creating our objects that we
need
so
let's start with
pygame.draw.circle
and we're going to put that on the
screen we're going to pass in a color so
there's the first variable
that we'll need we'll make all of our
tasks a different color
and then um for location
let's put it at 30 that'll get it away
from the left side of the screen just a
little bit
and then let's pass in a y-coordinate
for um for height and so essentially
they'll look exactly the same from top
to the bottom of the screen they'll just
change a y-coordinate
so y-coordinate and then let's make
these circles
a circumference of 20
thick so they'll be hollow
that might be radius of 20 yep
um okay so
that is gonna be
a circle now let's put the rectangle
down next to it
and we're going to do we're going to put
it on the screen we're going to make it
the same color as the circle and now
rectangles need
four coordinates passed in
so
since the center of the circle is at 30
and it has a radius of 20 that's going
to push it all the way up to 50 on the
right so let's go with 70 to have a
little bit of a gap between the circle
and the rectangle
and then let's since uh that circle is
the center point and we this for a
rectangle you define a corner let's do y
coordinate
minus 15 so that it'll be essentially at
the same height
let's make it 200 long and
30 tall okay
and so that's going to be a solid
rectangle of the same color that we call
in and so what i want to do as well to
make it look like it's a loading bar is
i want to draw a rectangle inside of
that that is going to be
just black so that it looks like a
hollow loading bar rather than
rather than a full
like colorful
rectangle
so we're going to
add some coordinates 75 so it'll be a
little bit further to the right and then
y coordinate minus 10 so it'll sit
inside of the rectangle and then it'll
be 190
by 20.
all right and as soon as we draw this
onto the screen it'll all make sense so
if you're following along
um
line by line just uh
just keep following along it's going to
look
it's going to look pretty good once we
call this so let's go ahead and actually
call one here let's start by drawing
green so let's do
draw task and then we give it a color
and a y coordinate so let's give it
color of green and then for y coordinate
let's give it 50. and let's just see if
that puts a circle in the rectangles on
the screen
yeah so i think that looks pretty good
right there and the nice part about
doing it as a function rather than
writing all that code for green is i'm
going to take this exact same code here
and we're going to do red
orange we'll do white and we'll do
so let's see red
orange
let's go with
white and purple so this is kind of
where if you're following along and you
want to play around with those settings
and make them different colors or
different rgb values like
do that make this game your own whatever
you're going to enjoy looking at i'm
sure my colors aren't going to do it for
everybody so
um take a look here i mean i just
you know using that one function we
created i was able to um give it you
know just five different y values in
five different colors and we get this
very colorful game where we've got what
we'll create is going to be five buttons
on the left and then five loading bars
on the right so that was pretty quick um
i think that looks pretty sweet let's
see what else can we do in this um first
video why don't we give a value to each
button so that'll be
um
that'll be an actual like uh
showing how much money each of them is
worth so we're gonna have to come up to
where we define variables in the
beginning and let's
make another section called game
variables
and let's go ahead all those colors that
we just made let's give them a value so
there's going to be green value
red value and you can play around with
these if you want um i'm going to just
go one two three four five to start
because uh my my theory with games is
you got to make them functional
and fun to play before you really worry
about like
little modifiers and difficulty and
things like that so let's get this
functional as fast as possible
and right so we just created the values
so we're going to pass that in as well
and we'll call it value
and what we're going to do
is we'll call this my value inside the
inside the function and we're also going
to draw
the actually let's call it value text
you can call it whatever you want but i
think that'll make more sense what we're
going to do now is um we're going to use
pygame's font dot render
and if this is your first time seeing um
like text being drawn onto a game with
pie game it is a little bit weird you
have to render the font and then draw it
onto the screen it doesn't just know how
to write text so you have to do it in
two steps so that's why we defined a
font up above and that's why you do it
with font.render
and
so
you give the value we're gonna use the
string version of the value so you have
to
convert value to a string here because
it's looking for a string and value is
an integer
or float by default and then define a
color for your text which will make
white
and then you actually put it onto the
screen
and since everything so far has been in
terms of that y-coordinate we need to do
the same here so we'll put it at 16
which should put it just inside the
circle that we defined
and then y-coordinate my 16 should do it
again
actually let's do -10 and i should put
it just inside the circle
and then the last thing we have to do is
actually the three
places that we called it here green
value
red
value
and
orange value
we have to actually
pass those values in for everybody oh i
got to fix my green value there
so anytime you say uh you're going to do
something new inside the function you
just need to make sure anywhere that
calls that function you update what
you're actually passing in so let's see
there
all right so here you can see like this
will be the cash value of running each
text
of running each task and we've drawn it
inside the button for each
game to be run so we've created the
shell of our game
in just under 15 minutes here and in the
next video we'll take a look at actually
clicking those buttons and having the
progress bar move across the screen and
updating your score so
hopefully you found this tutorial useful
uh keep an eye out for the next videos
coming on the channel and be sure to
check out the rest of the content we
have on the master tech while you're
there if you found this or any of that
content useful again i really appreciate
a like on the video subscribe to the
channel and be sure to let me know with
any questions or concerns in the
comments below i'll get back to you
right away and as always good luck with
your code and thanks for watching thanks
bye