美文网首页
pygame - alphabet

pygame - alphabet

作者: zxlele_c763 | 来源:发表于2021-05-26 16:47 被阅读0次

    pygame install

    pygame install

    Windows installation

    Make sure you install python3.6 with the "Add python 3.6 to PATH" option selected. This means that python, and pip will work for you from the command line.

    There is documentation with python for the "windows installation steps"

    py -m pip install -U pygame --user
    py -m pygame.examples.aliens

    Mac installation

    • python3 -m pip install -U pygame --user

    python codes:

    import sys, pygame
    pygame.init()
    
    size = width, height = 1200, 650
    #speed = [0, 1]
    speed = [1, 1]
    black = 0, 0, 0
    
    screen = pygame.display.set_mode(size)
    
    #ball = pygame.image.load(r'C:\PF1E5DG3-Data\xianaz\Desktop\programing\python\python_base\pygame\earth.gif')
    ball = pygame.image.load(r'C:\PF1E5DG3-Data\xianaz\Desktop\programing\python\python_base\pygame\resources\A.gif')
    ballrect = ball.get_rect()
    
    Aball = pygame.image.load(r'C:\PF1E5DG3-Data\xianaz\Desktop\programing\python\python_base\pygame\resources\A.gif')
    Aballrect = Aball.get_rect()
    
    Bball = pygame.image.load(r'C:\PF1E5DG3-Data\xianaz\Desktop\programing\python\python_base\pygame\resources\B.gif')
    Bballrect = Bball.get_rect()
    #ballrect = Aballrect
    
    
    fireball = pygame.image.load(r'C:\PF1E5DG3-Data\xianaz\Desktop\programing\python\python_base\pygame\resources\fire.gif')
    fireballrect = fireball.get_rect()
    
    
    ballrect.left += 120
    
    CurrentAlphabit = pygame.K_a
    isFire = False
    rightInput = False
    
    firexValue = ballrect.left
    xValue = ballrect.left
    yValue = ballrect.bottom
    
    while 1:
        #pygame.event.set_grab(True)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            if pygame.KEYDOWN == event.type:
                if (event.key == pygame.K_b and pygame.K_b == CurrentAlphabit):
                    xValue = ballrect.left;
                    yValue = ballrect.top;
                    ballrect = Aballrect
                    ball = Aball
                    CurrentAlphabit = pygame.K_a
                    isFire = True
                    ballrect.left += 20
                    if ballrect.right > width:
                        ballrect.left = 30
                if (event.key == pygame.K_a and  pygame.K_a == CurrentAlphabit) :
                    xValue = ballrect.left;
                    yValue = ballrect.top;
                    ballrect = Bballrect
                    ball = Bball
    
                    ballrect.left += 20
                    isFire = True
                    rightInput = True
                    CurrentAlphabit = pygame.K_b 
                    
                    if ballrect.right > width:
                        ballrect.left = 30
    
        if isFire:
            fireballrect.left = xValue
            #fireballrect.right = Aballrect.right
            fireballrect.top = yValue
            #fireballrect.bottom = Aballrect.bottom
            screen.fill(black)
            screen.blit(fireball, fireballrect)
            pygame.display.flip()
            pygame.time.wait(300)
            screen.fill(black)
            pygame.display.flip()
            #pygame.display.quit()
            #screen.clear()
            xValue = ballrect.left
            yValue = ballrect.bottom
            isFire = False
            continue;
        
        pygame.time.wait(3)
        ballrect = ballrect.move(speed)
        if ballrect.left < 0 or ballrect.right > width:
            speed[0] = -speed[0]
        if ballrect.top < 0 or ballrect.bottom > height:
            speed[1] = -speed[1]
    
        screen.fill(black)
        screen.blit(ball, ballrect)
    
        pygame.display.flip()
    

    相关文章

      网友评论

          本文标题:pygame - alphabet

          本文链接:https://www.haomeiwen.com/subject/fbgksltx.html