import pygame
import sys
from pygame.locals import *
from random import *
WHITE = (255,255,255)
BLACK = (0,0,0)
GREEN = (0,255,0)
REN = (255,0,0)
BLUE = (0,0,255)
pygame.init()
size = width, height = 400, 400
screen = pygame.display.set_mode(size)
pygame.display.set_caption("欧阳麟君")
shetou = [20]
clock = pygame.time.Clock()
# 蛇身
she = [(pygame.draw.rect(screen,REN,(160,160,40,40),0))]
pygame.draw.she[0]
shetou = [160,160]
def main():
while True:
screen.fill(WHITE)
##########################下面宫格线条绘制 ##########################
# 横
pygame.draw.aaline(screen,BLACK,(0,0),(400,0),1)
pygame.draw.aaline(screen,BLACK,(0,40),(400,40),1)
pygame.draw.aaline(screen,BLACK,(0,80),(400,80),1)
pygame.draw.aaline(screen,BLACK,(0,120),(400,120),1)
pygame.draw.aaline(screen,BLACK,(0,160),(400,160),1)
pygame.draw.aaline(screen,BLACK,(0,200),(400,200),1)
pygame.draw.aaline(screen,BLACK,(0,240),(400,240),1)
pygame.draw.aaline(screen,BLACK,(0,280),(400,280),1)
pygame.draw.aaline(screen,BLACK,(0,320),(400,320),1)
pygame.draw.aaline(screen,BLACK,(0,360),(400,360),1)
# 竖
pygame.draw.aaline(screen,BLACK,(40,0),(40,400),1)
pygame.draw.aaline(screen,BLACK,(80,0),(80,400),1)
pygame.draw.aaline(screen,BLACK,(120,0),(120,400),1)
pygame.draw.aaline(screen,BLACK,(160,0),(160,400),1)
pygame.draw.aaline(screen,BLACK,(200,0),(200,400),1)
pygame.draw.aaline(screen,BLACK,(240,0),(240,400),1)
pygame.draw.aaline(screen,BLACK,(280,0),(280,400),1)
pygame.draw.aaline(screen,BLACK,(320,0),(320,400),1)
pygame.draw.aaline(screen,BLACK,(360,0),(360,400),1)
########################## 上面宫格线条绘制 ##########################
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
elif event.type == KEYDOWN:
if event.key == K_LEFT:# 左
shetou[0] = shetou[0]-40
if event.key == K_RIGHT:# 右
shetou[0] = shetou[0]+40
if event.key == K_UP: # 上
shetou[1] = shetou[1]-40
if event.key == K_DOWN: #下
shetou[1] = shetou[1]+40
she[0]
pygame.draw.rect(screen,REN,(shetou[0],shetou[1],40,40),0)
pygame.display.flip()
clock.tick(30)
if __name__ == "__main__":
main()
如何增加蛇身,利用多边形?这样可以移动