Saturday, 20 July 2019

Simple PyGame Zero Apollo Lander #Apollo50th

With all the excitement of the 50th Anniversary of the first Moon Landing and the world record attempt Moonhack https://moonhack.com/, I wanted to experiment with PyGame Zero a little more. So I created my own, very simple, Moon Lander game using Python and PyGame Zero.

The lander has to pass through a red rectangle on the surface as it accelerates to the surface. Left and Right keys move it sideways and the up key gives it a boost. When the lander passes through the red rectangle it makes a noise; if it misses (or after it passes through the rectangle) it resets to a new position and starts again.

Two images were needed




An image from the game, the code and a link to the repository are shown below, please feel free to unzip the code and use it. It is a simple game and there is scope to improve (please feel free to do it - I would love to see it improve).







Repository https://github.com/scottturneruon/moonlander/archive/v1.0.zip


Resources
  1. Welcome to Pygame Zero https://pygame-zero.readthedocs.io/en/stable/
  2. Introduction to Pygame Zero https://pygame-zero.readthedocs.io/en/stable/introduction.html
  3. Built-in Objects - Pygame Zero https://pygame-zero.readthedocs.io/en/stable/builtins.html
  4. Space Asteroids - Pygame Zero http://www.penguintutor.com/projects/docs/space-asteroids-pgzero.pdf
  5. Pygame Zero Invaders https://www.raspberrypi.org/magpi/pygame-zero-invaders/
  6. Pygame Zero: SpaceInvaders II https://www.raspberrypi.org/magpi/pygame-zero-space-invaders-ii/
  7. My first PyGame attempt https://robotsandphysicalcomputing.blogspot.com/2019/07/my-first-pygame-zero-attempt.html
  8. Moon Hacks https://moonhack.com/


Cool book on the Moon Missions with Augmented Reality


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

Thursday, 4 July 2019

Cool Adafruit PyGamer #1

I seem to play with Games software more and more (e.g. the recent post My first Pygame zero attempt ) and that is not a problem at all. This post is another one.




The most recent AdaBox from Adafruit (see above) was based around their PyGamer Starter Kit and it is great fun. This is a microcontroller based, open-source Retro gaming emulator; or is it a cool handheld gaming device that you can write your own games for.




It can be programmed in CircuitPython, Arduino, but I been trying it out in the Beta version of MakeCode Arcade and if you have used MakeCode for the microbit this very much the same (see below).





A nice feature about this is you can share - this code example (shown above) was developed by my son (and is shared with his permission) after about an hour of playing - the emulator below shows the game in action.




My future plans with it so far:
- Investigated the features available in MakeCode Arcade for this console;
- Play with it using CircuitPython


In summary, a really nice bit of kit, that I think has lots of potential to explore.


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

Tuesday, 2 July 2019

My first Pygame zero attempt

I attended the brilliant #ExaBytes19 on 28th June 2019, among many very good sessions, I went to Jon Witts (@jonwitts) session on PyGame Zero [1]. Pygame zero is meant for Educational use and teaching programming through game development. Impressed with Pygame Zero relative simplicity, I have had a go myself.

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

I enjoyed playing with it, thank Jon for sharing this.


Resources

  1. Welcome to Pygame Zero https://pygame-zero.readthedocs.io/en/stable/
  2. Introduction to Pygame Zero https://pygame-zero.readthedocs.io/en/stable/introduction.html
  3. Built-in Objects - Pygame Zero https://pygame-zero.readthedocs.io/en/stable/builtins.html
  4. Space Asteroids - Pygame Zero http://www.penguintutor.com/projects/docs/space-asteroids-pgzero.pdf
  5. Pygame Zero Invaders https://www.raspberrypi.org/magpi/pygame-zero-invaders/
  6. 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

Who wants to produce AI produced cartoon strips

Question: How easy is it produce a comic/cartoon using genetative AI? Let's start with  using ChatGPT4o to produce cartoons. The idea wa...