Pages

miercuri, 18 februarie 2009

PyGame : Sounds in pygame.

First of all, you need two files. This is "load.py".

import os
import sys
import pygame
from pygame import mixer
pygame.mixer.init() 
def snd(nume):
    numeintreg = os.path.join("sunete",nume)
    sound = pygame.mixer.Sound(numeintreg)
    return sound
This is "main.py". The sounds "o.wav" can be any sound file.

import os
import sys
import pygame
from pygame import *
import load
def main():
     ocean=load.snd("o.wav")
     ocean.play()
main()

PyGame : Showing pictures on pygame

First of all, you need two files. This is "load.py"

import os
import sys
import pygame
def img(nume):
    numeintreg = os.path.join("date",nume)
    image = pygame.image.load(numeintreg)
    image = image.convert()
    return image
This is "main.py". The image "bk2.bmp" can be any image.
import os
import sys
import pygame
import load
def main():
    pygame.init()
    ecran = pygame.display.set_mode((640, 480))
    fundal = load.img('bk2.bmp')
    ecran.blit(fundal, (0, 0))
    pygame.display.flip()
main()

marți, 17 februarie 2009

PyGame : Keyboard on pygame

This is a short example of how to use the keyboard in pygame.

import os
import sys
import pygame
from pygame import *
def main():
   pygame.init()
   ecran = pygame.display.set_mode((640, 480))
   ruleaza= True
   action = "Help!"
   while ruleaza is True:
       for event in pygame.event.get():
           if event.type == QUIT:
               ruleaza == False
           elif event.type == KEYDOWN:
               if event.key == K_ESCAPE:
                   ruleaza = False
               elif event.key == K_LEFT:
                   action="L"
               elif event.key == K_RIGHT:
                   action="R"
           print action
main()

luni, 9 februarie 2009

About Pygame python module.

About PYGAME we can find out from web articles and we can get a picture of this python module:
Yet another powerful open source 2D game engine. Pygame is a set of modules allows you to create fully featured games and multimedia programs in the python language. Pygame is portable and runs on every platform and operating system.
Pygame is free. Released under the LGPL license, you can create an open source, free, freeware, shareware, and commercial games with it. See the license for full details.

The Python PyGame module is easy to use in both procedural and object programming.
The installation process is easy:
pip install pygame
The official web page can be found here.
The Wikipedia page with info about this python module can be found here.
The pypi webpage can be found here.
All documentation can be found on this webpage.