Ejemplo n.º 1
0
    if ball.rect.y <= 0:

        ball.speed[1] = -ball.speed[1]

    if pygame.sprite.collide_mask(ball, paddleL) or pygame.sprite.collide_mask(
            ball, paddleR):

        ball.bounce()

    # Clear the screen to black
    screen.fill(colors.BLACK)

    # Draw the net
    pygame.draw.line(screen, colors.WHITE, [599, 0], [599, 900], 5)

    # Draw the sprites
    sprites.draw(screen)

    # Display scores
    scoreLeft = ScoreDisplayer(None, 74, str(scoreA), colors.WHITE)
    scoreLeft.draw(screen, 280, 30)

    scoreRight = ScoreDisplayer(None, 74, str(scoreB), colors.WHITE)
    scoreRight.draw(screen, 880, 30)

    # Updating the screen what we've drawn
    pygame.display.flip()

    # Limit to 60 FPS
    clock.tick()
Ejemplo n.º 2
0
def main():
    """this function is called when the program starts.
       it initializes everything it needs, then runs in
       a loop until the function returns."""
    # Initialize Everything
    pygame.init()
    screen = pygame.display.set_mode((800, 600))
    pygame.key.set_repeat(500,30)
    pygame.display.set_caption('Skydive demo')
    pygame.mouse.set_visible(0)

    red   = 255,  0,  0
    green =   0,255,  0
    choose = dm.dumbmenu(screen, [
                            'Start Game',
                            'Options',
                            'Manual',
                            'Show Highscore',
                            'Quit Game'], 64,64,None,32,1.4,green,red)

    if choose == 0:
        print "You choose 'Start Game'."
    elif choose == 1:
        print "You choose 'Options'."
    elif choose == 2:
        print "You choose 'Manual'."
    elif choose == 3:
        print "You choose 'Show Highscore'."
    elif choose == 4:
        pygame.quit()
        exit()

    # Setup the scoreboard
    format_ = "0000.00"
    myfont = pygame.font.Font(pygame.font.match_font('arial'),12)
    color = 'red'

    sd = ScoreDisplayer(format_, myfont, color) 
    sd.center = 750,550 

    pygame.time.set_timer(USEREVENT,20)

    score = 0    
        
    # Create The Backgound
    background, background_rect = load_image('mount_everest.jpg', -1)
    
    # Put Text On The Background, Centered
    if pygame.font:
        font = pygame.font.Font(None, 36)
        text = font.render("Pummel The Chimp, And Win ", 1, (10, 10, 10))
        textpos = text.get_rect(centerx=background.get_width()/2)
        background.blit(text, textpos)

    # Display The Background
    screen.blit(background, (0, 0))
    pygame.display.flip()

    # Prepare Game Objects
    clock = pygame.time.Clock()
    whiff_sound = load_sound('whiff.wav')
    punch_sound = load_sound('punch.wav')
    chimp = Chimp()
    fist = Fist()
    
    # Create our skydiver animation
    animObj = skydiver_anim()
    animObj.pause()
    # Create the group of sprites
    allsprites = pygame.sprite.RenderPlain((fist, chimp))
    
    # Main Loop
    going = True
    while going:
        clock.tick(60)

        #Handle Input Events
        for event in pygame.event.get():
            if event.type == QUIT:
                going = False
            elif event.type == KEYDOWN and event.key == K_UP:
                animObj.play()
            elif event.type == MOUSEBUTTONDOWN:
                if fist.punch(chimp):
                    punch_sound.play() #punch
                    chimp.punched()
                else:
                    whiff_sound.play() #miss
            elif event.type == MOUSEBUTTONUP:
                fist.unpunch()
            # Score stuff
            if event.type == USEREVENT:    
            	  screen.fill(0,sd)          
            	  screen.blit(sd.image,sd)   
            	  pygame.display.update(sd)

            if event.type == KEYDOWN:

                if event.key == K_DOWN:      
                    score += 183.73
                    sd.set(score,200)  

                elif event.key == K_ESCAPE:
                    score = 0
                    sd.set(score)
        
        allsprites.update()

        #Draw Everything
        screen.blit(background, (0, 0))
        animObj.blit(screen, (200, 200))
        allsprites.draw(screen)
        pygame.display.flip()
        
        if animObj._state ==  pyganim.STOPPED:
            animObj.pause()

    pygame.quit()
Ejemplo n.º 3
0
from pygame import *
font.init()
from scoredisplayer import ScoreDisplayer

scr = display.set_mode((600,300))

format_ = "0000.00"
myfont = font.Font(font.match_font('arial'),12)
color = 'red'

sd = ScoreDisplayer(format_, myfont, color) 
sd.center = 150,250 

time.set_timer(USEREVENT,20)

score = 0
while 1:
    ev = event.wait()

    if ev.type == USEREVENT:    
    	scr.fill(0,sd)          
    	scr.blit(sd.image,sd)   
    	display.update(sd)

    if ev.type == KEYDOWN:

        if ev.key == K_UP:      
            score += 183.73
            sd.set(score,200)  

        elif ev.key == K_ESCAPE: