Classesallow us to give properties, or traits, toobjectswithin those classes. For example, if you had
A class of perfect snacking fruit...
...and those class properties were: red, sweet, and small...
...then objects that fit could be cherry, strawberry, raspberry (definitely not banana, lime, or watermelon).
This line of code sets the size of the image we want to use. You can change the 300 numbers to anything you want but we find 300 works nicely!
Now let’s center our image on the screen. We use WIDTH / 2 because that gives us the halfway mark, or the center. If you took a string, folded in half and pinched one end, you’d see that is the center of the string!
self.rect.centerx = int(WIDTH / 2)
When using divisionoperatorsin Python, we need to use integers and intwill convert the WIDTH / 2 number into an integer for us.
Let’s do the same for the vertical center.
self.rect.centery = int(HEIGHT / 2)
Make sure to create a rectangle for our image like we did for our text…
self.rect = self.image.get_rect()
…as well as positioning it. This will place our shop icon in the top left of the screen.
self.centerx = x
self.rect.bottom = y
Now it’s time to set up the bonus clicker criteria and the clicker cost to upgrade.
self.cost = cost
self.bonus = bonus
self.name = name
We useself.because if our shop has multiple items available, we can code for each specific item.