#🔒 MINI GAME PYTHON TURTLE

33 messages · Page 1 of 1 (latest)

glacial kite
#

Hello, I have a problem with my maze game project where the little triangle moves, but the graphical interface is not there.

the triangle moves correctly with the keyboard keys, but the maze is not visible.

and when I remove the turtle.done() there's the triangle on the maze but I can't move it

THE CODE :

import turtle
import random

Taille de la grille

GRID_SIZE = 15

Taille d'une cellule

CELL_SIZE = 20

player = turtle.Turtle()
player.color("blue")
player.shape("triangle")
player.pendown()
player.speed(0)

Fonctions pour déplacer le triangle

def move_left():
player.setheading(180) # Définir la direction vers la gauche
player.forward(10)

def move_right():
player.setheading(0) # Définir la direction vers la droite
player.forward(10)

def move_up():
player.setheading(90) # Définir la direction vers le haut
player.forward(10)

def move_down():
player.setheading(270) # Définir la direction vers le bas
player.forward(10)

Associer les touches du clavier aux fonctions de déplacement

turtle.listen()
turtle.onkeypress(move_left, "Left")
turtle.onkeypress(move_right, "Right")
turtle.onkeypress(move_up, "Up")
turtle.onkeypress(move_down, "Down")

Fermer la fenêtre Turtle

turtle.done()

ivory ospreyBOT
#

@glacial kite

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.

spiral holly
#

Our bot zaps file attachments, you can use the pastebin to share:

#

!paste

ivory ospreyBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

glacial kite
#

@spiral holly

spiral holly
#

Looks like your turtle movement is not inside your main function

glacial kite
#

what should i do?

spiral holly
#

I would try maybe moving lines 33-40 to be after the draw_maze() line in the main function

glacial kite
#

always this

spiral holly
#

Hmm

#

I made the change and it shows everything, but doesn't handle the movement

glacial kite
#

def main():
turtle.clear() # Efface l'écran avant de dessiner le nouveau labyrinthe
maze = generate_maze(GRID_SIZE, GRID_SIZE)
draw_maze(maze)
# Associer les touches du clavier aux fonctions de déplacement
turtle.listen()
turtle.onkeypress(move_left, "Left")
turtle.onkeypress(move_right, "Right")
turtle.onkeypress(move_up, "Up")
turtle.onkeypress(move_down, "Down")

Fermer la fenêtre Turtle

turtle.done()

ivory ospreyBOT
#

Hey @glacial kite!

It looks like you're trying to paste code into this channel.

Discord has support for Markdown, which allows you to post code with full syntax highlighting. Please use these whenever you paste code, as this helps improve the legibility and makes it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
spiral holly
glacial kite
#

I don't know

spiral holly
#
def main():
    turtle.clear()  # Efface l'écran avant de dessiner le nouveau labyrinthe
    maze = generate_maze(GRID_SIZE, GRID_SIZE)
    draw_maze(maze)
    # Associer les touches du clavier aux fonctions de déplacement
    turtle.listen()
    turtle.onkeypress(move_left, "Left")
    turtle.onkeypress(move_right, "Right")
    turtle.onkeypress(move_up, "Up")
    turtle.onkeypress(move_down, "Down")

    # Fermer la fenêtre Turtle
    turtle.done()
#

But it isn't handling the movement

glacial kite
#

how do i introduce it?

spiral holly
#

I'm not sure either, I don't work with turtle very much

glacial kite
#

I can't find a solution

glacial kite
#

and how to separate the code for a graphic part, movements etc.

#

@spiral holly

spiral holly
#

To be honest I am not sure how this should be handled for turtle

#

You might want to check out a more robust library for making a movement based game like arcade or pygame

glacial kite
#

my teacher wants turtle

ivory ospreyBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, 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.