gun in python turtle

Solutions on MaxInterview for gun in python turtle by the best coders in the world

showing results for - "gun in python turtle"
Lola
08 Mar 2016
1import turtle
2import os
3#wn is window
4#bp = border
5bullet = 'ready'
6#screen setup
7wn = turtle.Screen()
8wn.bgcolor('black')
9wn.title('SPACE.INVADERS')
10
11
12#border
13bp = turtle.Turtle()
14bp.speed(0)
15bp.color('green')
16bp.penup()
17bp.setposition(-300,-300)
18bp.pendown()
19count=0
20while count != 5:
21    count= (count+1)
22    bp.fd(600)
23    bp.lt(90)
24bp.hideturtle()
25
26#player
27p = turtle.Turtle()
28p.color('red')
29p.shape('triangle')
30p.penup()
31p.speed(0)
32p.setposition(0,-250)
33p.setheading(90)
34
35#enemy
36e = turtle.Turtle()
37e.penup()
38e.speed(0)
39e.shape('square')
40e.shapesize(1.25,1.25)
41e.color('orange')
42e.setpos(-250,250)
43e.speed(1)
44
45
46
47
48
49#p = player
50#ps = player speed
51
52ps = 15
53
54#moving left and right
55def left_mov():
56    x = p.xcor()
57    x -= ps
58    p.setx(x)
59
60def right_mov():
61    x = p.xcor()
62    x += ps
63    p.setx(x)
64#shooting
65def shoot():
66    global bullet
67    if bullet == 'ready':
68        bullet = 'fire'
69        shot= turtle.Turtle()
70        shot.penup()
71        shot.speed(0)
72        shot.goto(p.pos())
73        shot.color('white')
74        shot.shape('triangle')
75        shot.shapesize(0.5)
76        shot.lt(90)
77        shot.speed(1)
78        shot.fd(550)
79        bullet = 'ready'
80
81
82
83
84#bindings
85turtle.listen()
86turtle.onkey(left_mov, 'Left')
87turtle.onkey(right_mov, 'Right')
88turtle.onkey(shoot, 'space')
89#enemy movement
90while True:
91    e.fd(500)
92    e.rt(90)
93    e.fd(25)
94    e.rt(90)
95    e.fd(500)
96    e.lt(90)
97    e.fd(25)
98    e.lt(90)
99
queries leading to this page
gun in python turtlegun in python turtle