Sunday, August 25, 2013

Installing Pygame Subset for Android


I noticed that a new version of pgs4a came out.  I upgraded from 0.9.4 to 0.9.6 this morning.  The process went smoothly on my Ubuntu 12.04 LTS system.  I was up and running in 10 minutes and my programs ran with no problems.

Since the installation on Linux normally goes fine, I suspect that many of the problems people have with pgs4a is not due to the installation, but due to usage.

Here are three common problems I've heard about:

1) You're not specifying the directory of your application.  Many people will configure and build the name of the python file.  This is wrong.  You need to specify the name of the directory.


The location specified after build is the name of the directory, not the file.

2) You didn't name your main python file main.py.   You may have called the file something like runner.py or angryfish.py.  This is wrong.  The file needs to be called main.py.

3) You didn't initialize the android library in  your python code.


Then, there are cases where everything should be working, but it's not. Assuming that you installed the android sdk with the command.

 then your adb tool will be in android-sdk/platform-tools.

The most useful command will be ./adb help followed by ./adb logcat.   With your phone connected to your computer with a USB cable, running ./adb logcat will give you the logs from your phone.  By reading through the logs, you should be able to get some clues as to why your program is failing.




Match Game Lesson, Lists and Dictionaries


New lesson on a match game with lists and dictionaries.

The code for this lesson is available on bit bucket here.


Friday, May 31, 2013

Lesson 6 - Putting it all together - Python tile game on Android



Middle school student teaches a lesson on getting a character to walk around a map.  The map was created with Tiled.  It is a single image saved in png format.  The character can now move in all four directions.

Sunday, March 31, 2013

Lesson 5 - Going Mobile - Python on Android

Part one covers Python code modification.  Part two covers Android phone settings and configuration of Pygame Subset for Android.

Part 1


Technical points of part 1:
  • import android library and handle exceptions
  • map keyboard ESC key to Android back key (hard button) on phone
  • quit game if phone back key is pressed



Part 2

Technical points of part 2:
  • Set Android phone to debug mode
  • Configure game build with pgs4a
  • Build, package, install
  • Test game



Saturday, March 30, 2013

Lesson #4: Mouse and Touchscreen Control (taught by middle school student)



Middle school student, age 13, teaches you how to get mouse control working on the moving square.
  • Goes through event queue to check for the mouse button. event.type == MOUSEBUTTONDOWN:
  • Checks for point collision with a rectangle: collidepoint(mouse_pos)

Monday, March 18, 2013

Lesson #3 - The Moving Square





Lesson number three teaches movement in the Y axis.

The main concepts:
  • Add 1 to the y axis to move down;
  • Subtract 1 to the y axis to move up;
  • Bounds checking to detect when the square reaches the edge of the screen;
  • Conditional to change direction;
  • Clock to set the maximum Frames Per Second (FPS) that the game runs at


Lesson #2 - The Stationary Square


This lesson focuses on drawing a stationary red square.  

Main concepts:
  • Colors are set by a three number tuple (red, green, blue).  Each value ranges from 0 to 255
  • Each point on the phone screen has two numbers associated with it, the x and the y coordinate.  A single point is a pixel.  The phone screen is 480 pixels wide and 320 pixels high.
  • The rectangle is initially set by the upper left corner.  The example uses (0, 0).
  • The width and height of the rectangle are measured in pixels, 64 pixels wide and 64 pixels tall.

Bonus concepts:
  • Graphics such as a cartoon girl are loaded with image.load("filename");
  • The graphic is displayed on the phone screen with blit;
  • The position of the graphic on the screen is established with a rectangle.