Commit b2c963b0 by BellCodeEditor

save project

parent 4de2e10c
Showing with 45 additions and 4 deletions
import pygame import pygame
pygame.init() pygame.init()
background=pygame.display.set_mode((660,480)) s=pygame.display.set_mode((660,480))
w=pygame.image.load('bg.png')
b=pygame.image.load('body.png')
h=pygame.image.load('right.png')
j=pygame.image.load('left.png')
p=pygame.image.load('up.png')
y=pygame.image.load('down.png')
a=pygame.image.load('apple.png')
k=pygame.time.Clock()
x,y=210,240
q=[(180,240),(150,240),(150,210),(x,y)]
setheading="right"
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
print(event)
if event.type==pygame.QUIT: if event.type==pygame.QUIT:
exit() exit()
\ No newline at end of file if event.type==pygame.KEYDOWN:
if event.key==pygame.K_RIGHT and setheading!="left":
setheading ="right"
snake_head=h
if event.key==pygame.K_LEFT and setheading!="right":
setheading ="left"
snake_head=j
if event.key==pygame.K_UP and setheading!="down":
setheading ="up"
snake_head=p
if event.key==pygame.K_DOWN and setheading!="up":
setheading ="down"
snake_head=y
if setheading=="right":
x+=30
if setheading=="left":
x-=30
if setheading=="down":
y+=30
if setheading=="up":
y-=30
s.blit(w,(0,0))
x+=30
q.append((x,y))
q.pop(0)
s.blit(h,(x,y))
for i in range(0,len(q)-1):
s.blit(b,q[i])
s.blit(a,(180,180))
pygame.display.update()
k.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