Mostrando entradas con la etiqueta juego infantil. Mostrar todas las entradas
Mostrando entradas con la etiqueta juego infantil. Mostrar todas las entradas

jueves, 22 de octubre de 2015

Toma las vocales



# -*- coding: latin-1 -*-


#Este programa ilustra la idea de "tomar" objetos con un ratón
#(que es una manita), llevándolos de un lugar a otro.

import pygame,os,time,random
from pygame.locals import *
H=600
W=800
class Wall(pygame.sprite.Sprite):
    def __init__(self,x,y,height,width):
        pygame.sprite.Sprite.__init__(self,self.containers)
        brickImgTmp=pygame.image.load('./DataImgs/brick.png')
        brickImg=pygame.transform.scale(brickImgTmp,(height,width))
        self.image = brickImg
        self.rect = self.image.get_rect()
        self.rect.topleft = (x, y)

class Hand(pygame.sprite.Sprite):
    posx=0
    posy=0
    def __init__(self,x,y,height,width):
        pygame.sprite.Sprite.__init__(self,self.containers)
        brickImgTmp=pygame.image.load('./DataImgs/hand.png')
        brickImg=pygame.transform.scale(brickImgTmp,(height,width))
        self.image = brickImg
        self.rect = self.image.get_rect()
        self.rect.topleft = (x, y)
    def update(self):
        self.rect.topleft = (self.posx, self.posy)

class Wall2(pygame.sprite.Sprite):
    speed=10
    def __init__(self,x,y,height,width,vowel,alea):
        pygame.sprite.Sprite.__init__(self,self.containers)
        if vowel=='a':
            brickImgTmp=pygame.image.load('./DataImgs/brickaGreen.png')
        elif vowel=='e':
            brickImgTmp=pygame.image.load('./DataImgs/bricke.png')
        elif vowel=='i':
            brickImgTmp=pygame.image.load('./DataImgs/bricki.png')
        elif vowel=='o':
            brickImgTmp=pygame.image.load('./DataImgs/brickoRed.png')
        elif vowel=='u':
            brickImgTmp=pygame.image.load('./DataImgs/brickuBlue.png')
        elif vowel=='x':
            brickImgTmp=pygame.image.load('./DataImgs/basket.png')
        brickImg=pygame.transform.scale(brickImgTmp,(height,width))
        self.image = brickImg
        self.rect = self.image.get_rect()
        self.rect.topleft = (x, y)

def game():
    pygame.init()
    doh=pygame.mixer.Sound('./DataSounds/doh.wav')
    clock=pygame.time.Clock()
    disp=pygame.display.set_mode((640,480),0,32)
    background= pygame.Surface((640,480))
    imgTmp=pygame.image.load('./DataImgs/madagascar.png').convert_alpha()
    imgTmp2=pygame.image.load('./DataImgs/basket.png').convert_alpha()
    img2Tmp=pygame.image.load('./DataImgs/hand.png').convert_alpha()
    img=pygame.transform.scale(imgTmp,(W/12,H/20))
    imgBack=pygame.transform.scale(imgTmp,(W,11*H/14))
    img5=pygame.transform.scale(img2Tmp,(W/20,H/20))

    every = pygame.sprite.OrderedUpdates()
#    every = pygame.sprite.RenderUpdates()
#    every = pygame.sprite.RenderPlain()
    walls=pygame.sprite.Group()
    walls3=pygame.sprite.Group()
    hands=pygame.sprite.Group()
#    wall2s=pygame.sprite.Group()
    Wall.containers=walls,every

    wall2s=pygame.sprite.Group()
    wallAs=pygame.sprite.Group()
    wallEs=pygame.sprite.Group()
    wallIs=pygame.sprite.Group()
    Wall2.containers=wall2s,every
    Hand.containers=every
    final=pygame.Rect(80,40,40,40)
    wall_list=[]
    wall2_list=[]

    wallA_list=[]
    m=Wall2(3,6*50,220,180,'x',10) #basket
    wallIs.add(m)    #Así?
    a=Wall2(3*60,1*40,100,100,'a',10)
    e=Wall2(4*60,1*40,100,100,'e',10)
    i=Wall2(5*60,1*40,100,100,'i',10)
    o=Wall2(6*60,1*40,100,100,'o',10)
    u=Wall2(7*60,1*40,100,100,'u',10)

    wallAs.add(a)
    wallAs.add(e)
    wallAs.add(i)
    wallAs.add(o)
    wallAs.add(u)
    hand=Hand(100,100,50,50)
    pygame.display.set_caption("Hello, World!")

    background = imgBack
    mouse_cursor = img5

    pygame.mouse.set_visible(0)
    M=5
    grab=False
    select=' '
    while True:
        mousex, mousey = pygame.mouse.get_pos()
        mousexx, mouseyy = mousex, mousey
        mousex-= mouse_cursor.get_width() / 2
        mousey-= mouse_cursor.get_height() / 2
        for event in pygame.event.get():
            if event.type==QUIT or \
                    (event.type==KEYDOWN and event.key==K_ESCAPE):
                return
            keystate=pygame.key.get_pressed()      

            if event.type==MOUSEBUTTONDOWN:
                grab=True
                if grab and a.rect.contains(hand.rect):
                    a.rect.center=(mousex,mousey)
                    select='a'
                if grab and e.rect.contains(hand.rect):
                    e.rect.center=(mousex,mousey)
                    select='e'
                if grab and i.rect.contains(hand.rect):
                    i.rect.center=(mousex,mousey)
                    select='i'
                if grab and o.rect.contains(hand.rect):
                    o.rect.center=(mousex,mousey)
                    select='o'
                if grab and u.rect.contains(hand.rect):
                    u.rect.center=(mousex,mousey)
                    select='u'
            if event.type==MOUSEMOTION:
                if grab:
                    if select=='a':
                        a.rect.center=(mousex,mousey)
                    elif select=='e':
                        e.rect.center=(mousex,mousey)
                    elif select=='i':
                        i.rect.center=(mousex,mousey)
                    elif select=='o':
                        o.rect.center=(mousex,mousey)
                    elif select=='u':
                        u.rect.center=(mousex,mousey)
            if event.type==MOUSEBUTTONUP:
                for n in wallAs:                  
                    if not m.rect.colliderect(n.rect):
                        print "False"
                        grab=False
                    else:
                        print "True"
                        doh.play()
                        grab = False
                        n.kill()
        for alien in pygame.sprite.spritecollide(hand,wallAs,False):
            pass
        hand.posx,hand.posy=mousex,mousey
        disp.blit(background, (0,0))
        dirty=every.draw(disp)
        pygame.display.update(dirty)
        every.update()
        pygame.display.update()
        clock.tick(40)
    pygame.quit()
    fgrid.close()
game()