Python Forum
[PyGame] Snake not changing directions in Snake Game
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Snake not changing directions in Snake Game
#3
(Aug-10-2018, 05:55 PM)Windspar Wrote: first keydown well catch all keydown.
elif event.type == pygame.KEYDOWN: if event.key == pygame.K_RIGHT: snake.changeDirTo('RIGHT') elif event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: snake.changeDirTo('UP') elif event.type == pygame.KEYDOWN: if event.key == pygame.K_DOWN: snake.changeDirTo('DOWN') elif event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: snake.changeDirTo('LEFT')
should be
elif event.type == pygame.KEYDOWN: if event.key == pygame.K_RIGHT: snake.changeDirTo('RIGHT') elif event.key == pygame.K_UP: snake.changeDirTo('UP') elif event.key == pygame.K_DOWN: snake.changeDirTo('DOWN') elif event.key == pygame.K_LEFT: snake.changeDirTo('LEFT')
Good catch. That fixed the problem I was having, however now when the snake eats the food, the food keeps changing locations rapidly.
Reply


Messages In This Thread
RE: Snake not changing directions in Snake Game - by Bjdamaster - Aug-11-2018, 05:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how to add segments to the snake body blacklight 1 2,972 Sep-13-2023, 07:33 AM
Last Post: angelabarrios
  [PyGame] Snake game: how to get an instance for my snake's body multiple times? hajebazil 2 2,225 Jan-30-2022, 04:58 AM
Last Post: hajebazil
  Rocket will only move in two directions djwilson0495 7 3,894 Dec-14-2020, 05:43 PM
Last Post: djwilson0495
  help with snake game blacklight 3 2,671 Jul-30-2020, 01:13 AM
Last Post: nilamo
  Snake Game - obstacle problem Samira 3 5,764 Oct-31-2019, 02:58 PM
Last Post: Samira
  [PyGame] Made my first Python program: Snake. Please help me improve it andrerocha1998 7 6,324 Feb-19-2019, 07:08 PM
Last Post: Windspar
  Creating Snake game in Turtle Shadower 1 8,703 Feb-11-2019, 07:00 PM
Last Post: woooee
  [PyGame] Basic Snake game (using OOP) PyAlex 1 12,653 Sep-10-2018, 09:02 PM
Last Post: Mekire
  [PyGame] Snake controls not working jakegold98 5 6,561 Dec-12-2017, 01:45 AM
Last Post: Windspar

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020