Friday, December 21, 2012

Swarm, Sprites, Opacity, and Zombies


The winds are whipping around outside my window.  Although we planned to go surfing in Santa Cruz today, the rain and wind are making our surf outing look grim.

I decided to help my son work on his new game, Swarm.  Wow, surfing or Python programming... Well, he's a typical teenage boy, he'd rather go surfing.  But, we can't control the weather, so he's stuck with Pygame.

The concept of Swarm is to have a player face increasingly larger waves of swarming zombies.  It's a classic game with the ability to move and shoot in four directions.  The game is designed to work on his LG Optimus S Android phone with a screen size of 480x320.

The left thumb controls movement.  The right thumb controls firing.  There are unlimited bullets in the current version.  He takes a great deal of satisfaction is blasting through 20 zombies.

This is the first time we've used transparency.  For the controls, we learned that the transparency can be handled with Gimp.  In the layers window, there is a slider bar for Opacity.  For other surface objects, we're using the set_alpha method of the Surface class.




The grass and trees are made from 32x32 pixel tiles.  They're not set in a map right now.  My son is planning the game to involve going through a series of rooms.  He doesn't need to put the tiles into a map right now.

The swarm algorithm for the zombies to chase the player is pretty basic.  We're simply tracking the position of the player and move the zombies 1 pixel toward the player in both the x and y axis for every frame.  The frame rate is currently set to 30 frames per second.



 The trickier bit was how to handle the zombie crowding problem. We've got it set now to simply check for zombies colliding with each other using pygame.sprite.spritecollideany.


Friday, December 7, 2012

Teenagers and Python



Python endures the test of time.  After a few years and dozens of classes, I'm still teaching my teenage student exclusively Python.  

If you decide to teach your child to program, there are many choices.  Teaching children to program is trendy and popular, at least in my town of Palo Alto.   I've met other parents that use Scratch, Alice, Java, and JavaScript.  I've never met a parent that focused on Python for teaching.   You probably won't use Python.  You'll probably teach your child Java or JavaScript.  I stick to Python.  Why?

Well, my student is making significant progress both for desktop and mobile applications.  If it works, don't break it.

The article below was written by Marshall Brain.  It made me think again about why I don't move to Java or JavaScript.  The two hottest areas for kids are mobile and JavaScript development.  Since my student is interested in focusing more time on mobile development, it seems natural to use Java for Android or a some type of hybrid JavaScript-native platform like Appcelerator Titanium.   

I resist and continue on with Python, using the aging Pygame SDL layer, and Pygame Subset for Android. 

I persevere with Python partially because we started with Python, but also because I'm trying to avoid distractions.  My goal is not to teach my student to write a game.  The goal of my lessons is to get just a tiny bit deeper on a few basic concepts around data structures and inheritance.

Instead of covering a wide swath of technology, I'm trying to focus in on a few concepts at a time.  In the next few months, I hope to focus my student on data structures such as the list data type, more on dictionaries, possibly through the use of JSON data for tile maps.  I'm also planning to cover python classes in more details.






Teaching your kids how to
write computer programs

by Marshall Brain
Let's say that you have children, and you would like to help them learn computer programming at a youngish age. As the father of four kids, I have tried to approach it from several different angles. What I would like to do here is collect some ideas for parents who are looking for different options.
Let's start with a something important: Every kid is different. Some kids are reading and writing fluently years ahead of other kids. For them, learning to program is probably easier. Some kids have the basic analytical skills a lot earlier than others (Here's a story about a 9-year-old writing full-blown iPhone apps). And so on. You try to expose your kids to programming and it may or may not "take" the first time, simply because of these differences. So you wait a few months and try again, or you might try a different approach. Understand that, the first time you try to introduce your kids to programming, your kids might not "get it" at all. And that's OK.
The second thing to realize is that real analytical skills often don't start appearing until age 11 or 12 or 13 in many kids, so expecting huge breakthroughs prior to that may be unrealistic.
That being said, there are lots of fun things you can try as early as five or six...

Games

Let's start with a few games. Here are three games that my kids have particularly enjoyed. They teach basic problem solving ideas in different ways:
If you look around on the web you can find lots of "problem solving" games like these three.
Then there is this game, which actually does a very good job of teaching simple programming skills:
  • Light Bot (the "Play" button is on the bottom right, under the ad, after it loads)
LightBot
I love Light Bot. It will engage kids for a couple of hours, starting at age 7 or 8. Some of the puzzles in LightBot are too hard for kids. There are walkthroughs on YouTube that help.
A friend of mine suggested this game:

LOGO

As soon as you try Light Bot it may remind you a little of LOGO - a language for younger kids. You can find out more about it on a page like this:
Or jump into Google. There is lots of stuff about LOGO on the Web.

Bigger efforts

Lego MindstormsOne thing that one of my kids enjoyed quite a bit is Lego Mindstorms. This is a Lego robotics kit. I've seen kids as young as six or seven doing meaningful programs with it. It uses a graphical language that is pretty simple to understand. If you don't mind blowing $200, then it is definitely worth a look. If you find that your kid really likes it, you might also look into FIRST Lego League (FLL teams build Mindstorms robots, work on presentations, etc.). One of my kids has been on an FLL team for several years and it has been great for him.
The good thing about Mindstorms is that it lets kids build some interesting stuff. The problem is that, after a month or two, you may find that you have come to the limits of what it can do. [Yes, there are adults on YouTube showing off some amazing, advanced stuff, but I suspect that these people are geniuses.]
A friend recommended this educational system for programming robot simulations. It is free:
Another big effort like this is Phrogram, formerly known as Kids Programming Language. KPL had the huge advantage that it was free and pretty amazing. It came with dozens of sample programs and could do both simple and complex things (for example, a really good pinball machine was one of the samples). But for some reason they killed KPL off and morphed it into Phrogram. Phrogram is $50, and I haven't tried it, but assuming that it is a similar package it might be worth it.
On these pages, a father talks about his efforts to teach programming to his daughter using a tool called Greenfoot:
Which is interesting. He's able to create some pretty sophisticated stuff with her using object oriented techniques.
In a similar object oriented vein is a free system from MIT called Scratch:
My kids played with this for a couple of days.
If your kids would like to create games, here is one option to try:
GameMaker is a pretty sophisticated tool with a lot of options. There are tutorials to help you get started. I would not use this as a "first foray" perhaps, but it is something to consider for a second foray.
Also there is a free eBook on creating games with Python which states, "written to be understandable by kids as young as 10 to 12 years old, although it is great for anyone of any age who has never programmed before":
A friend has suggested that this is a nice intro.
One other thing to try is:
The tagline is: "Codecademy is the easiest way to learn how to code. It's interactive, fun, and you can do it with your friends."

Real programming - Stanford's Java Class

My son (around age 13) started using Stanford's free online Java class and he has gotten a lot out of it. The class includes YouTube lectures and class assignmentsthat reinforce the concepts discussed in class. The programming environment used in the class is called Eclipse. Eclipse is a full-featured development tool with a great debugger and it is free too. This is the class my son took:
See also:
Our son needed a little encouragement from his parents (i.e. deadlines) to get through the first assignments, but by the time be got to Programming Assignment #4 (writing the code for the game called "Breakout") he was completely engaged and extended that basic game in a number of directions without any prompting from us. I feel like this class taught him the essence of being a "real" programmer.
Stanford has many classes to explore - click for list. Their offerings represent a valuable resource for anyone wanting to learn programming.
Once comfortable with Java, something like this might be interesting to try - a combination of Greenfoot and Java:

Real programming - C and C++ Programming

The C and C++ programming languages are two of the most widely used programming languages in the world. There are free compilers that are readily available and lots of tutorial information can be found for free. Here are two resources that can help get you started:
Google is your friend and can help you find tons of other stuff.

Learning to write iPhone and iPad apps

Writing apps for the iPhone and iPad is not for newbies, but it is definitely something that middle school and high school students can master if they have a knack for programming. And the audience for these apps is gigantic through the App Store that Apple operates. Here are the steps that you need to take if you want to get started:
Google can help you to answer nearly any question or problem you run into as you are learning.

The BASIC Stamp

BASIC StampI have actually had a good bit of luck engaging my 10-year-old in programming using a device called a BASIC Stamp. So I would like to spend a little time here talking about it. It is not cheap, but it has three things going for it:
  1. It combines programming and simple electronics
  2. The programming tends to be very simple
  3. You can do real things with it, or at least things that seem realer (to my kids anyway) than Mindstorms.
We were first introduced to the BASIC Stamp when we found this kit at Radio Shack for $90:
You can also order it here:
The big caveat is that you need to have a computer with a serial port to use it. If you do not have such a computer (most computers made since 2005 don't have a serial port), then you need the USB version of the kit for $160:
And if you are going to do that, I might suggest you consider this robot kit instead, because it is the same price:
So, already, you can see that the BASIC Stamp is not simple or cheap. We've already had to worry about port types and which kit to get. And if that puts you off, so be it.
But we did buy the kit at Radio Shack, and we did have an older machine with a serial port, and we did get it set up and it did all work and... here is what was amazing about it. My kid could sit down with the book, by himself, and on his own he could wire up little circuits and write little pieces of code and get it all working. The programs and the electronics are easy enough that a 10-year-old can manage it. This is admittedly simple stuff, like wiring up a push button and having it make an LED blink, or making a servo motor turn or making sounds come out of a speaker. But the idea that my kid (who hates reading for the most part) could get this stuff working was impressive. And then he could think of extensions on his own. Trivial extensions, yes, like making two LEDs blink, but extensions.
The nice thing about this approach is that you can buy other pieces at Parallax.comand they are pretty easy to hook up. One of the first things we bought was a PIR module ($10), which is the kind of thing you use in a burglar alarm or an automatic light to sense a warm human body. We also bought a little text LCD panel ($25). And he built a device that could count people as they walked by. If you have a family of six people, how many times do they use the stairs in the house? How many times do they open the refrigerator? With this device you can find out. (The refrigerator was funny - it was opened something like 50 times a day!)
Next thing was a ultrasonic sensor ($30). With that and the LCD display you can build a little ultrasonic tape measure. They have a lot of little sensors like this that you can try. We've used the accelerometer, the thermometer, the RFID tag reader, etc.
His latest adventure is with the GPS module ($90) and the USB memory stick reader/writer ($35), which he used in a science fair project. With the USB memory stick thing, you can plug in a USB memory stick (AKA "thumb drive") and read and write files. So you can create a text file and start dumping in data. Then you can hook up the GPS, let it gather data and save the data into the memory stick. With that you can create bread crumb trails everywhere you go. You can then plug the memory stick into your laptop's USB port, load the data into a spreadsheet and do a scatter graph...
GPS Scatter Plot
...or you can drop the data into Google maps as described here:
As it turns out, the Parallax GPS is not the greatest. When we first hooked it up, it would never get a lock on the satellites. After an hour of probing on Google, we found out that you have to mount the GPS about 10 inches away from the Stamp (because of electrical noise generated by the Stamp). It would have been wonderful if this fact had been revealed in the Parallax documentation. But even after you do that, this device can have trouble getting a lock sometimes (ours doesn't work at all in rainy weather, for example). It does work in the car if you put it on the dashboard, but not from the interior. [All of these problems eventually led us to a site called Sparkfun.com, which has a much better selection of GPS modules that are slightly less easy to use.]
It also led us looking for material on the web about the BASIC Stamp. There is a lot of it. For example, there are people building autopilots from BASIC Stamps:
You can find all kinds of stuff like that. Then you discover that there are many other platforms more advanced than the Stamp, like for example the Arduino, theTeensy, the Microchip PICkit (see also this book and this book), the Gumstix, etc.

Conclusion

The point is, if you want to introduce your kids to programming, there are MANY different ways to do it. If you want to go down this road, Google is your friend. It is amazing how much stuff is out there. Just start looking, try different things with your kids, and see what works for you. It can be a lot of fun.
PS - Note to self: Open GPS Tracker, the BigAVR2

Sunday, December 2, 2012

Getting Android adb working with Pipo Smart S1



The Pipo Smart S1 is a 7" Android 4.1 tablet that costs under $100.  It works great and is quite fast.   It's comparable to the Nexus 7" at half the price.  I changed the firmware to rev3 with instructions from TopNotchTablets.  This download also got rid of the apps that had Chinese language, giving a more comfortable user experience.

The CPU is a Rockwell RK3066 1.6GHz chip.

Rooting the tablet and upgrading the firmware was fast and painless.

Getting the tablet to work with the Android Debug Bridge (adb) was trickier.

Pygame Subset for Android (PGS4A) relies on adb that is included in the platform-tools sub-directory of the Android SDK.




When I first connected the Pipo Smart S1 tablet to my Ubuntu box with a micro USB cable, the build worked, but the install failed.

After figuring out how to use adb, I started to use adb devices to see the connected devices.  It wasn't detecting the tablet.


I found out that adb needs a USB Vendor ID to work properly.  Pipo wasn't listed as a vendor.   I found that the Vendor ID for the RK3066 chip is 0x2207.

Using the Android Developer documentation on Hardware Devices, I created the file /etc/udev/rules.d/51-android.rules and inserted this:


SUBSYSTEM=="usb", ATTR{idVendor}=="0x2207", MODE="0666", GROUP="plugdev"

It still wasn't working for me.  I had USB debugging enabled on my tablet.

I then added the vendor ID code to ~/.android/adb_usb.ini

:~/.android$ cat adb_usb.ini 
# ANDROID 3RD PARTY USB VENDOR ID LIST -- DO NOT EDIT.
# USE 'android update adb' TO GENERATE.
# 1 USB VENDOR ID PER LINE.
0x2207

It's still not happening.  I check out lsusb and see some hope that the device is detected.  




I turn off wifi from the tablet.

I run adb devices again.


$ ./adb devices
List of devices attached 
???????????? no permissions


There's a bit more life.  I run it again as sudo.

$ sudo ./adb devices
[sudo] password for craig: 
List of devices attached 
???????????? no permissions

No go.

I kill the server. Then start it as root.
$ sudo ./adb devices
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
List of devices attached 
ZX7U17M3NX device

It found the device!

I build the Python app:

$ ./android.py build dad/dad_image release install

install:
     [echo] Installing /home/c/Documents/python/pgs4a-0.9.4/bin/dad_image-1-release.apk onto default emulator or device...
     [exec] 5391 KB/s (2741472 bytes in 0.496s)
     [exec] pkg: /data/local/tmp/dad_image-1-release.apk
     [exec] Success

BUILD SUCCESSFUL
Total time: 8 seconds

It looks like the build succeeded.  

Here's a screenshot of the game running on the Pipo Smart S1, transferred using a USB cable with adb.





After I got this working, I worked with my son, my only computer programming student,  to get a similar game working on his LG Optimus S phone.  The main learning points today:

  • using .append to fill a list of objects.   The list target_group contains all the enemies and all the bombs.
  • Set up triggers based on elapsed time use list slicing to control the number of targets on the screen.







After I wrote the blog post, I also found this  on slatedroid.com.  It covers many of the same steps.  I'm not sure if shutting off WiFi is needed.  The person below also seems to have adb working without having to run the adb server as root.  I may fiddle around with more things in the future.  The main thing is that I can connect my tablet to adb in debug mode and install the apk files easily.


Posted 21 November 2012 - 08:31 PM
Just a few tips to those are trying to connect to a RK3066 via ADB on linux.

  • Download & Install SDK
  • Edit udev rules (see step #3), the RK3066 Vendor ID is 2207
  • Restart udev (udevadm control --reload-rules)
  • Edit $HOME/.android/adb_usb.ini, add 0x2207 at the end of the file
  • Restart adb server (adb kill-server && adb start-server)
  • Plug & List your device (adb devices)


At step #2, you should get something like this
SUBSYSTEM=="usb", ATTR{idVendor}=="2207", MODE="0666", GROUP="plugdev"


At step #4, you should get something like this
# ANDROID 3RD PARTY USB VENDOR ID LIST -- DO NOT EDIT.
# USE 'android update adb' TO GENERATE.
# 1 USB VENDOR ID PER LINE.
0x2207

Saturday, December 1, 2012

Timers in Games

I've been trying to figure out the best way to set up timers in games.   Timers are used all the time, for example, the firing rate of a gun, the delay in a joystick button press to check to see how many times the button was pressed, or the speed of an animation.

The overall speed of the game is controlled by a clock that is usually used to control the frame rate.  For  example,
clock = pygame.time.Clock()
framerate = 60
 In the main game loop, the clock is ticked.
clock.tick(framerate)

 To control time for individual objects, I usually use the standard python time module.

## using the standard python time library, not a pygame module.  
start_time = time.time()
## some action
elapsed_time = time.time() - start_time
## 10 millisecond delay
if elapsed_time > 10:
     ## do the action we've been waiting for.
 

I notice that many people using the pygame.time module in their games.  I've tried to figure out the advantage of this and I can't understand it out.  The people using this module are usually better programmers than I am.

## using the pygame.time module, not the standard python time library.
current_time = pygame.time.get_ticks()
## example 10 millsecond delayif next_update_time < current_time:    # do stuff    next_update_time = current_time + 10
Finally, I notice that other people are using the main game clock, the one that is usually set to 50 fps or 60 fps.  Here's a code snippet that blits the image once every 10 frames.  If the game is running at 60 frames a second, the image is blitted 6 times a second, effectively setting up a delay of over 100 ms.


class walker:
    def __init__(self):
        self.ani_speed_init = 10
        self.ani_speed = self.ani_speed_init
        self.ani = glob.glob("walk/walk*.png")
        self.ani.sort()
        self.ani_pos = 0
        self.ani_max = len(self.ani) - 1
        self.img = pygame.image.load(self.ani[0])
        self.direction = "right"
        self.movement = False
        self.update(0)
        
    def update(self, pos):
        self.ani_speed -= 1
        self.x += pos
        if self.ani_speed == 0:
            self.img = pygame.image.load(self.ani[self.ani_pos])
            self.ani_speed = self.ani_speed_init
            if self.ani_pos == self.ani_max:
                self.ani_pos = 0
            elif self.movement:
                self.ani_pos += 1
        if self.direction == "right":
            windowSurface.blit(self.img, (self.x, self.y))



Sunday, November 25, 2012

Walking Animation with Pygame


My son spent an hour going through a great video from the Films by Kris site.  The video PyGame - Sprite Animation Walk Loop is a great introduction to walking animation and quite rewarding.  My son was able to create the application above in under an hour.

Although the original video has the character walking backward, my son changed the orientation of the character with the pygame.transform.flip method.

It's a fairly minor change.


        if self.direction == "right":
            windowSurface.blit(self.img, (self.x, self.y))
        elif self.direction == "left":
            self.left_img = pygame.transform.flip(self.img, True, False)  
            windowSurface.blit(self.left_img, (self.x, self.y))




More information on Pygame surface transformation is available here.

The tutorial that Films by Kris used is embedded below.


Porting Pygame Apps to Android


Since my son is on Thanksgiving holiday, I taught him two classes today.  I'm sure he would have preferred fishing.   The first class covered how to port one of his earlier Pygame desktop applications to Android.  The process only took an hour.  The game now works on his LG Optimus S Android phone and he can enjoy playing it while lying on his bed or after school with his friends.

His game, dropper, does not use any raster graphics.  Dropper only uses the primitive shapes from the pygame.draw module.  Despite the simple graphics and lack of sound effects, it's one of the most playable games he's developed.  It works quite well on his phone.

Here's an overview of the simple changes.


  • import android module
  • change screen width and height to 480, 320 (low-end phone screen)
  • change player size to make it easier to dodge bullets on a smaller screen
  • change frame rate to 30 fps to slow down the movements and make the game easier.  The smaller screen makes it more difficult to avoid the bombs.
  • android.init()
  • map the ESCAPE key in pygame to the physical back button on the phone.  He uses this to exit the game loop.
    • android.key_map(android.KEYCODE_BACK, pygame.K_ESCAPE)
  • adjust the height of the text boxes for the Game Over screen and final score.
  • use free clip art to create the android-icon.png file for the Android app launcher
  • use free clip art to create the android-presplash.jpg file for the initial splash screen that shows up prior to the game starting. 
In the future, it might be rewarding for the student to use Inkscape to create a logo for a mock software company.

Since the original game used the keyboard for controls, he added mouse controls.  PGS4A maps the mouse to the touchscreen.  This is so nice.  For this game, he created active areas of the screen to control left and right movement.  There's no instructions, but it seems intuitive to most people playing the game.

The original game also used the default system fonts on Ubuntu.  He saved the fonts from 
/usr/share/fonts/truetype/freefont/FreeSansBold.ttf on Ubuntu to his build directory and packaged the font as part of the Android app bundle. 


Saturday, November 24, 2012

Sprites and Tiles


My son finished his shooter game and I started to research tiles for the next project.

During Thanksgiving break, I started with Tiled TMX Loader.  This initially proved quite rewarding since there were several nice examples of Pygame code that shipped with the library.    I used Tiled Map Editor to make the maps from tile sets.

Since my son wants to show his friends his games on his phone, I was planning to package the Pygame application for his phone using Pygame Subset for Android (PGS4A).    

Unfortunately, when I did the build, I realized that Pygame Subset for Android does not support the XML libraries that Tiled TMX Loader requires.  There does not appear to be an easy way to build the XML C libraries into PGS4A or include a Python library with the application.    Here is a discussion thread from the Pygame Subset for Android forum.  The workaround people were using involved converting the tmx maps to JSON files and loading the map into the Pygame on Android application using the JSON module that was supported by PGS4A. 

Although Tiled can output a tile map to JSON, I realized that all the python JSON library does is load the JSON file data into dictionaries and lists that can then be accessed by the program.  Taking this route, I'm going to need to develop all the map camera movements, layer management, and collision detection myself.  Bummer.   The data is there, but I didn't want to think about how to manipulate it.

Feeling that manipulating map data from JSON files was too much of a task, I instead started to research sprites, basically shelving the idea for a complex map and focusing on understanding smaller lists and dictionaries of tiles made up of 32 x 32 pixel tiles.

piman's sprite tutorial was the most useful.  The application above is basically an extension of piman's tutorial.  Instead of colored rectangles, I used pygame.image.load("filename") to create image surfaces.  I used a single grass tile as the background and simply repeated it.

The controls at the bottom select the character to move.  

def select_character(buttons, mouse_pos, selection):
    selected_char = selection
    for b in buttons:
        if b.rect.collidepoint(mouse_pos):
            selected_char = b.character
    return(selected_char)

I recently realized that I can use pygame.Rect.collidepoint instead of pygame.Rect.colliderect.  The rectangles are the same ones that you use to blit the images onto the screen.

It's easy to get the mouse position with pygame.mouse.get_pos().

In the main event loop, I simply check for the mouse button up or down:
  • elif event.type == pygame.MOUSEBUTTONDOWN:
  • elif event.type == pygame.MOUSEBUTTONUP




Sunday, November 18, 2012

Pygame Subset For Android


My student recently bought an Android 2.2 smartphone on eBay for $40.  It's quite a good deal.  The phone is unlocked and can run games from GooglePlay as well as custom games.

I spent about an hour today teaching a lesson using Pygame Subset for Android.  Wow, talk about big bang for the buck.  By the end of an hour, my student was running a native Android app on his phone completely from a blank text editor.  The app has working animation, touchscreen interaction, and hard-buttons.

Since I was completely new to Android development, I ran into a small problem building the project with Ant.

When I ran the example build from the Pygame Subset for Android, I got an error message when the script ran Ant.

~/$ android.py build mygame install release

 

Initially, I spent some time trying to create a build.xml file.   This led to a dead end.

The solution is to look at the Target id, android-8.

In the android-sdk directory, you need to have the android-8 platform listed in the platforms directory.


ubuntu-desktop:~/Documents/python/pgs4a-0.9.4/android-sdk$ ls platforms/
android-17  android-8
ubuntu-desktop:~/Documents/python/pgs4a-0.9.4/android-sdk$ 

If you don't have this platform, and you probably won't by default, run the android program within the android-sdk/tools directory.

The reason this wasn't immediately obvious to me is that the error message for the missing android-8 target was at the top of the screen output and the build.xml error message was at the bottom.  I should have read the error messages closely, starting at the top of the output.

run
  $ ./android --help 

for help or

  $ ./android update sdk 

to install API-8, Android 2.2 platform support.








Sunday, September 30, 2012

GIMP YouTube Videos

As I am waiting for the french toast to cook this morning, I watched this video on GIMP usage.  Simply awesome.



This woman has 83 videos on using GIMP on her YouTube channel, Your Favorite GIMP Teacher!

I've watched 1 out of the 83 so far.

Below is the result of my 10 minutes with GIMP.

Tiled Map Editor

In addition to thinking about moving my student's shooter game to the web, I've been thinking of the next type of game to work on.

Right now, I'm considering a tile map game.  This Tiled Map Editor looks interesting.

It listed these tools that work with Tiled on Python:

  • Pygame map loader by dr0id
  • PyTMX by Leif Theden (bitcraft)
  • tmx.py by Richard Jones, from his 2012 PyCon 'Introduction to Game Development' talk.
  • pytmxlib: library for programmatic manipulation of TMX maps


I'm hesitant to go down the path of making a 3D First Person Shooter (FPS) game with PyOgre or Panda3D.  I haven't looked at things like Kodu too much, though it does seem similar to Alice.

I also found an interesting Game Based Learning Wiki.


Saturday, September 29, 2012

Mobile Game Engines Site

I stumbled across the Mobile Game Engines site while I was looking for a Python to JavaScript converter.

I don't think that I'll find a converter that will convert a full Pygame game into JavaScript.  The GameJs library looks interesting since the drawing API is based on Pygame.

Another interesting project is pyjs, a Python-to-JavaScript compiler, AJAX framework, and Widget Set API.

Wikipedia has a nice comparison of JavaScript frameworks that includes Pyjamas (pyjs) as well as the obvious ones like Dojo and jQuery.


Despite the inability to easily share games inside of a web browser, I intend to keep focusing on Pygame for now.   I don't think JavaScript has the necessary structure for effective teaching.

Monday, September 24, 2012

Scoring and Gun Types


Son changed:

  • Scores for enemies landed and enemies shot
  • Change of gun between piston and shotgun
  • Aligned shotgun blast graphic with shotgun movement from left to right
  • Using three graphics for the shotgun for left, middle, right
  • Using three graphics for the pistol for left, middle right
Gun change is currently controlled by the keyboard.  Plan to switch this to Button 4 on the joystick.  Right now, there's a problem with repeating the button every time the program goes through a loop.  

Although there's many ways to set up a button delay, I'm going to show my student this method using python's time.time() library.




The above code snippet references my_joystick. It simply checks to see if 300 milliseconds have passed since the last time the gun was changed. get_button(3) will check the yellow button Y on the XBox 360 controller or the button labled 4 on the Logitech RumblePad 2



These shooter games are fairly easy for middle school children to build. They don't rely on lists and dictionaries as much as the memory puzzle game did. A shooter game primarily uses addition and subtraction of the rectangle coordinates. Using pygame's Rect, it is easy to check for collision of two rectangles.

 Just watched this video on Gimp Tutorial: Layers - The Basics.

Tuesday, September 11, 2012

PyWeek

PyWeek is a challenge to write a game from scratch in one week.  I don't have an official entry, but I am engaging the community in discussion while I develop my own project in parallel to the challenge.  I hope to enter the challenge in 2013 with my son.

We're on day 3 of PyWeek 15.  The theme is "One Way Trip!"

As far as I know, there is no prize for winning except some minor recognition from a small community of online people.  My game tracks the story of one soldier through a battlefield.



I used Inkscape for the first time today.  I still find Inkscape and the GIMP difficult to use.  I'm using Audacity for the audio editing.

Tonight was also the first time I tried using sound channels.  Prior to this, sound was getting cut off every time I started a new Sound.play() action.  For example, the explosions and pistol shots could not occur at the same time.  By using the channels, I'm able to play multiple explosion and pistol sounds at the same time.  The documentation indicates that there are eight sound channels.


Sunday, September 9, 2012

Making of Warcraft


Patrick Wyatt, a famous game developer who tuned his craft at Blizzard, wrote a blog post on the making of Warcraft.  He gives us a view into the different roles of people working at a game company, the artists, the software developers, and the managers.  His blog is in two parts.  The second part has more choice tidbits on the dynamics of people in the company.

This section captures the frenzied culture stemming from working on multiple projects at the same time:

We worked together, played together, partied together, slept 10 to a hotel room for trade shows together, and in cases even lived together: I shared a house with three other Blizzard-folks which was the first of many similar dorm rooms scattered throughout Orange County, California.

Blizzard was working on at least four other games when I started on the Warcraft project, and as the company numbered only 20 everyone was mega-busy keeping those projects on track. It wasn’t uncommon for artists, programmers and designers to be working on two or sometimes three projects at a time, and of course our sole musician/sound-engineer, Glenn Stafford, worked on everything.
After Patrick's blog, I felt that I wanted more information on the culture of video game companies.  I ordered David Kushner's 2004 book called, The Masters of Doom.

Saturday, September 8, 2012

Scrolling

I've been trying to figure out how to scroll the background scene from left to right and up and down.

I initially started using the pygame Surface.scroll feature for image surfaces.  Although I was able to quickly get the image to scroll with the cursor keys, I'm having a problem with redrawing the image properly.

As I was searching for a solution, I found this link to Parallax scrolling, which seems interesting.  Just I was about to try parallax scrolling, I opened up the scrolling example that ships with pygame and realized that there is a cool method for rectangles called, Rect.move_ip.  Although I had seen this in the documentation before, I always assumed that ip dealt with the networking.  Well, it turns out that ip stands for In Place, not Internet Protocol.  Wow, move in place.  With this, I was off and scrolling in no time.





I'm using a single image in this short example and simply controlling movement and sight with the joystick hats.  Here's a lengthy way to pan the image around.

    h_axis = joy.get_axis(0)

    v_axis = joy.get_axis(1)
    x = int(h_axis * scroll_speed)
 
    y = int(v_axis * scroll_speed)
 
    if scenery_rect.left < 0 and x < 0:
        scenery_rect.move_ip(-x, 0)
    elif scenery_rect.left > 0 and x < 0:
        scenery_rect.right = WIDTH
    elif x >= 0 and scenery_rect.right >= WIDTH:
        scenery_rect.move_ip(-x, 0)
    elif scenery_rect.right <= WIDTH and x > 0:
        scenery_rect.left = 0
    if scenery_rect.top < 0 and y < 0:
        scenery_rect.move_ip (0, -y)
    elif scenery_rect.bottom > HEIGHT and y >=0:
        scenery_rect.move_ip(0, -y)

Due to my sports injury, I've been spending more time with my student.  He's making great progress with his shooter game.  He's up to one jet, one stealth fighter and one pistol.    He also reduced the target area of the crosshairs to around 7 pixels.

Sunday, September 2, 2012

Shooter With Joystick


Since it's Labor Day weekend, I had some time to work with my son on game concepts.  I went back to the lesson on pygame.joystick, that my son worked on last year.  So far, we put about two hours into the lesson.  It's a fun, easy and rewarding lesson that uses simple math.  It's also short enough so that we didn't use functions or classes.

The background is a simple static image that doesn't move. The gun sight is also a single image with transparent background enabled. My student didn't develop any targets yet because he went out to a Labor Day BBQ.

Here's the code: