From 86ea31935d6b099ddb03559ad9b1c69c039519af Mon Sep 17 00:00:00 2001 From: Usman Irfan <usmanirfan@USERs-MacBook-Pro.local> Date: Mon, 15 Oct 2018 09:23:14 -0400 Subject: [PATCH] Updated Boubdary --- .../POC_Demo/Snake_2.o_Demo.py | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/BlankProjectTemplate/POC_Demo/Snake_2.o_Demo.py b/BlankProjectTemplate/POC_Demo/Snake_2.o_Demo.py index 28bf90d..7cfe05a 100644 --- a/BlankProjectTemplate/POC_Demo/Snake_2.o_Demo.py +++ b/BlankProjectTemplate/POC_Demo/Snake_2.o_Demo.py @@ -1,19 +1,23 @@ #standard set up import pygame +from random import randint pygame.init() #setting width and height of window -win = pygame.display.set_mode((500,500)) + +screen_x = 500 +screen_y = 500 +win = pygame.display.set_mode((screen_x,screen_y)) pygame.display.set_caption("My Game") white = (255,255,255) black = (0,0,0) -x = 50 -y = 50 -width = 40 -height = 40 +x = randint(40,400) +y = randint(40,400) +width = 20 +height = 20 vel = 10 speed = 40 @@ -59,6 +63,21 @@ while run: x += vel*direction + if x < 0: + #x = 0 + x = screen_x - height + + if y < 0: + #y = 0 + y = screen_y - width + + if y > screen_y - width: + #y = 500 - width + y = 0 + if x > screen_x - height: + #x = 500 - height + x = 0 + win.fill(white) #all colors are defined in RGB with Pygame pygame.draw.rect(win,(255,0,0), (x,y,width, height)) -- GitLab