Commit 209ab183 by BellCodeEditor

save project

parent b9b04485
Showing with 7 additions and 2 deletions
import pygame
from pygame import locals
import random
# 初始化pygame,为使用硬件做准备
pygame.init()
......@@ -17,6 +17,7 @@ body = pygame.image.load('body.png')
x,y=240,120
position=[(180,90),(180,120),(210,120),(x,y)]
apple_x=360
apple_y=300
apple_head=360
setheading='right'
......@@ -30,12 +31,16 @@ while True:
if event.type==locals.KEYDOWN:
if event.key==locals.K_RIGHT and setheading !="left":
setheading='right'
snake_head=right
if event.key==locals.K_LEFT and setheading !="right":
setheading='left'
snake_head=left
if event.key==locals.K_UP and setheading !="down":
setheading='up'
snake_head=up
if event.key==locals.K_DOWN and setheading !="up":
setheading='down'
snake_head=down
if setheading=="right":
x+=30
......@@ -48,7 +53,7 @@ while True:
position.append((x,y))
if x==apple_x and y==apple_y
if x==apple_x and y==apple_y:
apple_x=random.randint(0,660)
apple_y=random.randint(0,480)
......
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