本文为大家分享了pygame游戏之旅的第14篇,供大家参考,具体内容如下
添加icon需要用的函数是:
gameIcon = pygame.image.load("carIcon.png")
pygame.display.set_icon(gameIcon)
添加bgm和音效的函数是:
crash_sound = pygame.mixer.Sound("crashed.wav")
pygame.mixer.music.load("bgm.wav")
源码:
import pygame
import time
import random
pygame.init()
crash_sound = pygame.mixer.Sound("crashed.wav")
pygame.mixer.music.load("bgm.wav")
white = (255,255,255)
black = (0,0,0)
gray = (128,128,128)
red = (200,0,0)
green = (0,200,0)
bright_red = (255,0,0)
bright_green = (0,255,0)
blue = (0,0,255)
car_width = 100
display_width = 800
display_height = 600
gameDisplay = pygame.display.set_mode( (display_width,display_height) )
pygame.display.set_caption('A bit Racey')
clock = pygame.time.Clock()
carImg = pygame.image.load('car.png')
gameIcon = pygame.image.load("carIcon.png")
pygame.display.set_icon(gameIcon)
pause = False
##crash = True
def things_dodged(count):
font = pygame.font.SysFont(None, 25)
text = font.render("Dodged:"+str(count), True, black)
gameDisplay.blit(text,(0,0))
def thing