pygame动画制作男孩女孩趣味对话

"""这是我用pygame制作的一个对话小程序,一个男孩和一个女孩进行对话。"""

import pygame
from pygame.locals import *

width,height = 960,720
sentences = ["我爱Python","真的吗?","当然是真的,我每天都用Python","我跟你学可以吗?","当然可以啊。","现在就开始吧。","。。。。。"]
background_image = "饭桌.png"
boy_image = "男孩.png"
girl_image = "女孩.png"

pygame.init()
screen = pygame.display.set_mode((width,height))
pygame.display.set_caption("pygame动画制作男孩女孩by李兴球@2018")

background = pygame.image.load(background_image)
boy = pygame.image.load(boy_image)
girl = pygame.image.load(girl_image)
screen.blit(background,(0,0))
screen.blit(boy,(0,200))
screen.blit(girl,(700,200))
pygame.display.update()

font = pygame.font.Font("msyh.ttf",26)
colors = [(0,0,250),(205,10,150)]
sentences_images = [ font.render(sentences[i],1,colors[i%2]) for i in range(len(sentences))]

frame = pygame.draw.rect(background,(0,255,255),(50,height-125,width-100,100),4)

time_counter  = 0
clock = pygame.time.Clock()
while time_counter < 1:                   # 等待1秒
    event = pygame.event.poll()
    clock.tick(1)
    time_counter = time_counter  + 1    

for sentence in sentences_images:        # 轮换显示对话
    event = pygame.event.poll()
    if event.type == QUIT:running = False
    screen.blit(background,(0,0))
    screen.blit(boy,(0,200))
    screen.blit(girl,(700,200))
    screen.blit(sentence,(100,height-100))
    pygame.display.update()
    clock.tick(0.5)    

running = True
while running:                           # 单击等待结束
本文隐藏内容 登陆 后才可以浏览
pygame.quit()

Python男孩女孩对话_pygame创意编程