diff --git a/BlankProjectTemplate/src/Gameplay.py b/BlankProjectTemplate/src/Gameplay.py index e4a5af2ae35429d870e05a45989d599a1619525d..a86212dbb115eb2b5b46ec606931f014d64ececf 100644 --- a/BlankProjectTemplate/src/Gameplay.py +++ b/BlankProjectTemplate/src/Gameplay.py @@ -16,9 +16,9 @@ vel = 10 global a a = 0 -#defining a list to keep track of snake's head -snake_loc = [] +#defining a list to update snanke's length +snake_loc = [] #variable to increment snake's length, initially it would be 1 snake_length = 1 @@ -96,7 +96,9 @@ while run: if(abs(x - food_location[0]) < 15 and abs(y - food_location[1]) < 15): score += 10 print(score) - snake_length += 5 + + #increment the length by 3 unit every time + snake_length += 3 @@ -105,27 +107,34 @@ while run: #consumption of food block food.redraw_food(x, y, food_location, screenSize) + + snake_top = [] + snake_top.append(x) + snake_top.append(y) + snake_loc.append(snake_top) - snake_head = [] - snake_head.append(x) - snake_head.append(y) - - snake_loc.append(snake_head) - + snake_blocks = len(snake_loc) #Draw food item food.draw_food(food_location) - if (len(snake_loc)) > snake_length: + if snake_blocks > snake_length: + #keep updating the new block del snake_loc[0] - + ''' + Logic for updating the length is taken from: + CodeWithHarry, CodeWithHarry. “Snakes Game: Length Increment Logic - Python Game Development Using Pygame In Hindi #17.†+ YouTube, YouTube, 2 Oct. 2018, + www.youtube.com/watch?v=mkGJb0W03DM&index=17&list=PLu0W_9lII9ailUQcxEPZrWgDoL36BtPYb. + ''' #food.update_score(x,y,food_location, score) #Draw snake snake.draw(snake_loc) - #update display pygame.display.update() +print(snake_head, '\n') +print(snake_loc) pygame.quit()