connectionsterew.blogg.se

In screen snake game
In screen snake game












(game_window, green, pygame. draw.rect(play_surface, color, xy-coordinate) If snake_pos = food_pos and snake_pos = food_pos: If change_to = 'RIGHT' and direction != 'LEFT': If change_to = 'LEFT' and direction != 'RIGHT': If change_to = 'DOWN' and direction != 'UP': If change_to = 'UP' and direction != 'DOWN': # Making sure the snake cannot move in the opposite direction instantaneously If event.key = pygame.K_RIGHT or event.key = ord('d'): If event.key = pygame.K_LEFT or event.key = ord('a'): If event.key = pygame.K_DOWN or event.key = ord('s'): The player’s main aim in the game is to achieve maximum points as possible by collecting the food. If event.key = pygame.K_UP or event.key = ord('w'): The snake in the snake game is controlled using four directions, and if the snakehead hits the wall or hits itself, then the snake dies, and the game will be ended with the score. Game_window.blit(score_surface, score_rect) Score_rect.midtop = (frame_size_x / 2, frame_size_y / 1.25) Score_rect.midtop = (frame_size_x - 100, 15) Score_surface = score_font.render('Score : ' + str(score), True, color) Game_window.blit(game_over_surface, game_over_rect)ĭef show_score(choice, color, font, size): Game_over_rect.midtop = (frame_size_x / 2, frame_size_y / 4) Game_over_rect = game_over_surface.get_rect() Game_over_surface = my_font.render('YOU DIED', True, red) Game_window = _mode((frame_size_x, frame_size_y)) Print(f' Had errors when initialising game, exiting.') # second number in tuple gives number of errors

In screen snake game how to#

The problem isn't how to make the game restart when you press space but to actually make it restart. In the game that I have found on github there is a game over screen that shows your score, now I want to make the game restart if you press space so that you don't need to close the program and open it again to play it again.












In screen snake game