diff --git a/BlankProjectTemplate/src/Food.py b/BlankProjectTemplate/src/Food.py index 083d18e30ca25dde70690f82cebf8a7460acef0d..4256507ae1e53b03cd7734ac8fd0794200b20f33 100644 --- a/BlankProjectTemplate/src/Food.py +++ b/BlankProjectTemplate/src/Food.py @@ -28,5 +28,5 @@ class Food(): # @param screenSize is the size of the screen def redraw_food(self, x, y, location,screenSize): if(abs(x - location[0]) < 15 and abs(y - location[1]) < 15): - location[0] = randint(0, screenSize - self.size) - location[1] = randint(0, screenSize - self.size) + location[0] = randint(0, grid_length - 1) * self.size + location[1] = randint(0, grid_length - 1) * self.size diff --git a/BlankProjectTemplate/src/Gameplay.py b/BlankProjectTemplate/src/Gameplay.py index e4a5af2ae35429d870e05a45989d599a1619525d..2e87d3b28c74fbe227d7f26ae5d5c033d68e88ee 100644 --- a/BlankProjectTemplate/src/Gameplay.py +++ b/BlankProjectTemplate/src/Gameplay.py @@ -3,16 +3,13 @@ # @brief implements gameplay and connects the different components of the game # @date 11/09/2018 - from random import randint from Snake import * from Food import * -# One size for all blocks created for snake -size = 20 -#velocity and score -vel = 10 + + global a a = 0 @@ -22,12 +19,7 @@ snake_loc = [] #variable to increment snake's length, initially it would be 1 snake_length = 1 -#initial x and y coordinates of the snake -x = randint(0,screenSize - size) -y = randint(0, screenSize - size) - - -speed = 40 +speed = 30 # 0 gives (- direction) # 1 gives (+ direction) @@ -39,12 +31,15 @@ score = 0 # parameters for initializing food on the screen food_location = [] -food_x = randint(0,screenSize - size) -food_y = randint(0,screenSize - size) +food_x = randint(0, grid_length - 1) * size +food_y = randint(0, grid_length - 1) * size food_location = [food_x, food_y] -##initialize snake +##initialize snake and draw snake body somewhere on the screen +print(x/size, y/size) + snake = Snake(size, 0, 20, 0) +pygame.draw.rect(win, red , [x,y, size, size]) food = Food(size) @@ -73,12 +68,13 @@ while run: #Snake moving depending on axis and direction if (snake.axis): - y += vel*snake.direct + y += (size)*snake.direct else: - x += vel*snake.direct + x += (size)*snake.direct - - + print("x: ",x,"y: ",y) + print("food x: ",food_location[0],"food y: ",food_location[1]) + #Boundary conditions for snake hitting window edge if x < 0: #x = 0 diff --git a/BlankProjectTemplate/src/init.py b/BlankProjectTemplate/src/init.py index 4caab43251293c0cdb716e3a849049ea2536acbc..88ba0d68750492cdb68776a28837810e691e5e17 100644 --- a/BlankProjectTemplate/src/init.py +++ b/BlankProjectTemplate/src/init.py @@ -4,6 +4,7 @@ # @date 11/09/2018 import pygame +from random import randint #initializing PyGame and setting game window dimensions pygame.init() @@ -16,3 +17,11 @@ white = (255,255,255) red = (255,0,0) blue = (0,0,255) black = (0,0,0) + +# One size for all blocks created for snake +size = 20 +grid_length = screenSize/size + +#make initial position sit within the grid +x = randint(0, grid_length) * size +y = randint(0, grid_length) * size