The Game!
A Bee buzzes around the screen and a player moves to avoid it; if the bee and player meet the player's image changes and a sneezing sound is produced (I just fancied have a short cute noise). Both the bee and the player characters wrap around the screen.
A very helpful source of advice on getting started on using Pygame can be found at [2]; my example takes the game produced there as a starting point. If you want to explain of what Pygame does previously mentioned page[1] and the page describing the built-in functions [3], I found a great help.
All the images were PNGs, the player characters were produced using https://www.bitmoji.com/ .
The game code is shown below; all images have to be put in an image folder and the sounds in a sounds folder.
Liked especially that the image for a character (or Actor) can be changed very easily. Collision detection can be done in a few ways but I selected for simplicity the idea that each image has a rectangle around it and used this say when they meet, as in the example below.
if bee.colliderect(player):
player_hurt()
Code, images, etc are available at: https://github.com/scottturneruon/pygame_tests
As background, the following were interesting and provide further useful information and tips
- Space Asteroids - Pygame Zero http://www.penguintutor.com/projects/docs/space-asteroids-pgzero.pdf
- Pygame Zero Invaders https://www.raspberrypi.org/magpi/pygame-zero-invaders/
- Pygame Zero: SpaceInvaders II https://www.raspberrypi.org/magpi/pygame-zero-space-invaders-ii/
I enjoyed playing with it, thank Jon for sharing this.
Resources
- Welcome to Pygame Zero https://pygame-zero.readthedocs.io/en/stable/
- Introduction to Pygame Zero https://pygame-zero.readthedocs.io/en/stable/introduction.html
- Built-in Objects - Pygame Zero https://pygame-zero.readthedocs.io/en/stable/builtins.html
- Space Asteroids - Pygame Zero http://www.penguintutor.com/projects/docs/space-asteroids-pgzero.pdf
- Pygame Zero Invaders https://www.raspberrypi.org/magpi/pygame-zero-invaders/
- Pygame Zero: SpaceInvaders II https://www.raspberrypi.org/magpi/pygame-zero-space-invaders-ii/
All opinions in this blog are the Author's and should not in any way be seen as reflecting the views of any organisation the Author has any association with. Twitter @scottturneruon
Glad you enjoyed the session Scott! I am going to have a play around with your program, it looks pretty cool!
ReplyDeleteThanks.....
ReplyDeleterobot kit
Robotics in Education
Educational robotics
Very informative!!!!
ReplyDeleterobot kit
keep posting..wonderful blog..
ReplyDelete3d printing materials
3d printed products
3d prototyping
thanks for sharing information,good blog..
ReplyDeleterobot kit
Robotics in Education
Educational robotics
Thanks for sharing. Amazing content.
ReplyDeleterobot kit