"q" is to move so when you press "q" you move in the direction of your mouse and when you press "q" again you stop. When you click your mouse the ship will shoot a bullet but it will pause for a second. Is there a way to make it not pause. Also can you make the triangle a rocket picture? Or the background picture a space.
The code:
from turtle import Screen, Turtle, Vec2D, Turtle
import turtle
import time
screen = turtle.Screen()
screen.title("Test")
screen.setup(width=1000, height=650)
ship = turtle.Turtle()
ship.shape("triangle")
ship.turtlesize(3)
ship.speed('fast')
ship.penup()
bullet = turtle.Turtle()
bullet.shape("circle")
bullet.speed('fast')
bullet.color("green")
bullet.penup()
bullet.hideturtle()
bullet.goto(-525, -350)
bullet.hideturtle()
bullet.turtlesize(0.5)
shot=0
coin=-1
def onmove(self, fun, add=None):
if fun is None:
self.cv.unbind('<Motion>')
else:
def eventfun(event):
fun(Vec2D(self.cv.canvasx(event.x) / self.xscale, -self.cv.canvasy(event.y) / self.yscale))
self.cv.bind('<Motion>', eventfun, add)
def goto_handler(position):
global target
onmove(screen, None)
target = position
onmove(screen, goto_handler)
def move():
global shot
if -350<bullet.ycor() and bullet.ycor()<350 and -525<bullet.xcor() and bullet.xcor()<525:
bullet.forward(15)
ship.setheading(ship.towards(target))
if coin==1:
ship.forward(5)
if shot==1:
bullet.hideturtle()
bullet.goto(ship.xcor(), ship.ycor())
bullet.setheading(ship.heading())
bullet.forward(15)
bullet.showturtle()
shot=0
if -275>ship.ycor() or ship.ycor()>275 or -450>ship.xcor() or ship.xcor()>450:
ship.backward(5)
screen.ontimer(move, 50)
def shoot(x, y):
global shot
if not(-350<bullet.ycor() and bullet.ycor()<350 and -525<bullet.xcor() and bullet.xcor()<525):
shot=1
def forward():
global coin
coin=-coin
target = (0, 0)
onmove(screen, goto_handler)
move()
screen.onscreenclick(shoot)
screen.onkeypress(forward, "q")
screen.listen()
screen.mainloop()