Commit 6e80ec82 by BellCodeEditor

save project

parent f68b98f3
Showing with 7 additions and 1 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import random
pygame.init() pygame.init()
screen = pygame.display.set_mode((660, 480)) screen = pygame.display.set_mode((660, 480))
FPSCLOCK=pygame.time.Clock() FPSCLOCK=pygame.time.Clock()
...@@ -12,6 +13,8 @@ up = pygame.image.load('up.png') ...@@ -12,6 +13,8 @@ up = pygame.image.load('up.png')
down = pygame.image.load('down.png') down = pygame.image.load('down.png')
x,y = 240,120 x,y = 240,120
List=[(180,90),(180,120),(210,120),(x,y)] List=[(180,90),(180,120),(210,120),(x,y)]
apple_x = 360
apple_y = 300
SetHead='right' SetHead='right'
snake_head=right snake_head=right
while True: while True:
...@@ -40,11 +43,14 @@ while True: ...@@ -40,11 +43,14 @@ while True:
else: else:
y+=30 y+=30
List.append((x,y)) List.append((x,y))
if x == apple_x and y == apple_y:
apple_x = random.randint(0,660)
apple_y = random.randint(0,480)
List.pop(0) List.pop(0)
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
screen.blit(snake_head, List[-1]) screen.blit(snake_head, List[-1])
for i in range(len(List)-1): for i in range(len(List)-1):
screen.blit(body, List[i]) screen.blit(body, List[i])
screen.blit(food, (360, 300)) screen.blit(food, (apple_x, apple_y))
pygame.display.update() pygame.display.update()
FPSCLOCK.tick(3) FPSCLOCK.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