Working with PyGame and Python on Mac OS X Lion (10.7.5)

November 29, 2012

So, previously I managed to get my Ubuntu Pygame working in Windows 7 64bit. It was a little difficult to setup because on Windows PyGame expects Python’s IDLE to be 32bit, so I had to install the 32bit version of the IDLE before I was up and running.

Today I decided to test my game on my dad’s secondhand Mac Book Pro 64Bit (2009 model). I ran into many problems and have found the Mac to be just that more harder than Ubuntu and Windows 7 so far. Anyhow, I have to run a slightly older Python IDLE version and PyGame version for things to work out.

After trying many different guides for OS X 10.7, I stumbled upon this blog. The only solution that worked for me: link.

After struggling for a couple of hours, I’ve managed to get my game running properly on the Mac. Everything works. I’ve got my apple falling in a continuous loop. I’ve got my moveable basket on the x-axis. I have collision detected between the apple and basket appropriately. Most importantly, I have my particle system made up of self drawn stars working smoothly on this rather old hardware! It’s only a Core 2 Duo with an Nvidia 9400M GS but with 4GB of DDR3 RAM. I was very worried it might bug out or slow down to extremes, but so far it’s all smooth. The real test of course will be when I have multiple things happening at once such as score updating, particle systems starting and stopping, and multiple apples/fruits dropping and being deleted properly later on. For now though, I am happy the base game works.

Here’s a look at the game running on my Mac Book.

My pre-preAlpha PyGame running on my old MacBook Pro.

Lastly, I found it quite hard to locate ~/.idlerc to put the config-highlight.cfg file into. I dislike the IDLE’s bright white background. So I usually use this guy’s themes: link.

I found that the hidden .idlerc folder is located right inside the Users/Username folder. In my system, my folder is called iptv. Basically I copied my .cfg file in the terminal and directed it into the .idlerc folder, since I couldn’t find any way to make the hidden folder visible in the default file browser window. The following picture is basically the whole process of setting up the .cfg into the right directory for the IDLE to detect it on my system.

Using the Mac Terminal for the first time. Commands are I think almost 100% in similarity to how I use the Ubuntu terminal.

After that, it was just a matter of going into Python’s IDLE and setting it to use the tango theme. IDLE -> Preferences -> Highlighting -> Custom Theme and then selecting tango from the drop down menu. Looks like I’m now set up on all three OS’s, and can start adding further game functionality in the times to come. In the meanwhile, my Unity 3D project and Matlab Audio project are due…


Casual Gaming

November 25, 2012

On all computer platforms, and mobile devices casual gaming is very popular. From business men to 4 year olds.

For this very reason, I figured it would be a good way to start off my first proper 2D game that I make. This is a game I hope to complete and then get it sold on the Ubuntu Software Center. Hopefully, from there the plan would be to get it onto Desura, Gameolith and then Steam Greenlight.

I had previously ventured into using the SDL library with C++ knowledge, but this proved to be quite time consuming and I’d end up focusing more on why my syntax was wrong instead of focusing on making my game logic work right.

This is where PyGame and Python came into play. I had previously messed around with Python a couple of years back in it’s IDLE interpreter and found it fun to play with. Now looking for a serious API, PyGame has become my main tool for developing my 2D casual game.

PyGame and Python are multi-platform, easy to code and have a plethora of additional libraries for me to add more functionality to my game (like Twisted for network etc).

Without further ado, these are some screen shots of my 2D game working on both Ubuntu 12.10 and Windows 7. Note, the art I used here is self made and only temporary. They act as a placeholder while I work out the kinks in my code. I’ll definitely be making better finalized art for the final output, if I can successfully reach there.

Fruit Catcher running on Ubuntu 12.10.

Now running the same code, only slightly modified on Windows 7.

I am well aware that both Python and PyGame itself can be heavy on resources. With this in mind, I have many computers in my household amongst family members that I can test this game on. The lowest specced machine in my grasp is a HP Mini with an Intel GMA 945 chipset. The highest system I have is my current development system, my desktop. An AMD Phenom II x4 with an Asus AMD RadeonHD6870 dual booting W7 and Ubuntu 12.10. If I can successfully make the game run smooth enough on the HP Mini, then I can be certain to make it run great on higher end systems. Only time will tell though, as I get deeper into adding game functions.

To end my post today, my game has only the following functionality:

  • Particle System (shoots stars within a 180 degree range, upwards)
  • Animated Apple (falling down in a loop continously)
  • Collision Detection (my apple hitting the basket, thus triggers the particle system)

I am able to add a self updating text unit on the top of the screen for the score, but have yet to implement it in Fruit Catcher. One
issue I currently have is that sound that plays fine in Ubuntu 12.10 in PyGame, does not play in Windows 7. I am not yet sure if this is
because of my sound file format, or if Windows 7 doesn’t play well with PyGame.


The Sketch

November 24, 2012

Whenever I have ideas now, I make it a point to write it down on paper and draw it out if possible. That’s exactly what I did for my first Gtk+3 application. If I hadn’t drawn it out, I wouldn’t have pushed myself to further learn how Gtk+3 works, or what the function calls look like in Python. I have myself a folder of ideas now, useful for possible future applications.

How it looks to start an idea out on paper.


The Revival

November 23, 2012

I first made this blog back in 2009. Back then, I was completely clueless on how to go about setting up this wordpress account.
However, recently a friend of mine started a wordpress blog of his own. This reminded me about this blog. To top it off, in a year or so I may be finishing my Software Engineering & Games Design degree.

To this point, it would probably be wise to have a sort of online archive of whatever accomplishments I have made or have striven to make during my studies or on my own time. This could become beneficial when job hunting!

So, on with the content! In this past year I’ve learned how to use Gtk +3, an API that helps you create Linux GUI applications. Since I had some form of Python programming background due to messing around with Pygame, it wasn’t that hard to start myself up on this. Here’s the chronology of how I made my first (rather) proper GUI using Gtk +3 in images:

The humble beginnings, guided by tutorials.

This was my beginning. I programmed this in Python’s IDLE 2.7 on Ubuntu.

More ambitious adventuring begins with my small modifications.

This is where I began to stray from the tutorials guiding hand. I added new rows and columns using the table functionality as wisely as possible. Before I discovered GtkImage, I simply used GtkButtons as placeholder’s for what I had imagined. Hence the large logo button on the left.

Messing around even further with buttons.

Now, I further delved into what GtkButton could do. Using the stock Gtk+3 icons, I added the Record, Pause and Stop icons to the buttons. This wasn’t good enough for me, I wanted the text gone! Just simple buttons with icons on them. So I moved on.

Closest to the final GUI I’ve reached thus far.

It looks oversized, I know. However, this was a big milestone for me. I managed to replace the GtkButton on the left with the GtkWidget and load my own image into it. The best part would have to be the fact that I added my own Record, Pause, and Stop icons to my button using GtkButton.set_image(GtkWidget *image). Specifically, for the record button I did:

self.image_record = Gtk.Image()
self.image_record.set_from_file("images/record_button.png")
button_record.set_image(self.image_record)

The reason I decided to start making this application is that I needed a proper system sound recorder, not one of those microphone recording software. Functionality in my application is currently scarce. I have coded into it the ability to save on any location on disc, and I can send Ubuntu a request for a notification to be called via a bash script. However, actually recording the system’s audio is a lot harder than I imagined. I’ve looked into PyAudio and using Sox in a bash script, and have only managed to make PyAudio record from my microphone. Hopefully in the future I’ll discover how to complete this application properly. For now, it’s on to more learning!

These links could be useful for myself as a reminder in the future, or you the reader if Gtk+3 ever piques your interest.
Python Gtk+3 Tutorials
Official Gtk+3 Documentation (in C++, so you’ll have to figure out what it looks like in Python)