Pages

luni, 21 martie 2011

PyGame : Using with Android.

What is Android?
Wikipedia says:
Android is an open-source software stack for mobile devices that includes an operating system, middleware, and key applications.[5][6] Google Inc. purchased the initial developer of the software, Android Inc.

Python on Android?

The Pygame Subset for Android is a port of a subset of Pygame functionality to the Android platform.
This pygame subset for Android, allows us the creation of Android-specific games.
In the chapter "samples" comes only with just one classic sliding numbers puzzle.
The good thing is, it can run on a PC.
I installed Fedora pygame with "yum install pygame" as root.
And I run the application example of "samples".
Here is the result:

It works great on Fedora.

marți, 12 octombrie 2010

PyGame : First interface - part 2

One thing necessary to create an interface and a game is using a "sprite system".
To illustrate this, I'll show you a sequence of source code:

import pygame
def must_quit():
    event = pygame.event.poll()
    return event.type == pygame.QUIT
screen = pygame.display.set_mode((640, 480))
SpriteImage = pygame.image.load('image.jpg')
while not must_quit():
    screen.blit(SpriteImage, (0, 0))
    pygame.display.flip()

It sounds simple but is not.
Why? Because when you work with multiple images when source code is more complicated.
For this we need a system and use the "classes".
Let's see:

class SpriteImage:
    def __init__(self, image_filename):
        self.image = pygame.image.load(image_filename)
    def paint(self):
        screen.blit(self.image, (0, 0))
screen = pygame.display.set_mode((640, 480))
sprite = SpriteImage('image.jpg')

This is a more simple way to use it.
Try learning more about pygame.
Good luck.