From b43fef2cd7dc43a82c9a747661af572e08584b25 Mon Sep 17 00:00:00 2001 From: Anshul Sood <33415007+AnshulSood11@users.noreply.github.com> Date: Tue, 14 Nov 2017 21:54:45 +0530 Subject: [PATCH] Update incomplete =patch.py Continuous mobility added, some minor changes made --- incomplete patch.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/incomplete patch.py b/incomplete patch.py index 9049ebd..0e09028 100644 --- a/incomplete patch.py +++ b/incomplete patch.py @@ -1,6 +1,6 @@ import pygame, random ,threading -size = width, height = 1000, 1000 +size = width, height = 1000, 800 pixel = 5 speed = [pixel,0] head = [500,400] @@ -12,7 +12,7 @@ BLUE = (0,0,255) YELLOW = (0,255,255) BLACK = (0,0,0) -fps=15 +fps=20 def direction(): if event.type == pygame.KEYDOWN : @@ -73,7 +73,7 @@ def move(): def wall(): - if head[0] + pixel >= 1000 or head[1] + pixel >= 800 or head[0] <= pixel*2 - 2 or head[1] + pixel <= pixel*2 - 2 : + if head[0] + 2*pixel >= 1000 or head[1] + 2*pixel >= 800 or head[0] <= 0 or head[1] <= 0 : return 0 else: return 1 @@ -96,14 +96,16 @@ def eat(): def new_food(): display() - food[0]=random.randint(0,1000-pixel) - food[1]=random.randint(0,800-pixel) + food[0]=random.randint(0+pixel,1000-pixel) + food[1]=random.randint(0+pixel,800-pixel) pygame.draw.circle(screen, YELLOW, (food[0], food[1]), pixel) pygame.display.update() pass screen = pygame.display.set_mode(size) clock = pygame.time.Clock() +timer_event = pygame.USEREVENT + 1 +pygame.time.set_timer(timer_event, 250) #Adds continuos mobility to the head pygame.init() display() new_food() @@ -115,3 +117,4 @@ def new_food(): direction() eat() +