pygame游戏之旅游戏之旅 调用按钮实现游戏开始功能调用按钮实现游戏开始功能
主要为大家详细介绍了pygame游戏之旅的第12篇,教大家调用按钮实现游戏开始功能,具有一定的参考价值,
感兴趣的小伙伴们可以参考一下
本文为大家分享了pygame游戏之旅的第12篇,供大家参考,具体内容如下
实现点击功能:
click = pygame.mouse.get_pressed()
print(click)
if x + w > mouse[0] > x and y + h > mouse[1] > y:
pygame.draw.rect(gameDisplay, ac, (x,y,w,h))
if click[0] == 1 and action != None:
action()
修改显示文字:
pygame.font.SysFont('comicsansms',115)
源代码:
import pygame
import time
import random
pygame.init()
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')
def things_dodged(count):
font = pygame.font.SysFont(None, 25)
text = font.render("Dodged:"+str(count), True, black)
gameDisplay.blit(text,(0,0))
def things(thingx, thingy, thingw, thingh, color):
pygame.draw.rect(gameDisplay, color, [thingx, thingy, thingw, thingh])
def car(x, y):
gameDisplay.blit(carImg, (x,y))
def text_objects(text, font):
textSurface = font.render(text, True, black)
return textSurface, textSurface.get_rect()
def message_diaplay(text):
largeText = pygame.font.SysFont('comicsansms',115)
TextSurf, TextRect = text_objects(text, largeText)
TextRect.center = ((display_width/2),(display_height/2))
gameDisplay.blit(TextSurf, TextRect)
pygame.display.update()
time.sleep(2)
game_loop()
def crash():
评论0
最新资源