Python Forum
PROJECTILE WITH TURTLE - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: PROJECTILE WITH TURTLE (/thread-31648.html)



PROJECTILE WITH TURTLE - artnote1337 - Dec-25-2020

Hello. The idea here was to shot a projectile til the end of the screen. What actually happens is that the function is just printing it at the end of the screen and there is no movement upwards after shooting.
I am a beginner and might be doing something really wrong here. The 'personagem' object can move across the screen.

def shoot():
    projectile = turtle.Turtle()
    projectile.speed(0)
    projectile.shape('square')
    projectile.color('white')
    projectile.shapesize(stretch_wid=0.25, stretch_len=0.25)
    projectile.penup()
    projectile.goto(personagem.xcor(),personagem.ycor())
    while projectile.ycor() <= 290:
        projectile.dy = 0.2
        projectile.sety(projectile.ycor() + projectile.dy)
    projectile.clear()
screen.onkeypress(shoot,'p')



RE: PROJECTILE WITH TURTLE - ibreeden - Dec-26-2020

I am not acquainted with Turtle, but perhaps it helps to add a time.sleep(0.5) to the while loop.


RE: PROJECTILE WITH TURTLE - MK_CodingSpace - Dec-26-2020

Some comments here.
1. This part needs to be out of the shoot() function.
    projectile = turtle.Turtle()
    projectile.speed(0)
    projectile.shape('square')
    projectile.color('white')
    projectile.shapesize(stretch_wid=0.25, stretch_len=0.25)
    projectile.penup()
2. projectile.dy = 0.2 needs to be out of while loop
3. what does "projectile.clear()" do here? Probably should remove this line.
4. What is the window color? The default color is white. You set the color of projectile white. Is that the reason that you cannot see the projectile?
5. Needs border checking for personagem.