My modifications to Liam Fraser’s PiShooter

I am a big fan of Liam Fraser’s tutorials on YouTube. I wanted to change PiShooter so that there was an explosion when you hit the Pi. I made a few changes to Liam’s code. Becuase I am only just getting to grips with pygame, I didn’t make a class for my explosion – I just found a “quick and dirty” was to achieve my goal.

First,  I loaded up an explosion image into “boom”.

Then I added a bit to the collision detection part.

I stored the location of the shot in x1 and y1. Then, if there was a hit, I killed the Pi sprite and made a new one (so the one we hit disappears and a new one begins again at x=0. I’ve made a variable “count” and then in the main loop I blit the explosion to the screen for 20 frames. On my computer this is enough to make the explosion visible (but my laptop is pretty slow!)

antiloquax

Advertisements

Tags: , ,

3 Responses to “My modifications to Liam Fraser’s PiShooter”

  1. Des. Says:

    Hi antiloquax,
    I am fast becoming a fan of your listings and comments relating to the Raspberry-pi and python. I have a 10 week (approx) wait for my pi to arrive so I downloaded racey2 (first class by the way) and am currently enjoying getting to grips with python.

    With respect to your python code snips etc would it be possible to place them on the page as text files so the code snips can be cut-n-pasted into an editor? The reason I ask is because I find I often find some of the images difficult to read.

    Thanks for sharing your skill and posting the code.

    Kind regards,
    Des (57 yr old Raspi-fan)

  2. antiloquax Says:

    Thanks for your comment. I think i have tended to use images as i like the code highlighting that gets lost if you just post up the text. I’ll try putting any future code on as text though as readability is more important i suppose.
    I hope you get your pi soon des! 🙂

  3. Des Says:

    Hi again antiloquax,
    Thanks for the reply and until my real-pi arrives I will continue with racypi2 and the “virtual-pi” coding which is great fun. Have been a puppy fan for some time now so this is just icing on the cake (pie?) and while I wait for the raspi to arrive I will continue to enjoy your tutorials.
    Thanks again for posting and sharing.
    Best wishes.
    Des.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: