Skip to main content


A challenging physics based puzzle game where you use magnets to maneuver balls through a series of levels.

Paul Paterson

On each level you must find a way to guide a number of different coloured balls to their destination zones by using a series of magnets or by nudging the table. Watch out for hazards and the perilous purple balls!

Requires: Python 2.6+, pygame 1.9+ and pymunk 1.0



Home Page


Magnetospheres 0.1.2 — 9 Jun, 2011

Magnetospheres 0.2 — 18 Jun, 2011

Magnetospheres 0.2a — 28 Oct, 2011 account Comments

  • Jouni Järvinen 2011-06-18 17:49:12

    Got a load of tips for you:
    - Bz2-compressed tar is much better than gz-compressed.

    - Using an §import§ for each importable thing is full waste.

    - If you have more than one var' which'll be identical on init', just do §var1 = var2 = var3 = []§. Note that the same trick doesn't work for vars prefixed with §self.§

    - Your codes have much unnecessary indentations.

    - For better readibility & faster comprehensing, instead of using just one "#" to comment out a code line, use two of them, to clearly separate them from comments, especially when using the search feature.

    - To improve readability, don't add spaces inside a tuple, like §(125, 167)§, but don't do the same for the whole tuple like §('blue',(300,490)),§ or inside a function's tuple like §random.randrange(200,900)§, as it decreases readibility and slows down ability of comprehension.

    - If your list won't be modified while running the program, instead make it into a tuple for higher performance.

    - Since the program is coded in Py v2.6, the Ternary Conditional Operations are very useful to cut down on repeated code. Specifically the lines 105-113 in the file "" could use that. "".

    - As continuation to the above, ne noted that TCO is meant as replacement for if(-elif)-else controlling calls doing almost the same thing, meaning usage in single function calls, which weren't controlled by if-elif-else or if-else, won't work, just like use of List Comprehensions in function calls not expecting a list is wrong in terms of resultant result while in terms of syntax it's not wrong.

    - As continuation to the above, the lines 32-39 in the file "" could be replaced by TCO. The same can't be done with the lines 77-83 in the same file but with the lines 94-99 & 105-114 it can. You seem to have used TCO in the file "".

    - It is your own but the ":" used in dicts makes more sense if there is no spaces in either side of the character.

    Paul Paterson 2011-06-18 19:44:42

    Thanks for the tips and good advice. I'll try the Bz2 compression - this could bring the size down quite nicely.

    As you noted, I'm a spaced-out kind of guy! I like my spaces around commas and colons and indentation. You comments are interesting though and it has triggered me to do some research into what other people think of readability in Python. 

    You are right with the TCO comments. I've come through the Python 2.1+ days and so this operator is something that I don't always think of and when I do I tend to be a bit cautious in its usage. I think that you are right though, in the places you highlighted this operator would make it clearer that the code is really just selecting a value.

    Your comment on the tuple is also interesting. I once read a quote from Guido that said that he intended tuples for inhomogeous data and that he recommended lists for homogenous data even when the list would not vary. I never quite bought into that 100% but at the same time it does tend to lean me towards lists most of the time. 

    In general I agree on the multiple initialization, although there are some nasty little gotchas like in your example code,

    a = b = []

    Now b is [1] as well as a, which may not the intention!

    Thanks again for the tips and comments. It is always great to get such good feedback on my code.

    Jouni Järvinen 2011-06-18 21:54:55

    Wow, I didn't know that append would affect the §b§ too if they're initialized at once; I tested and it is so even in Py v2.7.1 & v3.1.4 I have. Thank you for bringing this into my attention.

  • Jean-Patrick Pommier 2011-09-08 09:07:00

    The window doe not fit my screen (1024x768) under ubuntu 10.10

  • Idonthaveamail 2011-10-29 13:12:51

    I just want you to know that i have learned a good lot from your game.

    Paul Paterson 2011-10-29 14:46:46

    I'm glad you found it useful!



  • Mekire 2011-12-21 16:01:09

    Excellent game.  Seems like it would be amazing if you could get it to work on the new big touch screen desktops (I unfortunately don't have one though).

    Wanted to let you know that apparently the new version of pymunk has made a slight change and you get the error:
    AttributeError: 'module' object has no attribute 'init_pymunk'

    The file in the serge directory no longer needs line 9:

    After commenting that line out it worked perfectly.
    This was using python 2.7 and pymunk 2.1.0 on a Windows 7 system.


    Paul Paterson 2011-12-21 17:30:48

    Thanks - a touch screen would work very well for this kind of game. Unfortunately I don't have one either - maybe there will be one under the Christmas tree this year!

    Thanks for the error report, details and fix on pymunk - I'll put a version check and change in to cope with that.