Turbo-Frambozenbier
Posts: 40
Joined: Sun Jan 22, 2012 5:41 pm
Contact: Website

Re: RasPi Space Invader- PDF and source code

Tue Apr 17, 2012 10:09 pm

Hi,

For all of you lucky people who have already got a RasPi (or those who know how to install pygame on Linux or Windows), Mark Tranter has produced a RasPi Space Invader game based on the Pi Shooter tutorials Liam Fraser has been producing on his YouTube channel.

It's on the front page here:

http://www.frambozenbier.org


User avatar
meltwater
Posts: 1014
Joined: Tue Oct 18, 2011 11:38 am

Re: RasPi Space Invader- PDF and source code

Tue May 01, 2012 9:35 pm

Spotted this earlier, can't wait to try out!  Great work.
______________
http://www.themagpi.com/
A Magazine for Raspberry Pi Users
Read Online or Download for Free.

My new book: goo.gl/dmVtsc

Meltwater's Pi Hardware - pihardware.com

Like the MagPi? @TheMagP1 @TheMagPiTeam

User avatar
Jim Manley
Posts: 1593
Joined: Thu Feb 23, 2012 8:41 pm
Location: SillyCon Valley, California, and Powell, Wyoming, USA, plus The Universe
Contact: Website

Re: RasPi Space Invader- PDF and source code

Wed May 02, 2012 3:23 am

So, running the game (or any game with sound) out of the box on a Pi running Debian results in the following errors. I haven"t looked, but, I"m guessing a sound driver needs to be installed?

ALSA lib confmisc.c:768:(parse_card) cannot find card "0"
ALSA lib conf.c:4170:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4170:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1251:(snd_func_refer) error evaluating name
ALSA lib conf.c:4170:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4649:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2190:(snd_pcm_open_noupdate) Unknown PCM default
Traceback (most recent call last):
File "invader2.py", line 15, in

laser = pygame.mixer.Sound("laser.wav")
pygame.error: mixer system not initialized
The best things in life aren't things ... but, a Pi comes pretty darned close! :D
"Education is not the filling of a pail, but the lighting of a fire." -- W.B. Yeats
In theory, theory & practice are the same - in practice, they aren't!!!

User avatar
grumpyoldgit
Posts: 1454
Joined: Thu Jan 05, 2012 12:20 pm

Re: RasPi Space Invader- PDF and source code

Wed May 02, 2012 8:55 am

I've tried it out on my Ubuntu 12.04 setup and had great fun. I am very impressed at what can be achieved with a few lines of code. I really need to sit down and concentrate on those Python tutorials!

User avatar
oztrailrider
Posts: 55
Joined: Sat Jan 14, 2012 3:21 am

Re: RasPi Space Invader- PDF and source code

Wed May 02, 2012 9:25 am

Great work, I look forward to trying out this tutorial and messing with it when I get my pi. This is exactly the sort of thing that will really help kids to learn programming, allowing them to make changes to the code and see how it affects the program when executing it.

toxibunny
Posts: 1383
Joined: Thu Aug 18, 2011 9:21 pm

Re: RasPi Space Invader- PDF and source code

Wed May 02, 2012 11:01 am

Tried to look at the source code, get a tar.gz file containing something called 'tartmp.DbmPKW'. What gives?
note: I may or may not know what I'm talking about...

liamfraser280
Posts: 354
Joined: Tue Oct 04, 2011 6:53 pm
Contact: Website

Re: RasPi Space Invader- PDF and source code

Wed May 02, 2012 11:04 am

The sound problem is because the alsa module isn"t loaded. Could do with adding some error handling code a time the beginning so that it doesn"t crash if there is no alsa module loaded.

You should be able to load it on Debian by running modprobe snd_bcm2835. Its currently disabled at boot because it is still in alpha development.

User avatar
Jim Manley
Posts: 1593
Joined: Thu Feb 23, 2012 8:41 pm
Location: SillyCon Valley, California, and Powell, Wyoming, USA, plus The Universe
Contact: Website

Re: RasPi Space Invader- PDF and source code

Wed May 02, 2012 1:03 pm

Hi Liam,

No joy after the modprobe.  I did an apt-get install alsa-utils, but, still nothing.

I found the http://www.raspberrypi.org/for.....sa-drivers thread and it looks like sound is pretty much screwed indefinitely.

This is an example of why we can't even consider promoting the Pi for the educational sector until basic functions like this are all resolved.  Teachers aren't going to be able to deal with this kind of problem, and even the most curious nerd students are going to be puzzled.
The best things in life aren't things ... but, a Pi comes pretty darned close! :D
"Education is not the filling of a pail, but the lighting of a fire." -- W.B. Yeats
In theory, theory & practice are the same - in practice, they aren't!!!

antiloquax
Posts: 406
Joined: Sun Nov 20, 2011 11:37 am
Contact: Website

Re: RasPi Space Invader- PDF and source code

Wed May 02, 2012 4:12 pm

toxibunny said:


Tried to look at the source code, get a tar.gz file containing something called 'tartmp.DbmPKW'. What gives?


The tar.gz file is a Linux archive. You can extract it easily in any Linux machine with:


tar -zxvf <filename>


This page has links to some programs that will extract such archives in Windows.

Thanks to Liam for trying to sort out the sound problems. I haven't got an RPi yet, so I can't give any more help yet. I'll check in my qemu version later. Sound is handled in Pygame by "sdl mixer", I think. I wonder if that could be the issue. In the mean-time, you could comment out the sound lines. I'll also have a go at some error-handling, if I can't fix it any other way.

Thanks to everyone for having a go with this!

antiloquax

liamfraser280
Posts: 354
Joined: Tue Oct 04, 2011 6:53 pm
Contact: Website

Re: RasPi Space Invader- PDF and source code

Wed May 02, 2012 4:21 pm

Something like this would probably do it

# Somewhere near the start

if not pygame.mixer or not pygame.mixer.get_init():

sound = FALSE

# When playing or doing anything to do with sound

if sound:

# Code to play sound

(Don't know how to do the code box thing properly!)

antiloquax
Posts: 406
Joined: Sun Nov 20, 2011 11:37 am
Contact: Website

Re: RasPi Space Invader- PDF and source code

Wed May 02, 2012 5:20 pm

Thanks Liam

liamfraser280
Posts: 354
Joined: Tue Oct 04, 2011 6:53 pm
Contact: Website

Re: RasPi Space Invader- PDF and source code

Wed May 02, 2012 5:25 pm

No worries

antiloquax
Posts: 406
Joined: Sun Nov 20, 2011 11:37 am
Contact: Website

Re: RasPi Space Invader- PDF and source code

Wed May 02, 2012 5:32 pm

I haven't got my sound set up yet in my qemu pi. But I think the problem is that you have to initialise mixer after creating the display on some systems.

If I add:


pygame.mixer.init()


just before the lines that load the sounds, I don't get the mixer not initialised message (instead I get a "no audio device" at the moment!). But if your sound is on, this should work.

mark

User avatar
cheery
Posts: 219
Joined: Wed Jan 25, 2012 9:39 pm

Re: RasPi Space Invader- PDF and source code

Wed May 02, 2012 6:48 pm

I'll take a review on it once I'm done with other rpi related things. Should be able to appraise it's usefulness. Thank you from sharing.

antiloquax
Posts: 406
Joined: Sun Nov 20, 2011 11:37 am
Contact: Website

Re: RasPi Space Invader- PDF and source code

Wed May 02, 2012 6:51 pm

By the way, I don't know how closely the performance of the different releases under qemu reflects the way that the RPi itself will run, but Arch is much facter than Debian.

For an example, I ran glxgears on my qemu-debian and got about 9.5 frames per second. The arch OS runs at just over 16 fps.


User avatar
cheery
Posts: 219
Joined: Wed Jan 25, 2012 9:39 pm

Re: RasPi Space Invader- PDF and source code

Wed May 02, 2012 8:45 pm

All right. My analysis of this material concluded.

The PDF is horrible. Please pay more attention to make it clear what is code and what is not. It also has a fundamental problem, that it doesn"t create value to the example. Instructions should motivate reader and explain things that plain code cannot explain properly.

The example in itself stands out okay. I"d say it"s of average quality as you could write cleaner code with python. Linus has a good rule here. Linus says that if your code nests more than 3 levels you"'ve screwed it. Your code works outside of raspberry pi, that"s okay, but it just hints that you made a fancy wrapping into an existing python example.

Structure of the file is terrible – it's a tarbomb! Also you have no structure you monster! That alone will make it more tedious to extend along from this project. Inside the tar file you should create this kind of structure:


invader/assets/ – directory that gets all the images and wav files
invader/invader.py – clear name for the main source file
invader/doc/ – all the documentation you provide
invader/ – directory name comes from invader.tar.gz

Get right back into draft table. You can do better than this! Do it.

User avatar
abishur
Posts: 4478
Joined: Thu Jul 28, 2011 4:10 am
Location: USA
Contact: Website

Re: RasPi Space Invader- PDF and source code

Wed May 02, 2012 9:32 pm

Yikes!  Let's be sure to keep our critiques uplifting here   The internet looses all inflection so it's very easy for something that is meant to be light hearted to come across as biting
Dear forum: Play nice ;-)

antiloquax
Posts: 406
Joined: Sun Nov 20, 2011 11:37 am
Contact: Website

Re: RasPi Space Invader- PDF and source code

Wed May 02, 2012 9:48 pm

cheery said:

Thanks for your comments, cheery.

This was pretty much the first game I wrote. I know that it's not a very elegant program. As I think I mentioned in the text file, I'm aware of some of its shortcomings. Basically I just hacked away until it did what I wanted. I'll do better next time.

As for the .pdf - in my original document, the code was formatted in monospace and the main text in (I think) century gothic. This seems to have got lost in translation. You're right, it does make it less easy to follow.

Thanks also for your comments on the tarball. I did just put all the files in together - I had no idea that was seen as poor form.

I am learning as I go. Until I heard Eben on the Radio late last year, I hadn't done any programming since the 1980s.

Anyway, thanks for taking the time to read and respond.


User avatar
Jim Manley
Posts: 1593
Joined: Thu Feb 23, 2012 8:41 pm
Location: SillyCon Valley, California, and Powell, Wyoming, USA, plus The Universe
Contact: Website

Re: RasPi Space Invader- PDF and source code

Wed May 02, 2012 9:57 pm

Well, at least he put a smiley at the end. Most people think I use too many, and when I don"t, the thought police come out of the woodwork and note my IP address

My point about this is that we _all_need to start thinking about how the noobs are going to view this sort of thing. If we _know_ there are issues, we need to at least note them, if not outright put in a workaround for a (semi-)broken feature.

This is why, when I"m teaching software engineering implementation (we"re not just programming any more, Toto ), I tell my students to write as many error-handling routines as they can think of before they even think about writing a single line of actual functional code. No one can think of everything that can go wrong up front (except Murphy, of course), but, if you get used to being paranoid early on, you will not only make your own life easier, but also that of potentially dozens, hundreds, thousands, or even millions who may wind up using/adapting/integrating your code. Bad habits always start way too early, and good habits can"t be started early enough.

I won"t go into detail here how I teach students how backing up is vital, but, let"s just say that, after losing a full day"s worth of work after I intentionally delete their originals, those who didn"t back up never forget to again!
The best things in life aren't things ... but, a Pi comes pretty darned close! :D
"Education is not the filling of a pail, but the lighting of a fire." -- W.B. Yeats
In theory, theory & practice are the same - in practice, they aren't!!!

Turbo-Frambozenbier
Posts: 40
Joined: Sun Jan 22, 2012 5:41 pm
Contact: Website

Re: RasPi Space Invader- PDF and source code

Thu May 03, 2012 12:05 am

Hi,

I've been following the conversation on my phone tonight and decided to reply when I got home. Firstly, I work on the Frambozenbier website so I should declare that up-front.

1) Your right about the font and the readability, that could be improved.

2) Your right that this might not be a text book example of how to code in Phyton.

We will look at correcting the format, but we wont make any apollogies for publishing a tutotorial writen by somebody who hasn't done any programing like this for almost 30 years until a device like the RasPi came along to re-awaken his enthusiam, and other tutorials like Liams gave him the confidence to start writing something like this himself.

For those who dont know this game was based on Liam Frasers RasPi shooter examples, even though they dont look anything like each other now. This is exactly how I learned to code, I didn't write a masterpiece on day one, I just modified other examples to make small changes one at a time.

Thousands of text book have been available over the years on creating the perfect code, but in my opinion these prescriptive guides have contributed to lots of people being too afraid to try and pick up coding, and NOT becoming interested in IT, the learning curve is just too steep if you aim for "perfect code" on day one.

I think we should be telling people it's ok to make mistakes, it's ok to have four or five levels of indentation or structure if it means you learned something you would otherwise not had the confidence to try.

The Ramones were not the most technical band ever put together, but they encouraged a whole other generation of bands like Metalica to form becuase they made it ok to "just give it a go" without having to master the art to perfection first, they made it ok to be a "work in progress". I'd like to think that they helped people to become professional musicians, not hindered?

We like the people who aren't afraid to try something new and give it a go at Frambozenbier, we think thats essentially why the RasPi and the foundation exists, and anyone who learns something new and wants to share it with others is welcome to send us a howto, tutorial, or example at we'll do our best to help them and make it avialable to others. ( articles @ frambozenbier.org )

Frambozenbier literally means "Raspberry Homebrew" and promotes the DIY aspect, so it might not be the best place for professional programmers and teachers to look for best practice examples, but it might could be just the thing you need if you are a newbie who is keen to learn and wants to take a working example and modify it to make it do something else and create something new within a few hours of coding.

I think these examples are just the kind of thing that Liz, Eben and the other members of the foundation were hoping to see people create, so in that sense I think it's a win, and every person that does find it useful is one person that is getting exited about IT that we might otherwise have lost.

(I'm going to stop typing here as my kebab is getting cold)

Turbo

toxibunny
Posts: 1383
Joined: Thu Aug 18, 2011 9:21 pm

Re: RasPi Space Invader- PDF and source code

Thu May 03, 2012 12:58 am

I"m not *too* far off releasing my first pygame game. Hoping for a review from cheery when I get it posted >:]•
note: I may or may not know what I'm talking about...

User avatar
grumpyoldgit
Posts: 1454
Joined: Thu Jan 05, 2012 12:20 pm

Re: RasPi Space Invader- PDF and source code

Thu May 03, 2012 7:54 am

Cheery by name .........

User avatar
meltwater
Posts: 1014
Joined: Tue Oct 18, 2011 11:38 am

Re: RasPi Space Invader- PDF and source code

Thu May 03, 2012 8:23 am

Yep, I think people need to remember that just because people on here are willing to help out beginners it does not mean any of us claim to be world experts (in a lot of cases it is people who are learning in just the same way as the reader, but perhaps a few steps further on).

While the comments may indeed be correct, the context is not.

If the article was in a highly expensive text book or within an accredited course then you would have some cause for complaint.  There is a reason why good training is not free and why people spend 3 or 4 years of their life going to university and why employers will often favour those who have.  This is so that people are taught the right way to do things (mostly), or often a company will re-train you to do things the right way, but appreciate you are more than capable of learning quickly those extra bits.

However, there is huge value in sharing your learning experiences with others and for beginners to gain from your efforts.  That is the whole point of the Raspberry Pi community after-all.

Cheery, any chance you would like to write some articles about good programming practice, defensive programming etc for beginners, I"m sure it would be really helpful for others to learn.  I"m sure if they are good, then Frambozenbier will be willing to feature them, as would the MagPi.

The same offer is open to anyone else too, just to be clear.
______________
http://www.themagpi.com/
A Magazine for Raspberry Pi Users
Read Online or Download for Free.

My new book: goo.gl/dmVtsc

Meltwater's Pi Hardware - pihardware.com

Like the MagPi? @TheMagP1 @TheMagPiTeam

User avatar
SN
Posts: 1012
Joined: Mon Feb 13, 2012 8:06 pm
Location: Romiley, UK
Contact: Website

Re: RasPi Space Invader- PDF and source code

Thu May 03, 2012 8:49 am

I'm going to defend cheery here… look where he is from, Finland.  English is not his first language so don't expect him to be using the more subtle expressions in our language to a level that you might want in a critique (and to be fair he's right, the layout and code/commentary layout is very poor though the words and intent are good).

And lets not forget… Finns have never renowned as the most cheery of personalities… <– important wink smiley, defuses many an unintended internet storm in a teacup
Steve N – binatone mk4->intellivision->zx81->spectrum->cbm64->cpc6128->520stfm->pc->raspi ?

antiloquax
Posts: 406
Joined: Sun Nov 20, 2011 11:37 am
Contact: Website

Re: RasPi Space Invader- PDF and source code

Thu May 03, 2012 9:00 am

Well, I am wishing now that I had spent a bit more time on the code and the text description before passing it on to Frambozenbier. [hangs head in shame]

I will try to revise the whole thing as soon as possible and re-submit it!

mark

Return to “General discussion”

Who is online

Users browsing this forum: dcaccount, HermannSW, InterlightTechnology, k-pi and 41 guests