diff --git a/BlankProjectTemplate/src/Snake_2.o_Demo.py b/BlankProjectTemplate/src/Snake_2.o_Demo.py index 78cbcd14e3dbc3c00659e1774c4587a466610537..2db388bbdcfe5706c95aaf0c6532f3a2a72b0c46 100644 --- a/BlankProjectTemplate/src/Snake_2.o_Demo.py +++ b/BlankProjectTemplate/src/Snake_2.o_Demo.py @@ -1,16 +1,16 @@ -## Author: Usman Irfan, Andy Hameed -# This module will be used to control snake body movements and gameplay +## @file Snake_2.o.py +# @author Andy Hameed, Usman Irfan +# @brief implements gameplay and connects the different components of the game +# @date 11/09/2018 import pygame from random import randint +#initializing PyGame and setting game window dimensions pygame.init() - -#setting width and size of window to screenSize screenSize = 500 win = pygame.display.set_mode((screenSize,screenSize)) - -pygame.display.set_caption("My Game") +pygame.display.set_caption("Snake 2.o") #Define color constants white = (255,255,255) @@ -18,27 +18,26 @@ red = (255,0,0) blue = (0,0,255) black = (0,0,0) -#width1, size1 correspond to constant width and size for the food block -#width and size change over time as the snake consumes food - -width, width1 = 20,20 # can replace with size - one number -size, size1 = 20,20 -size = 20 # One size for all block created for snake +# One size for all blocks created for snake +size = 20 +#velocity and score vel = 10 score = 0 -x = randint(0,screenSize - size) -y = randint(0, screenSize - size) + +#initial x and y coordinates of the snake +x_init = randint(0,screenSize - size) +y_init = randint(0, screenSize - size) speed = 40 + # 0 gives (- direction) # 1 gives (+ direction) direction = 0 # 0 - x-axis , 1 - y-axis axis = 0 - location = [] food_x = randint(0,screenSize - size) @@ -96,8 +95,8 @@ while run: #consumption of food block if( abs(x - food_x) < 15 and abs(y - food_y) < 15): score += 1 - food_x = randint(0,screenSize - size1) - food_y = randint(0,screenSize - size1) + food_x = randint(0,screenSize - size) + food_y = randint(0,screenSize - size) location = [food_x, food_y] ## --------------------------DELETE -------------------------- @@ -106,15 +105,16 @@ while run: size += 20 else: size += 20 - - print('score = ', score) ##---------------------------DELETE---------------------------- + + print('score = ', score) + win.fill(white) #Draw food item - pygame.draw.rect(win,blue, (location[0], location[1], size1, size1)) + pygame.draw.rect(win,blue, (location[0], location[1], size, size)) #Draw snake pygame.draw.rect(win, red , (x,y,size, size))