pygame老鼠过街-配音与封面版本

pygame老鼠过街-配音与封面版本


马路上车来车往,请操作可怜的小老鼠过街去找妈妈吧。

"""pygame老鼠过街-配音与封面版本,在川流不息的车流中,你需要操作一只小老鼠成功过街."""

import pygame
from pygame.locals import *
from random import randint
import time,sys

class Rat():
    def __init__(self,images,x,y,w,h):
        self.framesList = images        # 造型列表
        self.造型切换间隔时长=0.4       # 以秒为单位
        self.过关=False
        self.rect = pygame.Rect(x,y,w,h)
        self.造型编号=0
        self.begintime = time.time()
        pass       

class GameObject():
    def __init__(self,framesRight,framesLeft,x,y,w,h):
        self.frames_right = framesRight
        self.frames_left = framesLeft
        self.造型数量 = len(self.frames_left)
        self.造型编号=0
        self.造型切换间隔时长=0.1    # 以秒为单位
        self.移动间隔时长=0.03       # 以秒为单位 
        self.rect = pygame.Rect(x,y,w,h)
        self.xspeed=randint(1,5)
        self.yspeed=0
        self.begintime = time.time()
        self.begintime2 = time.time()
        
    pass
            
    def collide(self,rat):
        if self.rect.colliderect(rat.rect):
            return True
        else:
            return False        

pygame.init()
screen_width,screen_height=480,360
screen = pygame.display.set_mode((screen_width,screen_height))
pygame.display.set_caption("pygame老鼠过街--作者:李兴球")
背景 = pygame.image.load("街道.png")
 
BellToll  = pygame.mixer.Sound("BellToll.wav")
Cricket  = pygame.mixer.Sound("Cricket.wav")
Cricket.play()
Laugh_male1 = pygame.mixer.Sound("Laugh-male1.wav")
pygame.mixer.music.load("欢快女唱电.wav")
pygame.mixer.music.play(-1,0)

rat0 = pygame.image.load("mouse1-a.png")
rat1 = pygame.image.load("mouse1-b.png")
rats = [rat0,rat1]
rat = Rat(rats,screen_width//2,screen_height-30,20,30)
frame0 = pygame.image.load("小汽车.png") 
framesRight = [frame0]
framesLeft = [pygame.transform.flip(f,True,False) for f in framesRight]

font = pygame.font.Font("c:/windows/fonts/msyh.ttf",30)
textstring = " "
textImage =font.render(textstring,True,(0,255,255))
(tx,ty,tw,th) = textImage.get_rect()
textpos=(screen_width//2 - tw //2,screen_height//2 - th/2 -100)
#新建一些小汽车
car1 = GameObject(framesRight,framesLeft,100,30,70,30)
car2 = GameObject(framesRight,framesLeft,200,160,70,30)
car3 = GameObject(framesRight,framesLeft,300,260,70,30)
car4 = GameObject(framesRight,framesLeft,400,200,70,30)
car5 = GameObject(framesRight,framesLeft,230,90,70,30)
cars = [ car1,car2,car3,car4,car5]

封面  = pygame.image.load("封面设计.png")
running = True
game_over = False
while running:
    for event in pygame.event.get():
        if event.type==QUIT:
            running=False
            game_over = True
        if event.type==KEYDOWN or event.type==MOUSEBUTTONDOWN:
            running=False
    screen.blit(封面,(0,0))
    pygame.display.update()

if game_over == True: pygame.quit();sys.exit()

# 进入游戏循环
pass
# 退出游戏循环显示结果

# 根据不同的游戏结果显示不同的字符            
textImage =font.render(textstring,True,(0,255,255))
(tx,ty,tw,th) = textImage.get_rect()
textpos=(screen_width//2 - tw //2,screen_height//2 - th/2 -100)
screen.blit(textImage,textpos)
pygame.display.update()
while True:
    event = pygame.event.wait()
    if event.type == QUIT:break
pygame.quit()

 

如需要下载完整源代码及素材, 请

成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)

李兴球

李兴球的博客是Python创意编程原创博客