gun in python turtle

import turtle
import os
#wn is window
#bp = border
bullet = 'ready'
#screen setup
wn = turtle.Screen()
wn.bgcolor('black')
wn.title('SPACE.INVADERS')


#border
bp = turtle.Turtle()
bp.speed(0)
bp.color('green')
bp.penup()
bp.setposition(-300,-300)
bp.pendown()
count=0
while count != 5:
    count= (count+1)
    bp.fd(600)
    bp.lt(90)
bp.hideturtle()

#player
p = turtle.Turtle()
p.color('red')
p.shape('triangle')
p.penup()
p.speed(0)
p.setposition(0,-250)
p.setheading(90)

#enemy
e = turtle.Turtle()
e.penup()
e.speed(0)
e.shape('square')
e.shapesize(1.25,1.25)
e.color('orange')
e.setpos(-250,250)
e.speed(1)





#p = player
#ps = player speed

ps = 15

#moving left and right
def left_mov():
    x = p.xcor()
    x -= ps
    p.setx(x)

def right_mov():
    x = p.xcor()
    x += ps
    p.setx(x)
#shooting
def shoot():
    global bullet
    if bullet == 'ready':
        bullet = 'fire'
        shot= turtle.Turtle()
        shot.penup()
        shot.speed(0)
        shot.goto(p.pos())
        shot.color('white')
        shot.shape('triangle')
        shot.shapesize(0.5)
        shot.lt(90)
        shot.speed(1)
        shot.fd(550)
        bullet = 'ready'




#bindings
turtle.listen()
turtle.onkey(left_mov, 'Left')
turtle.onkey(right_mov, 'Right')
turtle.onkey(shoot, 'space')
#enemy movement
while True:
    e.fd(500)
    e.rt(90)
    e.fd(25)
    e.rt(90)
    e.fd(500)
    e.lt(90)
    e.fd(25)
    e.lt(90)

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source