贪吃蛇
import pygameimport sys
from pygame.locals import *
import random
pygame.init()
white=(255,255,255)
bg=(255,255,255)
black=(0,0,0)
left=50
top=50
speed = [-2, 1]
size = width,height = 640,640
screen = pygame.display.set_mode(size)
pygame.display.set_caption('贪吃蛇')
clock=pygame.time.Clock()
rectangle=pygame.draw.rect(screen,black,(left,top,50,50),1)
while True:
for event in pygame.event.get():
if event.type == QUIT:
sys.exit(0)
if event.type == KEYDOWN:
if event.key == K_LEFT:
speed = [-5, 0]
if event.key == K_RIGHT:
speed =
if event.key == K_UP:
speed =
if event.key == K_DOWN:
speed =
if left < 0 or left > 590:
# 翻转图像
# 反方向移动
speed = -speed
speed = -speed
if top < 0 or top > 590:
speed = -speed
speed = -speed
'''screen.fill(white)
pygame.draw.rect(screen,black,(left,top,50,50),1)'''
left=left+speed
top=top+speed
screen.fill(bg)
# 更新图像
pygame.draw.rect(screen,black,(left,top,50,50),1)
# 更新界面
pygame.display.flip()
# 延迟10毫秒
pygame.time.delay(30)
貌似忽然间发现了贪吃蛇的雏形 你是原创?? Mike_python小 发表于 2020-5-22 14:55
你是原创??
呃,哥们,这还不是成型的游戏,只是贪吃蛇的一个小部分的功能模块,原创也不失我,是小甲鱼。哈哈哈哈 {:10_275:}
页:
[1]