Commit fa695f7c by BellCodeEditor

save project

parent abf830f5
Showing with 12 additions and 6 deletions
import pygame
from pygame import locals
import random
pygame.init()
screen=pygame.display.set_mode((660,480))
FPSCLOCK=pygame.time.Clock()
......@@ -12,6 +13,8 @@ up=pygame.image.load("up.png")
down=pygame.image.load("down.png")
x,y=240,120
position=[(180,90),(180,120),(210,120),(x,y)]
apple_x=360
apple_y=300
setheading="right"
snake_head=right
while True:
......@@ -26,10 +29,10 @@ while True:
setheading="left"
snake_head=left
if event.key==locals.K_UP and setheading!="down":
setheading=="up"
setheading="up"
snake_head=up
if event.key==locals.K_DOWN and setheading!="up":
setheading=="down"
setheading="down"
snake_head=down
if setheading=="right":
x+=30
......@@ -40,12 +43,14 @@ while True:
else:
y+=30
position.append((x,y))
if x==apple_x and y==apple_y:
apple_x=random.randint(0,660)
apple_y=random.randint(0,480)
position.pop(0)
screen.blit(background,(0,0))
screen.blit(snake_head,position[-1])
for t in range(len(position)-1):
screen.blit(body,position[t])
screen.blit(food,(360,300))
for i in range(len(position)-1):
screen.blit(body,position[i])
screen.blit(food,(apple_x,apple_y))
pygame.display.update()
FPSCLOCK.tick(3)
\ No newline at end of file
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