0

os version =windows xp
hi guys i'm having problems using pygame the following code just does not seem to work.
Code: ( text )

1.
clock=pygame.time.Clock()
2.
while True:
3.
sound1.play()
4.
clock.tick(60)
5.
pKeys = pygame.key.get_pressed()
6.
Eves=pygame.event.get()
7.
villian.face()
8.
villian.hert()
9.
if Eves[KEYDOWN] and pKeys[K_UP]:
10.
hero.moveup()
11.
if Eves[KEYUP] and pKeys[K_UP]:
12.
hero.gravity()
13.
if Eves[KEYDOWN] and pKeys[K_DOWN]:
14.
hero.movedown()
15.
if Eves[KEYDOWN] and pKeys[K_RIGHT]:
16.
hero.forward()
17.
if Eves[KEYDOWN] and pKeys[K_LEFT]:
18.
hero.back()
19.
if Eves[KEYDOWN] and pKeys[97]:
20.
sound.play()
21.
hero.reShape()
22.
if Eves[KEYUP] and pKeys[97]:
23.
hero.Shape()
24.
if Eves[KEYDOWN] and pKeys[115]:
25.
hero.Kick()
26.
if Eves[QUIT]:
27.
pygame.quit()
28.
raise SystemExit()
29.
allsprites.update()
30.
screen.blit(background,(0,0))
31.
allsprites.draw(screen)
32.
pygame.display.flip()
33.
time.sleep(1/30)

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by joshuabraham
0

The appropriate code tags are

[code="Python"] ## code here

[/code]

What's happening? I'm guessing that the sound plays, but then the code hangs after that?

Jeff

0

sorry for taking so long to reply have not been able to get online.this is the complete code

import pygame
import time
from pygame.locals import *
pygame.init()
screen=pygame.display.set_mode((800,620))
class Hero(pygame.sprite.Sprite):
    def __init__(self,img):
        pygame.sprite.Sprite.__init__(self)
        self.image=pygame.Surface((100,220))
        self.zin=pygame.image.load(img)
        self.zin=self.zin.convert()
        self.sin=pygame.image.load("C:/Python24/redhead.GIF")
        self.sin=self.sin.convert()
        self.highkick=pygame.image.load("C:\Python24\highkick.GIF")
        self.highkick=self.highkick.convert()
        self.lowkick=pygame.image.load("C:\Python24\lowkick.Gif")
        self.lowkick=self.lowkick.convert()
        self.image.blit(self.zin,(0,0))
        self.rect=self.image.get_rect()
        self.rect.topleft=0,400
        self.a=screen.get_rect()
        self.a1=0
    def forward(self):
        self.a1=1
    def back(self):
        self.a1=2
    def original(self):
        self.rect.topleft=0,400
    def moveup(self):
        self.a1=3  
    def movedown(self):
        self.a1=4
    def reShape(self):
        self.a1=5
    def Shape(self):
        self.a1=6
    def Kick(self):
        self.a1=7
    def lowKick(self):
        self.a1=8
    def gravity(self):
        self.a1=9
    def update(self):
        if self.a1==0:
            self.original()
        if self.a1==1:
            if self.rect.right<=self.a.right:
                self.rect.move_ip(5,0)
            else:
                self.rect.move_ip(0,0)
        if self.a1==2:
            if self.rect.left!=0 :
                self.rect.move_ip(-5,0)
            else:
                self.rect.move_ip(0,0)
        if self.a1==3:
            if self.rect.topleft[1]!=200:
                self.rect.move_ip(0,-200)
            
        if self.a1==4:
            if self.rect.bottom!=self.a.bottom:
                self.rect.move_ip(0,5)
            else:
                self.rect.move_ip(0,-5)
        if self.a1==5:
            self.image.fill((0,0,0))
            self.image.blit(self.sin,(0,0))
        if self.a1==6:
            self.image.fill((0,0,0))
            self.image.blit(self.zin,(0,0))
        if self.a1==7:
            self.image.fill((0,0,0))
            self.image.blit(self.highkick,(0,0))
        if self.a1==8:
            self.image.blit((0,0,0))
            self.image.blit(self.lowkick,(0,0))
        if self.a1==9:
            if self.rect.bottom!=self.a.bottom:
                self.rect.move_ip(0,200)
            
class Villian(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.image=pygame.Surface((100,220))
        self.fr6nt=pygame.image.load('C:/Python24/toba-pyweek3/toba-pyweek3/data/cards/1.PNG')
        self.fr6nt=self.fr6nt.convert()
        self.bac2=pygame.image.load('C:/Documents and Settings/xx/Desktop/c++ tutor/js3e3/mouse3.GIF')
        self.bac2=self.bac2.convert()
        self.image.blit(self.bac2,(0,0))
        self.rect=self.image.get_rect()
        self.rect.topleft=400,500
        self.a1=0
    def forward(self):
        self.rect.move_ip(0,5)
    def face (self):
        if hero.rect.x<=self.rect.left:
            self.a1=0
        else:
            self.a1=1
    def hert (self):
        if self.rect.colliderect(hero):
            self.a1=2
        
    def update(self):
        if self.a1==0:
           self.image.fill((0,0,0))
           self.image.blit(self.bac2,(0,0)) 
        if self.a1==1:
            self.image.fill((0,0,0))
            self.image.blit(self.fr6nt,(0,0))
        if self.a1==2:
            self.image.fill((0,0,0))
            self.image.blit(self.fr6nt,(0,0))
            
        if self.rect.top!=900:
            self.forward()
        else:
            self.original()
    def original(self):
        self.rect.topleft=400,500

imig=pygame.image.load('C:/Python24/Blue hills.GIF')
background=pygame.Surface(screen.get_size())
background=background.convert()
background.blit(imig,(0,0))
screen.blit(background,(0,0))
test="C:/Python24/r3.PNG"
red="C:/Python24/redhead.GIF"
hero=Hero(test)
villian=Villian()
sound = pygame.mixer.Sound('C:/Python25/other python games/Cherry_Chat/media/woohoo.WAV')
sound1 = pygame.mixer.Sound('C:/Python25/other python games/Cherry_Chat/media/wish-you-were-here.WAV')
allsprites=pygame.sprite.RenderPlain((hero,villian))
allsprites.draw(screen)
pygame.display.flip()

clock=pygame.time.Clock()
while True:
    sound1.play()
    clock.tick(60)
    pKeys = pygame.key.get_pressed()
    Eves=pygame.event.get()
    villian.face()
    villian.hert()
    if Eves[KEYDOWN] and pKeys[K_UP]:
        hero.moveup()
    if Eves[KEYUP] and pKeys[K_UP]:
        hero.gravity()
    if Eves[KEYDOWN] and pKeys[K_DOWN]:
        hero.movedown()
    if Eves[KEYDOWN] and pKeys[K_RIGHT]:
        hero.forward()
    if Eves[KEYDOWN] and pKeys[K_LEFT]:
        hero.back()
    if Eves[KEYDOWN] and pKeys[97]:
        sound.play()
        hero.reShape()
    if Eves[KEYUP] and pKeys[97]:
        hero.Shape()
    if Eves[KEYDOWN] and pKeys[115]:
        hero.Kick()
    if Eves[QUIT]:
        pygame.quit()
        raise SystemExit()
    allsprites.update()
    screen.blit(background,(0,0))
    allsprites.draw(screen)
    pygame.display.flip()
    time.sleep(1/30)
This article has been dead for over six months. Start a new discussion instead.
Be sure to adhere to our posting rules.