![]() |
Intro to Building Simple Apps with PyGame... in 30 mins!
2 Attachment(s)
Pygame is a set of modules, built on Python, that you can use to build games. It's free and it's pretty easy, it's a great alternative to make apps for the N900.
This is another beginner tutorial in association with the N900 coding competition , running til July 21st. Please get involved :) Part1: Building a hello world style app with a spaceship that moves to keypresses http://i90.photobucket.com/albums/k2...aeStarShip.png Part2: Building an accelerometer app which makes a hammer sound when the N900 is held and moved downwards in a hammering motion http://i90.photobucket.com/albums/k2...-maeHammer.png This short tutorial covers:
Pre-requisites • Python should be installed correctly on your PC and n900. If not, please read over the start of MikeC's excellent tutorial to get your environment set up. Python for the N900 is available in the 'extras' repository. • You should have WinSCP on your PC and OpenSSH client-server on your n900 (or equivalents) for copying the files over. Caveats I am also a beginner, this tutorial is put out there in the hope it helps but should not be seen as well written or particularly ‘good’ Get Python and PyGame PyGame for you development machine can be downloaded from pygame.org. The 'python-pygame' module is available to install on your N900 via the extras repository. You can also install it from xterm, using the following command: Code:
apt-get install python-pygame It's basically Hello World, but with an added moveable space ship. I created two images for this example, star_background.jpg and starship.jpg. Feel free to use the files attached or substitute your own. http://i90.photobucket.com/albums/k2...background.jpg http://i90.photobucket.com/albums/k2...l/starship.jpg Next we build the code. The first step is to import and intialize PyGame. Open up a new file in your IDE or text editor and type in: Code:
import pygame Code:
screen = pygame.display.set_mode([800,420]) Code:
#load the background image We need to create a clock object to manage the loop timing, a fps variable to assign the speed, and a boolean 'mainloop' to set to false when we want the loop to stop running (e.g. quitting the app) Code:
mainloop = True Code:
while mainloop: Code:
import pygame Code:
cd /opt http://i90.photobucket.com/albums/k2...aeStarShip.png Part2 - adding sound and accelerometer with maeHammer Start off with a hammer image. You can use the one I've drawn or substitute it for one of your own. You also need a sound file of a hammer noise (or any noise), you'll find hammeronce.wav in my attached files or again feel free to substitute one of your own. http://i90.photobucket.com/albums/k2...nal/hammer.jpg Here is the full code, a lot of it should be familiar to the previous example. Copy and paste it into your ide/text editor, and save as maeHammer.py. To test, grip the n900 at the right side (handle of the hammer image) like you're holding a hammer and do a hammer type motion. A sound should play when the left side of the n900 goes down past the horizontal orientation. Please do not hammer anything other than air with your n900! Code:
import pygame Code:
def play_hammerSound(): # plays the hammer sound file Code:
def get_rotation(): # returns accelerometer data Code:
while mainloop: Anyway, you cant run this locally as the accelerometer file wont exist on your computer im sure :) So use WinSCP and OpenSSH to transfer the files into your N900’s Opt directory. To run, open Xterm and cd into the opt directory and run the main.py file. Code:
cd /opt http://i90.photobucket.com/albums/k2...-maeHammer.png That's it from me. Make sure you check out the much better tutorials on pygame.org - http://www.pygame.org/wiki/tutorials. There are also lots of examples and ideas there, it's a great resource :) |
Re: Intro to Building Simple Apps with PyGame... in 30 mins!
Here's some guides that I've found useful, or, potentially useful when it comes to pygame:
This guide seems to be pretty good for getting started in pygame. I keep meaning to look through it more, but haven't had a chance to. Invent with Python also covers game design as well as learning to program in Python. It's primarily aimed at kids (supposedly), however it covers a lot. It starts out with some text-based games, but then moves on to using pygame. This tutorial isn't too bad, and mostly works. He's got exercises to go with the lessons, with IMO is quite helpful. Hope someone finds them useful! |
Re: Intro to Building Simple Apps with PyGame... in 30 mins!
I rebuild the hammer app into a vuvuzela playing one :D
details found here: http://talk.maemo.org/showpost.php?p...8&postcount=26 thank kojakker for you detailed posts! |
Re: Intro to Building Simple Apps with PyGame... in 30 mins!
is it possible to crete a game clone of lane splitter or temple run. just simple. may be a box moving with obstacles. there are many simple games in android which have no esp graphics at all. like impossible jump and speedes 3D or falling ball. or smthng like stick games. those games do not have any esp graphics but are damn addictive. is it possible to make them?
|
Re: Intro to Building Simple Apps with PyGame... in 30 mins!
Quote:
Or are you requesting that someone else do the work for you? |
All times are GMT. The time now is 07:19. |
vBulletin® Version 3.8.8