Galcon Games
Phil Hassey - game dev blog
Phil Hassey as Snidely Whiplash
"You can't buy awesomeness.
You're born that way."

Elephants! is free on the App Store!

My gift to you: A totally FREE iPhone game! I made this game several years ago with some other way-cool game-dev friends. In “Elephants!” you save the giraffes while jumping on a rolled up squirrel! More fun than a barrel of pigeons! For Christmas this year I figured I’d port it over to the iPhone for you :) Check it out!

From the dev side, yeah, this is my first attempt at “python” on the iPhone. Even though it’s actually restricted tinypy code. Here’s a sample of game code so you get the idea of what’s behind this game. All this code is converted by tinypy into C++ code so I can compile it with Xcode for the iPhone:

def elephant_new(g:Level,pos:List(int))->Sprite:
    s = Sprite('elephant',pygame.Rect(43-14,8,28,48))
    s.rect.set_centerx(pos[0])
    s.rect.set_bottom(pos[1])
    
    g.sprites.append(s)
    
    s.ball = ball_new(g,(int(s.rect.get_centerx()),int(s.rect.get_bottom())))
    s.suit = ElephantSuit()
    s.vy = 0
    s.vx = 0
    s.jump = 0 
    s.facing = 'e'
    s.score = 0
    s.z = 1
    s.state = 'live'
    s.name = 'elephant'
    
    return s

5 Responses to “Elephants! is free on the App Store!”

  1. Rene Dudfield Says:

    Nice one Mr Hassey.

    The annotated python looks ok.

    Just wondering if you prototyped first with cpython and then moved towards the tinypyC++ version? I guess you iterated between the two.

    Also, have you worked much on error messages? At least so it can tell you what type a method is expecting?

    I imagine this line:
    s.ball = ball_new(g,(int(s.rect.get_centerx()),int(s.rect.get_bottom())))

    Could get the float returned by get_centerx() to cooerce into an int automatically perhaps. However, I would kind of like int and float to be separate some times.

    cu,

  2. philhassey Says:

    @Rene:

    This game was originally written in python a few years ago (see http://www.imitationpickles.org/elephants/ ). I took that code and ported it over.

    I do give error messages for any improper types being used in tinypy, and for wrong number of parameters, etc.

    However, within tinypy, an int and a float are both the same type. This is for a number of reasons:

    - in python3 (and in python2, to a lesser extent) ints can automagically get converted to floats pretty easily. Having ints be a different type yielded non-pythonic results.
    - Having them different types could give you some really painful situations, mainly in the case of passing a List(int) to a List(float), those types don’t auto-convert in C++ (without extra code, anyways, which would add more overhead to all those calls)
    - I do have explicit C types available, such as int16, uint32, etc, so if you REALLY want to use a C-int, you can. I might also add float32 and float64 so you can choose between those as well.

    So yeah, you can do what you want, but for “int” and “float” I decided to keep the code as similar to python as possible. When I “release” this project I’ll have to write up some documentation (or copy this blog comment) emphasizing this point since it is a good question. And probably the design decision that was the hardest to make.

    -Phil

  3. Who Cares Says:

    Hi there
    I’m surprised there is a way to create iPhone apps out of Phyton. Just wondering how hassle free you can compile and run it(?).
    I was long into Pygame and hope to return once a day, still loving it!
    In between I met Unity 3D, which went free recently (Indie version). It includes a very powerfull 3D engine (3D physics as well) and allows you do script in BooPython, Javascript and Mono. You really can build a game out of the “Build” button for Windows and Mac. For the iPhone you need an additional plugin, which cost some bugs.
    Altough you have to learn many things again (escpecially for 3D envs) it gives you the same feeling as Pygame (take out the pain of coding).
    http://unity3d.com/

  4. Oscar Says:

    Hi Phil,

    Did you consider using Shed Skin instead of tinypy? I have not really looked into it, but I’d like to try using python for mosync (which only supports c/c++ at the moment).

    Did you do some comparison before you went with tinypy? In that case, it would be interesting to read about it.

  5. philhassey Says:

    @Who Cares: yeah I’ve been considering using Unity for some projects as well. It’d be even nicer if it had the support for Boo on the iPhone.

    @Oscar: Well, I made tinypy, so that was a bit of bias. I think if you look back a post here I cover some of my reasons. I think the biggest one was that ShedSkin depends on libgc, which was a dependency I wanted to avoid. I don’t have any speed comparisons, but I do know that ShedSkin IS more like python than tinypyC++. tinypyC++ requires annotation of all functions, whereas ShedSkin has the smarts to infer everything.


Galcon   Watermelons   Dynamite   The Hairy Chestival
All content of imitation pickles (c) 1999-2008 - Phil Hassey  "we care"