I am making a simple Object-oriented projectile simulation program in python. I am just using the Turtle and Math modules. The problem is when I try to simply move my projectile (as a test before integrating some equations) it does not move.
import turtle
from turtle import Turtle
import math
window = turtle.Screen()
window.title("Projectile")
window.bgcolor("black")
window.setup(width=800, height=800)
window.tracer(0)
def drawLine():
line = turtle.Turtle()
line.penup()
line.pencolor("white")
line.pensize(10)
line.goto(-400, -300)
line.pendown()
line.forward(800)
line.penup()
line.ht()
class Projectile:
def __init__(self, x, y, color, shape, a, b):
self.turtle = turtle.Turtle()
self.turtle.goto(x, y)
self.turtle.color(color)
self.turtle.shape(shape)
self.turtle.shapesize(a, b)
def launch(self, x, y):
self.turtle.penup()
self.turtle.setx(self.turtle.xcor() + x)
self.turtle.sety(self.turtle.ycor() + y)
running = True
while running:
window.update()
drawLine()
projectileOne = Projectile(-290, -290, "red", "circle", 1, 1)
projectileOne.launch(25, 25)
This is supposed to move my turtle, isn't it?
self.turtle.setx(self.turtle.xcor() + x)
self.turtle.sety(self.turtle.ycor() + y)
I don't understand what's happening. Why isn't the projectile moving? It just moves (25, 25) and stops.
The errors I get after the code runs:
Traceback (most recent call last):
File "C:\Users\HP\Desktop\Python projects\test\test.py", line 39, in <module>
drawLine()
File "C:\Users\HP\Desktop\Python projects\test\test.py", line 12, in drawLine
line = turtle.Turtle()
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\turtle.py", line 3813, in __init__
RawTurtle.__init__(self, Turtle._screen,
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\turtle.py", line 2557, in __init__
self._update()
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\turtle.py", line 2660, in _update
self._update_data()
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\turtle.py", line 2646, in _update_data
self.screen._incrementudc()
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\turtle.py", line 1292, in _incrementudc
raise Terminator
turtle.Terminator
[Finished in 7.4s]
And if I completely remove drawLine()
from the code I get:
Traceback (most recent call last):
File "C:\Users\HP\Desktop\Python projects\test\test.py", line 40, in <module>
projectileOne = Projectile(-290, -290, "red", "circle", 1, 1)
File "C:\Users\HP\Desktop\Python projects\test\test.py", line 24, in __init__
self.turtle = turtle.Turtle()
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\turtle.py", line 3813, in __init__
RawTurtle.__init__(self, Turtle._screen,
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\turtle.py", line 2557, in __init__
self._update()
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\turtle.py", line 2660, in _update
self._update_data()
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\turtle.py", line 2646, in _update_data
self.screen._incrementudc()
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\turtle.py", line 1292, in _incrementudc
raise Terminator
turtle.Terminator
[Finished in 5.2s]