import class_ss
import random
import pygame
import sys
p = (5,0)
ps = pygame.Surface((10,10))
pygame.init()
root = pygame.display.set_mode((500,500))
im = pygame.image.load('1.png')
s1 = class_ss.snake()
sss = s1.show()
clock = pygame.time.Clock()
while 1:
pygame.display.update()
for event in pygame.event.get():
if event.type==pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key ==pygame.K_RIGHT:
#s1.eat()
s1.move(90)
im = pygame.transform.rotate(im, 90)
sss = s1.show()
if event.key ==pygame.K_DOWN:
s1.move(180)
im = pygame.transform.rotate(im, -90)
sss = s1.show()
if event.key ==pygame.K_LEFT:
#s1.eat()
s1.move(-90)
im = pygame.transform.rotate(im, -90)
sss = s1.show()
if event.key ==pygame.K_UP:
s1.move(0)
im = pygame.transform.rotate(im, 0)
sss = s1.show()
root.fill((0, 0, 0))
ps.fill('red')
root.blit(ps, (p[0] * 10, p[1] * 10))
for i in range(len(sss)):
pygame.draw.rect(root,(255,255,255),pygame.Rect(sss[i][0]*10,sss[i][1]*10,10,10))
root.blit(im, (sss[0][0] * 10, sss[0][1] * 10))
s1.move(s1.direction)
sss = s1.show()
clock.tick(10)
s1.panduan()
if sss[0]==p:
x=random.randint(0,50)
y=random.randint(0,50)
p=(x,y)
s1.eat()