 Welcome to the simple cookie clicker tutorial. I'm gonna make a simple cookie clicker game in less than 30 lines of code Before I get started let me do a quick shout-out to my members It's one especially note here Kevin who has made it to his fourth month of membership. Thank you so much Kevin note I don't have a cool name yet for that group got to come up with something and thanks to everybody who has joined as a member subscribed commented and Thumbs up or like to say so click below to join Today's lesson is a cookie clicker game. So before we get that to be honest, I didn't quite know what this was So I found this and it was actually was shared with me I shouldn't say I found this and basically you just click on this cookie and That's it. I don't quite know what else it does. So I'm just gonna reproduce that part of it I'm not doing the fancy animations or anything. I don't not gonna do the per second thing I'm just gonna show you how to make a cookie click on it And count the clicks. So let us go ahead and get started Now before I actually get started. I'm gonna need to make I'm gonna actually I'm gonna need a cookie so I'm gonna go back to that and This is a site. I always use this is open click clip art and I'm gonna go ahead and search for cookie and One thing about this site is that everything on it is creative commons zero Which means that you can use it for any purpose and without attribution I use this with my students all the time. It's mostly clean once in a while some weird stuff pops up But it's pretty cool. So this is the cookie I chose but there are tons and tons of different options So I'm gonna go ahead and click on this and I'm gonna right click here And I'm gonna save this image now. I'm gonna go ahead and put this on my desktop. I'm gonna call it cookie now Note that this is a PNG file as you can see up here So I'm gonna go ahead and save that I'm gonna be using the turtle module Which I've used in a lot of my tutorials previously and the problem with the turtle module is that you can't use Png's so I'm gonna go ahead and Go back to my desktop and I'm gonna go ahead and open this and see what happens Okay, that's good. Now that is not what I want to happen I want to be able to open with other application, but since I can't do that I'm gonna go ahead and open up something called gimp, and this is what I use to Basically edit all my images on my computer So I'm gonna go ahead and go to file open recent you can see I've already done this because I practiced this So this image as you can probably see is a little bit too large for what our purpose is So I'm gonna do is I'm gonna go to image and I'm gonna go to Scale image here, and I'm gonna make it 300 by 300 I'm gonna hit scale and that's about the right size for our screen So I'm gonna go to file and I'm gonna go to export as now the Turtle module only lets you use gif files I think WMF and I know what that is and bitmaps So I'm gonna go with the gif file and I'm gonna call it naturally cookie dot gif because good naming is important So I'm just gonna go ahead and just take the defaults and now I have opened this file I have changed it to a gif and I've saved it onto my desktop. I can close this Now note that I'm gonna be putting my Python file Cookie clicker dot PY. It is also on the desktop The image has to be in the same folder as the program So let's go ahead and get started as I mentioned. I'm gonna be using the turtle module so we'll go ahead and import that and Then I'm going to create the screen and this is just stuff that you've seen Hopefully in my other tutorials if you haven't Well, this is this should get you started as well. So I'm gonna call this cookie clicker By at Tokyo EdTech and I'm gonna make background color And then finally I'm gonna put win dot main loop Okay, don't forget the parentheses a lot of people do and they message me and say well It's not working and it's because you forgot the parentheses So I'm gonna go ahead and run this and let's see what comes up Now unfortunately it comes up on my other screen and so what this is what I wanted I have a blank screen with nothing on it. So so far so good. Okay, so let's go ahead and Create the cookie So if you haven't used the turtle module before Basically the turtle module I need to register the shape so I'm gonna go win dot register Shape and the shape is cookie dot JP or not gif What that does now if I run this nothing's gonna happen nothing different If I run it just looks like that all I've done is I told the system that there is a shape Called cookie jiff and it's saved in this case. It's gonna be in the same folder Now if you're on other computers like windows, you might need to put the full path. I don't know how it works But this should work on most systems Now I'm gonna go ahead and create the cookie now to create the cookie. I'm gonna make a turtle object So Now I'm gonna say cookie dot shape and this is where cookie dot jiff comes in I'm also gonna do cookie dot speed even though I don't think I need it here This is not the movement speed. This is the animation speed of the turtle module So let's go ahead and run this and see what happens Okay, pretty cool You can see we've already gotten our cookie on the screen note that by default Turtles pop up at the center of the screen. So that is zero zero now It's a little bit big so you can't see it on this particular screen, but you get the idea and then What I'm gonna do is just gonna keep going and we need to keep track of the number of clicks so when the game starts the number of clicks is zero and To draw the clicks what I'm gonna do is I'm gonna create another turtle object. I'm gonna call it pen Does that be called pen? I just chose to call it that and I actually don't want to see this turtle at all So I'm gonna hide it I can still use it to draw a text, but I'm gonna hide the actual turtle itself I'm gonna make the pen color white And I'm gonna do pen dot pen up because I don't want to draw a turtle trail and Then I want to go take the pen and move it to 0400 and those are the XY coordinates and the following I'm gonna go ahead and do pen dot right And I'm gonna use an f-string here if he this is a Was introduced what Python 3.67 something like that. So you should hopefully have that so I'll put clicks and clicks So basically I just want to draw this text on the screen and then I'll put a line Equals and I want this in the center I want the text centered and I'm gonna make a font change font equals and it's gonna be I'm gonna use courier new and It's gonna be 32 in size and it's gonna be normal as opposed to like bold or italic notice here. There are two Right parentheses, I know I'll get a million messages about that The outer one matches the right method and the inner one matches this tuple. Okay, so let's go ahead and test it. Oh Very cool. And so we've already got Clicks zero now notice, you know, of course, nothing happens when I click on it and we're gonna take care of that now So all we're gonna do is create a function and I'm gonna call this Clicks And I'm gonna leave that blank for now and it's gonna give us an error and I'll explain why in a second and What I want to do is when I click this method or when the cookies clicked. I'm going to Change clicks so notice I use the global keyword here. So clicks equals zero It's because it's out here in the global space and not here not defined here in the function I gotta use it the global keyword because I'm gonna be incrementing clicks here in a second Clicks plus equals one and then what I want to do is I want to clear the pen So I'm gonna clear the text that's already there and then I just want to go ahead and do this again So I'm gonna copy that because I am lazy and Then finally the last thing this is it. It's a very very short program is I gotta tell the computer What to do when I click the cookie so cookie dot on click And I got to give it the function name Which is clicked notice. I didn't put any parentheses now. I'm gonna run this and like I said, there will be an error But you'll I'll explain it in a second So I'm gonna go ahead and click the Cookie and you can see over here in my terminal. You'll see an error says function XY Clicked it takes zero positional arguments, but two were given and this is a default of the turtle module When you use the on click method it automatically sends the XY coordinates to the function So we have to deal with that. So we just put X and Y in here and now we have a complete quick clearing. That's it so be me and There you go pretty exciting now again. I didn't put all the animations into it I didn't put any you know other other stuff But this should hopefully give you an idea of how simple it is to make this type of game Now you can hear I don't know if you can hear me clicking or not To be honest, I'm already bored, but I will get to a hundred and there we go And that is that let me go over it real quick We just count how many lines that was one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty twenty one twenty two Wow, twenty two lines of code. How how pretty cool is that? So basically we're using the turtle module We set up the screen here and that sets up the little the window Give it a title set a background color. We got to tell the computer We're gonna be using this particular shape again. This particular shape is in the same folder It's in the same location on the computer as the Python file we create our cookie and Just you know, it's a Python turtle and it's a turtle module turtle I should say and we're using the cookie dot gif that we created earlier and just set the speed to zero I don't think I even had to do that so I can get this down to 21 lines And again, we set clicks to zero when the game starts And then we're gonna be using this pen to draw on the screen and we just went get we hide it We set the color that we're gonna be writing in Pull the pen up because it will draw a line if we don't move it to where it once It's supposed to be and then right on the screen what we want to be written again You can change the font here It's got to be something on your computer and then we made a function called clicked it takes two arguments x and y which are automatically passed by the on click method and Basically, we just increment clicks clear the pen and then write again and that is that well fast and efficient, I hope you enjoyed it Join subscribe like thanks so much. Take care