Commit 3d0b8546 by BellCodeEditor

save project

parent 811d9294
Showing with 25 additions and 5 deletions
import pygame import pygame
import random
from pygame import locals from pygame import locals
pygame.init() pygame.init()
...@@ -14,13 +15,19 @@ body=pygame.image.load('body.png') ...@@ -14,13 +15,19 @@ body=pygame.image.load('body.png')
left=pygame.image.load('left.png') left=pygame.image.load('left.png')
up=pygame.image.load('up.png') up=pygame.image.load('up.png')
down=pygame.image.load('down.png') down=pygame.image.load('down.png')
my_font = pygame.font.Font('neuropol.ttf',18)
x, y = 240, 120 x, y = 240, 120
position = [(180,90),(180,120),(210,120),(x,y)] position = [(180,90),(180,120),(210,120),(x,y)]
apple_x = 360
apple_y = 300
setheading= "right" setheading= "right"
snake_head=right snake_head=right
score=0
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
...@@ -46,16 +53,29 @@ while True: ...@@ -46,16 +53,29 @@ while True:
y-=30 y-=30
else: else:
y+=30 y+=30
position.append((x,y)) if x ==apple_x and y == apple_y:
position.pop(0) a=random.randint(1,22)
b=random.randint(1,16)
apple_x = a*30-30
apple_y = b*30-30
score+=10
else:
position.pop(0)
if x < 0 or x > 630 or y < 0 or y > 450:
exit()
position.append((x,y))
screen.blit(background,(0,0)) screen.blit(background,(0,0))
screen.blit(snake_head,(position[3])) screen.blit(snake_head,(position[-1]))
for i in range(len(position)-1): for i in range(len(position)-1):
screen.blit(body,position[i]) screen.blit(body,position[i])
#screen.blit(body,(position[2])) #screen.blit(body,(position[2]))
#screen.blit(body,(position[1])) #screen.blit(body,(position[1]))
#screen.blit(body,(position[0])) #screen.blit(body,(position[0]))
screen.blit(food,(360,300)) screen.blit(food,(apple_x,apple_y))
info="Score"+str(score)
text=my_font.render(info,True,(0,0,0))
screen.blit(text,(540,0))
pygame.display.update() pygame.display.update()
FPSCLOCK.tick(10) FPSCLOCK.tick(7.5)
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