Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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)
Comment

PREVIOUS NEXT
Code Example
Python :: python min date from dictionary 
Python :: how to update sheety 
Python :: how to make download link in Jupyter appmode 
Python :: fibonacci numbers in lamda python 
Python :: voilion plot 
Python :: ROC plot for h2o package 
Python :: default python structure 
Python :: opencv houghlines only horizontal 
Python :: login system read data python 
Python :: sklearn isolationforest 
Python :: text replace 
Python :: python send email with attachment 
Python :: fomat json load python 
Python :: how to read json file from s3 bucket into aws glue job 
Python :: rename column in dataframe 
Python :: sqlalchemy date beween 
Python :: snap pdf 
Python :: Select a Column in pandas data Frame Using dot notation 
Python :: Python print traceback when error occurs in a class 
Python :: not all arguments converted during string formatting postgresql 
Python :: writer.append_data(image) means 
Python :: Take input of any number and generate all possible binary strings without recursion 
Python :: adding multiple items to a list python 
Python :: Python Tkinter Menu Widget Syntax 
Python :: Convert PySpark RDD to DataFrame 
Python :: how to code fibonacci series in python 
Python :: flask-sqlalchemy inheritance 
Python :: how to set notepad ++ for run python 
Python :: is tkinter built into python 
Python :: pylance not reading django 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =