可以用pygame模块中的绘制图形来整一个贪吃蛇吗?
可以用pygame模块中的绘制图形来整一个贪吃蛇吗?图形移动的时候如何添加一个蛇尾,
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 =
clock = pygame.time.Clock()
# 蛇身
she = [(pygame.draw.rect(screen,REN,(160,160,40,40),0))]
pygame.draw.she
shetou =
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 = shetou-40
if event.key == K_RIGHT:# 右
shetou = shetou+40
if event.key == K_UP: # 上
shetou = shetou-40
if event.key == K_DOWN: #下
shetou = shetou+40
she
pygame.draw.rect(screen,REN,(shetou,shetou,40,40),0)
pygame.display.flip()
clock.tick(30)
if __name__ == "__main__":
main()
{:10_249:}{:10_249:}{:10_256:}{:10_256:}{:10_256:}怎么填充后边的蛇尾,从而不导致他直接刷没了,剩下的撞墙,撞到自身蛇尾的我慢慢完善,{:10_254:}{:10_254:} {:10_269:}{:10_266:}{:10_266:}{:10_266:}是不是发错版块了,应该发问题求助{:10_266:}
页:
[1]