snakeq/snake/snake.py
2022-10-31 21:04:13 +01:00

32 lines
No EOL
913 B
Python
Executable file

#!/usr/bin/env python
import sys, pygame
class Snake:
def __init__(self, grid_width=50,grid_height=50, grid_pts=15):
self.grid_width=grid_width
self.grid_height=grid_height
self.grid_pts=grid_pts
pygame.init()
self.screen=pygame.display.set_mode((grid_width*grid_pts,grid_height*grid_pts))
def draw_pts(self,x,y,color=(255,255,255)):
rect=pygame.Rect(self.grid_pts*x, self.grid_pts*y, self.grid_pts, self.grid_pts)
pygame.draw.rect(self.screen,color,rect, 0)
def run(self):
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
self.screen.fill((0,0,0))
self.draw_pts(1,1)
self.draw_pts(0,0,color=(95,1,255))
pygame.display.flip()
game=Snake()
game.run()