pygame stops after display.update

Asked by At

I've programmed a game ("Dodgeball"), which has a start-menue, but if I pressed the play-button, screen doesn't do anything, although there is a 'show function' every turn, but the program works still and shows output in the console.

The Program worked already, but now I want to add a menue to it. Please excuse me, if I missed anything to say - this is my first question on a forum and sorry for my bad english.

class Button(object):
    def __init__(self,x,y,label):
        self.surround = 10
        self.width = 400
        self.height = 60
        self.x = x - self.width/2
        self.y = y - self.height/2
        self.label = label
        self.borderColor = (100,100,255)
        self.pressedColor = (0,0,120)
        self.mouseOverButtonColor = (0,0,150)
        self.basicColor = (0,0,200)
        self.borderThickness = 2
        self.rect = pg.Rect(self.x, self.y,self.width, self.height)
        self.rectOut = pg.Rect(self.x-self.borderThickness, self.y-self.borderThickness,self.width+2*self.borderThickness, self.height+2*self.borderThickness)
        self.font = pg.font.Font('freesansbold.ttf', 80)
        self.label = font.render(self.label, True, fontColor)
        self.labelwidth = self.label.get_width()
        self.labelheight = self.label.get_height()
    def checkMouseOverButton(self):
        x, y = pg.mouse.get_pos()
        if self.x < x < self.x+self.width and self.y < y < self.y+self.height:
            return True
            return False
    def show(self):
        x, y = pg.mouse.get_pos()
        leftPressed,rightPressed,middelPressed = pg.mouse.get_pressed()
        pg.draw.rect(screen, self.lineColor, self.rectOut)
        if self.x < x < self.x+self.width and self.y < y < self.y+self.height:
            if leftPressed:
                pg.draw.rect(screen, self.pressedColor, self.rect)
                pg.draw.rect(screen, self.mouseOverButtonColor, self.rect)
            pg.draw.rect(screen, self.basicColor, self.rect)

def game():
    global heartnumber,probability,stripespeed,score
    player.gotomouse() #own Function
    if heartnumber == 0: #check for life-condition
        run = False
    if r.randrange(0,1000) < probability: #new stripe falling down
        newstripex = r.randrange(0,screenWidth)
        newstripe = projectile(round(stripespeed+r.randrange(-2,12)), newstripex, -64, newstripex+8)
        print("New Stripe:{}".format(newstripe))
    for stripe in stripes:
        stripe.position['y1'] += stripe.speed
        stripe.position['y2'] += stripe.speed

        if collision(stripe.position['x1'], stripe.position['y1'],stripe.position['x2']-stripe.position['x1'], stripe.position['y2']-stripe.position['y1'],player.position['x1']+player.width/2, player.position['y1']+player.height/2, player.width/2):
            print("Heartnumber -= 1")
            heartnumber -= 1
            del stripes[stripes.index(stripe)]

        '''if stripe.position['y2'] > player.position['y1'] + 60:
            if not player.position['x2'] < stripe.position['x1'] and not player.position['x1'] > stripe.position['x2']:
                heartnumber -= 1
                del stripes[stripes.index(stripe)]'''
        if stripe.position['y1'] >= screenHeight:
            print("Stripe '{}' deleted and Score += 1'".format(stripe))
            score += 1
            probability += probability_addition
            stripespeed += stripespeedaddition

def show():
    global fpsLabel
    for g in range(heartnumber):
        screen.blit(heart, (screenWidth * (0.95 - g * 0.05) ,15))
    screen.blit(scorelabel, (20,20))
    scorel = font.render((str(score)), 10, fontColor)
    screen.blit(scorel, (200,20))
    for stripe in stripes:
        screen.blit(stripe.pic, (stripe.position['x1'], stripe.position['y1']))
    print("New Pic")

while work:
    print("New Work Run")
    clock = pg.time.Clock()
    stripes = []
    run = True
    quit = False
    mLeftClick = False
    player = Player(0, screenHeight*0.92)

    print("Startmethod ready")
    while run != 0:
        print("Next run")

This is the important part of the output:

the startLoop L-I-V-E-S
the startLoop L-I-V-E-S
Playbutton pressed
Startmethod ready
New Pic
Next run
New Pic
Next run
New Pic
Next run
New Pic
Next run
New Pic
Next run
New Stripe:<__main__.projectile object at 0x102b3bf60>
New Pic
Next run

0 Answers