#๐Ÿ”’ Handling rotations and movements in snake project

16 messages ยท Page 1 of 1 (latest)

frail epoch
#

Hi everyone, i'm new to python and programming in general, so i'm trying to do a basic snake game with pygame, but i can't handle correctly a few things :

  • first of all, making the parts (body and tail) of my snake folllow the head,
  • and making the sprites of my snake rotate parts by parts when the player takes a turn.
    (i don't know what's wrong exactly so i'll send a screenshot of the part of my code where i program binds and movement)
shell forgeBOT
#

@frail epoch

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

frail epoch
#

By the way it's my first time sending a message here, so apologies if this is a bit unprecise. Let me know if you need more informations !

frail epoch
proven plover
proven plover
frail epoch
#

i wrote this but i think it doesn't work as intended

player_img = pygame.image.load("Python/#3 snake/head_up.png")
player_img = pygame.transform.scale(player_img, (32, 32))
player_x = screen_width // 2 - player_img.get_width() // 2
player_y = screen_height // 2 - player_img.get_height() // 2

# Initialisation corps du serpent et redimensionnement
body_img = pygame.image.load("Python/#3 snake/body_vertical.png")
body_img = pygame.transform.scale(body_img, (32, 32))
body_x = player_x + player_img
body_y = player_y + body_img.get_height()

# initialisation de la queue du serpent
tail_img = pygame.image.load("Python/#3 snake/tail_down.png")
tail_img = pygame.transform.scale(tail_img, (32, 32))
tail_x = body_x
tail_y = body_y + tail_img.get_height()```
#

it just positions the snake correctly when the game is booting but honestly i'm completely lost when it comes to how to make the parts follow each other when a key is pressed

proven plover
frail epoch
proven plover
frail epoch
#

i'll leave this post open and hit you up if i'm still stuck somewhere.

shell forgeBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.