Monday, August 26, 2013

Tiled JSON Map Loader Example Code Available

Someone asked me for the source code for the JSON map loader example I created for a video tutorial on using Tiled to export 2d tile maps as JSON map files. Although .tmx is a more popular format, Pygame Subset for Android does not support the xml parser libraries.  Because of this, we can't use the TMX Loader library available on the Pygame site.  Pytmxloader also will not work.  This is unfortunate since the pytmxloader is especially nice.  Although these libraries will work on the desktop.  They will not work on the Android phone.  :-(

At some point, I was planning to write a library for JSON map file loading.  However, I never got around to it.  The code below will work on desktop and mobile phones.  It is for educational purposes only.



JSON Map Loader Lesson Code that works with Tiled maps.




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)