好了废话不多说直接上代码
import pygame, sys, randomfrom pygame.locals import * pygame.init()mainClock = pygame.time.Clock() WINDOWWIDTH = 400WINDOWHEIGHT = 400rectLength = 18 windowSurface = pygame.display.set_mode((WINDOWWIDTH,WINDOWHEIGHT),0,32)pygame.display.set_caption(‘Snake’) BLACK = (0,0,0)GREEN = (0,255,0) snakeRect = []for i in range(7,10): snakeRect.append(pygame.Rect(i*(rectLength+2)+1,0+1,rectLength,rectLength))food = pygame.Rect(5*(rectLength+2),5*(rectLength+2),rectLength+2,rectLength+2) moveLeft = TruemoveRight = FalsemoveUp = FalsemoveDown = False direction = 1foodImage = pygame.image.load(‘cherry.png’)pygame.mixer.music.load(‘background.mid’)pygame.mixer.music.play(-1,0.0) pickUpSound = pygame.mixer.Sound(‘pickup.wav’)while True: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYDOWN: if event.key == K_LEFT
用python实现贪吃蛇
最新推荐文章于 2024-03-13 21:31:57 发布