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 4 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 guys welcome back to the
channel and uh today's video will be the
fourth and final installment in our
building like an idle clicker adventure
capitalist type game
using python and pygame so if you missed
the first three episodes be sure to go
back and check those out we've already
created where you draw this very
colorful board each task runs at a
different speed and gives you a
different amount of money when it's
completed and then in the last video we
drew these buttons on to where you could
buy more of each task and then you also
eventually can buy managers but we
haven't set up the code yet to where
buying those managers or
buying more of these items does anything
yet so that's what we'll be doing in
this video
again be sure to check out the previous
ones if you do want to follow along line
for line but without any further ado
let's get into it
so i'm going to start with the logic for
buying the managers because it's
actually really straightforward what
we're going to do is we're going to say
if
the
green manager so we
already when we did the draw buttons
we have red manager by and read by and
those are the buttons that are going to
be
getting passed back so we're looking to
see if the button green manager buy
collides with a mouse click so we can
come right into the code we already
built for when you click on the tasks
and piggyback off the framework that's
there and it'll be if the event position
now that was clicked is colliding with
the green manager buy button but we need
a few additional conditions because
there's no reason to
to let them do anything if they don't
have enough money so their score right
the money has to be greater than or
equal to the green manager cost for the
button to do anything
and then we'll add another here which is
and not
green owned so if green is
owned already there's no reason to do
this button either but all we're gonna
do when it is clicked
is two things we're gonna set green
owned equal to true because now you had
enough money you clicked on the button
and you bought it and then the other
thing we need to do is we need to
subtract out the cost
of purchasing the manager
so
now this should handle buying it and
this also will probably make the button
disappear because we made drawing the
button on the screen conditional on it
not being owned
but what we haven't done yet is we
haven't actually said
what happens if
um green is owned so
let's go ahead and say if green is owned
and
green
draw
draw green
is false so actually we just say and not
draw green so what we're saying here
is it hasn't been clicked on but you own
the manager
and we're going to set draw green equal
to true so another way to think about
this draw green we set it we called it
draw because it's what's actively
drawing the progress bar but it also
could be thought of as like a green
active variable and so
what we're saying here is if you own the
manager and it's not active set it
active so let's go ahead and run this
and uh before i copy this code five
times let's just get to a hundred money
as fast as we can click them all
and let's see when i get to a hundred i
will try to purchase that green manager
button it shouldn't let me do anything
none of these buttons are going to let
me do anything yet because i don't have
enough money but now we're almost to a
hundred i'm gonna buy the manager
okay local variable manager button
reference before assignment interesting
screen manager dot by collide point
so let's take a look at our draw button
function because i think it should have
let us purchase it there
if not owned manager button
buy
oh we need an else condition for this
guy that's my mistake
it needs to exist in all conditions
because it's one of the things that
we're returning so the function is going
to cancel out so what we'll do
is since the background of the screen is
black
we'll make it black when uh when it's
already been purchased so
just to speed things up so you guys
don't have to watch me click around i'm
gonna make it to where you start with 90
this time so we can test so you can see
all i did was change the initial money
that we start with but now okay i was
able to buy the manager and you can see
once it's purchased it goes away you can
click here nothing happens and that
green task is running automatically on
its own so that's pretty sweet i'm going
to copy that real quick for the other
colors i'm going to change the initial
score back to zero
yeah obviously it can take a while to
test something the first time you write
it so you can do things like adjust your
starting score to just give yourself uh
an easier time testing
and as long as you remember to change it
out change it back to what the correct
starting conditions are then that's a
really
slick trick for troubleshooting a little
more rapidly
so now we want that exact code for all
six of our tasks for all six of our five
of our colors
red owned
and obviously the cool thing about this
is um you know i'm just doing it with
generic shapes and colors but you
definitely could substitute in like your
own custom icons like that's what
adventure capitalist does they have like
really fun
little cartoon shapes for each task and
they have this like way of scaling it
such that you feel like a
multi-multi-multi-billion trillionaire
by the end of the game
and so like what we're doing here is
we're creating a framework where you can
customize this game and you can spend
all the time you want on the aesthetics
improving it down the line but you have
the shell of the game working really
well already for you so
hopefully you find this useful i had a
lot of fun the first time i made this
game and so i decided to do a series on
it
so
change everything from green to red
and then let's go ahead and do that
again for orange and white
and then we'll do purple
so i've said this in i think every
episode so far every piece of it um
when you do see code like this that has
to get essentially copied and just have
like one thing replaced each time you
definitely could go through and do a for
loop
and find that's basically automating
yourself a way of not needing to write
the same essential code five times
um
for sure you can do that if you want
that'd be a little slicker
um i am just doing it this way because
it's really easy for me to keep like
where each thing is if you want to
modify like what one button does at a
time it can be easy to do it this way
but i am spending a lot of time as a
consequence of that um just replacing
like the name of one color with the name
of another so
there's definitely value in taking the
time to create
for loops that'll that'll do this for
you five times but that should do it
okay so um i'm gonna just i'm not gonna
run the test real quick i don't wanna
chew up too much time and we saw that it
worked for the first one
so the next thing we're gonna do it's
gonna be very similar to what we just
did here we are going to handle what
happens if you buy
more of a
specific task so like if you
pay the money to buy an additional green
square you know we want the value to
increase
and we also want the cost of buying more
to increase so
let's go ahead and
use the same collide point so i'm going
to steal kind of this
if task here
and i'm going to say if just green buy
so not green manager buy collides with
the mouse and the score is greater than
just the green cost and now we don't
need the and not owned anymore
so what we're doing is we're checking to
see if you clicked on the buy more green
button
and that you have enough money to buy it
and if you did then we're gonna do a
couple things we're going to increment
the green
value so we'll do that first
we're going to add some value and how
much should we add i think because this
is the cheapest one we'll just add 0.15
but then we also need to update the
green
cost and i'll update it by 0.1 and
here's why
um again
make these values whatever you want them
to be here's why i rounded those values
when we drew the buttons on when you
give them decimal points pi game can do
this weird thing and python we're just
tacks on like instead of 0.15 it'll say
0.149
because that's going on in the
background of the computer
so if you do find yourself with crazy
rounding issues just go through and
round it off to a couple decimal points
um and then the last thing is
you actually have to subtract out the
green cost from your money but you want
to do that before you update the green
cost
okay
so
let's go ahead and run this and i think
this will make it to where you can buy
more green let's just check that real
quick
okay so now you can see it's worth 1.15
every time and we can buy a few more and
it looks like i actually forgot to round
this value when we did our draw task so
let's go add that real quick so i can
show you what i was talking about
uh draw buttons
string manager cost
draw task yeah so this string value the
value was just thrown out some crazy
decimal points so let's just round it to
two but
you could see right there
and i've only got the code in for green
so far but you could see right there
yeah so now we don't get those
thankfully we don't get those crazy
rounding issues and we can buy more of
them
and that's really cool like now the
green is worth more than the red
just by running this for a little bit so
let's go ahead and copy that for all of
them
and we'll just play the game a little
bit we'll get a few of the managers
and this is really when it starts to pay
off when you see all of your
functionality finally programmed
green
there we go so then let's make this guy
this will be red for everything
and the nice part about the way we wrote
this code because we made everything a
variable
is we really can just go through and
find everywhere that said green and make
it red and then
um to make it to where you also like you
increase the cost by a progressively
larger number but you also pro increase
the value of each task because you want
each task to feel kind of unique and
like
there's different benefits of getting to
different checkpoints
um obviously the like up the the high
end stuff that takes way longer to
finish
should give you
more money and it also makes sense that
it would cost more to continue upgrading
those so
uh what i have here just some default
values that um they're not going to be
that crazy like
i'm essentially saying okay well the
value is going to be directly
proportional to
um the speed as well as the cost so what
i'm saying is
it's an exact comparison like if if you
buy 10 white it's going to give you more
money but it's also slower so it's going
to i mean
it should make sense to you my main
point is if you're designing this game
and you want to show it to people and
play it with people
um i recommend spending some time to
play around with the actual like
gameplay and change some values change
some speeds add some code for like oh
you get above a thousand and then this
happens or this happens
but i'm trying to help you guys build
the framework of the game so
these these are some default values i
found were pretty fun in creating it
initially and running through it so
let's go ahead and see now
first thing i do every time i play this
game is i try to get myself a manager
like as fast as possible even before
buying more of any product because i
hate clicking around
on all five tasks it's really time
consuming so i try to get to 100 as fast
as possible using all the tasks
yeah let's see get ourselves a green
manager
upgrade green a little bit more because
you can tell like with how much
now we get per execution of green
it's really worth it to upgrade them a
little bit
let's see if we can get it up to like
yeah we'll get them above six
and now we'll run the other ones a
little bit
and
i'll probably chop this up in the video
a little bit to just
highlight the different cool things
going down
um but yeah if you stuck with it this
whole tutorial and you built this game
start to finish with me i really
appreciate you being here i try to get a
lot of these tutorials out every week
and i take a lot of requests so if
there's something specific that you want
to see rebuilt in python or pygame or
you have any other questions about just
software in general and writing
programming just let me know about in
the comments and i'll be sure to get
back to you as soon as i can
um but hopefully you've enjoyed this
series if you did definitely be sure to
subscribe to the channel and be on the
lookout for more fun content and uh
definitely i appreciate you being here
and watching all these videos
and yeah let me know if you decide to
build this game and you add on to it and
you add other features what you do
differently
because it's always fun to see like how
someone can take the framework
of a project and really expand it out to
make it their own there's obviously a
million different
things you could do with this game
you know to really to take it to the
next level but uh i think this is pretty
fun pretty cool to look at um you know i
bought the second manager there now and
i'm only doing half the work and
they're making quite a bit more than me
clicking these three
so
let's see i'll just play around for a
bit longer
and i will say this is actually fairly
addictive
especially like if you're doing
something on your other screen like
you're writing emails or something you
leave this up on the left screen and let
yourself get a whole bunch of money
while you're not looking and then
buy a obscene number of upgrades once
you come back with thousands of dollars
it's really
it is addictive which is definitely kind
of the sense i got from it the first
time i played it uh
you know like the app adventure
capitalist on my phone
where you just spend hours a day and you
don't even realize it
upgrading it and
some fun things you could do with this
game you could make it to where the
costs of upgrading are actually way
higher but then when you hit certain
checkpoints like everything multiplies
times two like achievements that's sort
of the standard style of this game is
like if you get everything times 10 then
then you get a multiplier where the
speed of everything doubles like the the
possibilities of things you could add on
are endless so
um
i enjoyed making this a lot i hope you
enjoyed watching this series of videos
and following along if you did
as always i appreciate you checking out
the channel be sure to leave a like and
a subscribe if you found it useful and
if you want to see anything specific in
the future just let me know about the
comments below and i will try to get
back to you as soon as i can
and as always good luck with your code
and thanks for watching thanks guys bye