diff --git a/BlankProjectTemplate/POC_Demo/Snake_2.o_Demo.py b/BlankProjectTemplate/POC_Demo/Snake_2.o_Demo.py index 28bf90dffa7302564ecc0ba3ebb037c5f72e6a99..7cfe05a49c27332f94b6492097b04370caeb33f5 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))