Turn the space ship using left and right arrows.
Move forwards with the up arrows.
Made in tynker.com, the Python 1 course, not cross-platform compatible but source code is below
import turtle, random screen = turtle.Screen() screen.register_shape("ship", ((-10, -10), (0, -5), (10, -10), (0, 10))) screen.bgcolor('black') for i in range(10): screen.register_shape("rock" + str(i), ((random.randint(-20, 20), random.randint(-20, 20)), (random.randint(-20, 20), random.randint(-20, 20)), (random.randint(-20, 20), random.randint(-20, 20)), (random.randint(-20, 20), random.randint(-20, 20)), (random.randint(-20, 20), random.randint(-20, 20)), (random.randint(-20, 20), random.randint(-20, 20)))) '''screen.register_shape("rock1", ((random.randint(-20, 20), random.randint(-20, 20)), (random.randint(-20, 20), random.randint(-20, 20)), (random.randint(-20, 20), random.randint(-20, 20)), (random.randint(-20, 20), random.randint(-20, 20)), (random.randint(-20, 20), random.randint(-20, 20)), (random.randint(-20, 20), random.randint(-20, 20)))) screen.register_shape("rock2", ((random.randint(-20, 20), random.randint(-20, 20)), (random.randint(-20, 20), random.randint(-20, 20)), (random.randint(-20, 20), random.randint(-20, 20)), (random.randint(-20, 20), random.randint(-20, 20)), (random.randint(-20, 20), random.randint(-20, 20)), (random.randint(-20, 20), random.randint(-20, 20)))) screen.register_shape("rock3", ((random.randint(-20, 20), random.randint(-20, 20)), (random.randint(-20, 20), random.randint(-20, 20)), (random.randint(-20, 20), random.randint(-20, 20)), (random.randint(-20, 20), random.randint(-20, 20)), (random.randint(-20, 20), random.randint(-20, 20)), (random.randint(-20, 20), random.randint(-20, 20))))''' ship = turtle.Turtle() ship.shape("ship") ship.penup() ship.speed(0) ship.color("green") asteroids = [] for i in range(10): a = turtle.Turtle() a.penup() a.speed(0) a.shape('rock' + str(i)) a.color(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) a.goto(random.randint(-200, 200), random.randint(-200, 200)) asteroids.append(a) #make each asteroid its own shape and color def right(): ship.right(10) def left(): ship.left(10) def forward(): ship.forward(5) x = ship.position() q = 0 for i in range(10): if abs(int(x[0]) - int(asteroids[i].position()[0])) <= 20: if abs(int(x[1]) - int(asteroids[i].position()[1])) <= 20: q += 1 if q > 0: ship.ht() else: ship.st() def bullet(): bullet = turtle.Turtle() bullet.color("white") x = ship.position() bullet.penup() bullet.speed(0) bullet.goto(x[0], x[1]) bullet.color(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) bullet.left(ship.heading() - 5) for p in range(400): bullet.forward(1) q = 0 x = bullet.position() for i in range(len(asteroids)): if abs(int(x[0]) - int(asteroids[i].position()[0])) <= 20: if abs(int(x[1]) - int(asteroids[i].position()[1])) <= 20: q += 1 if q > 0: asteroids[i].ht() bullet.ht() del asteroids[i] q = 0 screen.onkey(right, "Right") screen.onkey(left, "Left") screen.onkey(forward, "Up") screen.onkey(bullet, "Space") screen.listen()