miercuri, 18 februarie 2009

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()

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()