-
-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add game_popit.py in examples #2798
base: main
Are you sure you want to change the base?
Conversation
Add file beginner game_popit.py in examples.
|
||
|
||
class Game: | ||
"""The game-class. Object's and logic is in here.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grammar: "Objects and logic are in here"
self.size = (640, 480) | ||
"""Display size.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why store size if you just use it in one place, in pygame.display.set_mode.
Also these doc strings seem like overly much since the attributes aren't supposed to be used outside of the class. Why not use normal comments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To help the beginner understand what they put into the "pygame.display.set_mode".
I'm not used to Visual Studio Code but it seems to be the way to make the variableinfo show up when hovering over it?
self.caption = "PopIt" | ||
"""Name of the game.""" | ||
self.frame_rate = 30 | ||
"""Desiered frame rate for the game.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: desired
Also I'd put it at least 60, makes the movement smoother.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
pygame.draw.circle(self.screen, self.color, self.position, self.radius) | ||
|
||
|
||
class Game: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the point of a class if you're just going to call it like a function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To show the beginner that you can make your game or app as a class. In my mind it makes it easier to use the example in teaching. The teacher can ask the student to use the class as "game engine".
|
||
return False | ||
|
||
def blit(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically pygame sprite systems call this draw, imo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I don't understand. You want every ball to be a sprite/circle and not just color/radius/etc.?
if self.position.distance_to(position) < self.radius: | ||
return True | ||
|
||
return False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return self.position.distance_to(position) < self.radius
?
* Object pooling | ||
Balls are not repeatedly created and destroyed but reset. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think is a good feature for an example. Most games need to deal with dynamic amounts of objects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair. I do believe shmups and "Vampire Survivors"-clones are a thing suited for pygame. On old pi's and laptops things get slow fast and can suck the fun out of it for a beginner.
A bunch of the examples are games, they don't start with |
What value does this example provide when we have other "basic game" examples like chimp and aliens? |
Fair. But finding things in the examples are not easy as a young beginner. "Is arraydemo.py a game? It says demo and on steam a demo is a game. Oh a demo can be a kind of example." While making "game_popit" I was asked if I knew where the monkey punching game were. The person did not know that chimp is "monkey". |
I believe that many of the examples that are here now requires you to know more python than a person just discovering pygame might know. If the code is easy to copy/paste and can be built upon with ease maybe more people will find pygame fun at first try. I tried to write a recognizably, beginner and entry level game that you could copy/paste. I think chimp is a perfect example for pygame. It is clean, works great. But questions I got when showing it was: "What is os.path.split and os.path.join? Why do I need image = image.convert(). I just loaded my image." |
Thank you for all the feedback! |
Those are good questions for a beginning user to be asking, because those are important things to know for writing pygame-ce games. |
I agree. But the questions are being asked the same way a teenager ask why they should make their bed or brush their teeth. I'm sharing the experience I had using pygame to inspire a young person to learn python. The person was curious but not motivated. Pygame is an excellent way to learn basic python and I tried to sneak in something extra. Such as classes and pooling to see how far I could push it. Not trying to justify or hype my code, just wanted to share the experience. Appreciate all the feedback and thanks for taking the time to look at the code. If it don't fit the project, don't hesitate to close/cancel the merge. |
PopIt
About
A beginner pygame example about clicking on balls.
Features
Makes it easy to share and copy/paste.
The beginner can read every step in detail.
The main game is contained inside a class.
Balls moves the same speed at different frame rates.
Click on balls to "destroy" them.
The color of the balls are set with random RGB-values.
Balls moves at random speed towards a random target.
Place ball at random position inside a specific area.
Balls are not repeatedly created and destroyed but reset.