Commit 1f9be5b8 by BellCodeEditor

save project

parent c757cd91
Showing with 18 additions and 3 deletions
import pygame
from pygame import locals
import random
pygame.init()
time=pygame.time.Clock()
x=240
y=120
apple_x=360
apple_y=300
setheading='right'
screen=pygame.display.set_mode((660,480))
shenti=[(180,90),(180,120),(210,120),(x,y)]
......@@ -14,6 +17,7 @@ right = pygame.image.load('right.png')
left = pygame.image.load('left.png')
up = pygame.image.load('up.png')
down = pygame.image.load('down.png')
setheading="right"
snake_head=right
......@@ -40,16 +44,27 @@ while True:
elif setheading=="left":
x-=30
elif setheading=="up":
y+=30
y-=30
else:
y-=30
y+=30
position.append((x,y))
position.pop(0)
if x==apple_x and y==apple_y:
apple_x=random.randint(0,660)
apple_y=random.randint(0,480)
shenti.append((x,y))
shenti.pop(0)
screen.blit(bg,(0,0))
screen.blit(snake_head,shenti[-1])
for i in range(len(shenti)-1):
screen.blit(body,shenti[i])
screen.blit(food,(360,300))
screen.blit(food,(apple_x,apple_y))
pygame.display.update()
time.tick(3)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment