import turtle
win = turtle.Screen()
win.title(“Tanks”)
win.bgcolor(“black”)
win.setup( width = 1000, height = 1000 )
win.tracer(0)
Tank A
tank_a = turtle.Turtle()
tank_a.speed()
tank_a.shape(“square”)
tank_a.color(“white”)
tank_a.shapesize(stretch_len = 2, stretch_wid = 2 )
tank_a.penup()
tank_a.goto(0, -400)
Tank 2
tank_b = turtle.Turtle()
tank_b.speed()
tank_b.shape(“square”)
tank_b.color(“white”)
tank_b.shapesize(stretch_len = 2, stretch_wid = 2 )
tank_b.penup()
tank_b.goto(0, 400)
#Function Tank A
def tank_a_up():
y = tank_a.ycor()
y += 20
tank_a.sety(y)
def tank_a_down():
y = tank_a.ycor()
y -= 20
tank_a.sety(y)
def tank_a_left():
x = tank_a.xcor()
x -= 20
tank_a.setx(x)
def tank_a_right():
x = tank_a.xcor()
x += 20
tank_a.setx(x)
Function Tank B
def tank_b_up():
y = tank_b.ycor()
y += 20
tank_b.sety(y)
def tank_b_down():
y = tank_b.ycor()
y -= 20
tank_b.sety(y)
def tank_b_left():
x = tank_b.xcor()
x -= 20
tank_b.setx(x)
def tank_b_right():
x = tank_b.xcor()
x += 20
tank_b.setx(x)
Key Binding Tank A
win.listen()
win.onkeypress(tank_a_up, “w”)
win.onkeypress(tank_a_down, “s”)
win.onkeypress(tank_a_left, “a”)
win.onkeypress(tank_a_right, “d”)
Key Binding Tank B
win.listen()
win.onkeypress(tank_b_up, “Up”)
win.onkeypress(tank_b_down, “Down”)
win.onkeypress(tank_b_left, “Left”)
win.onkeypress(tank_b_right, “Right”)
Main game loop
while True :
win.update()
This is the code.
I have to add a .png image to Tank A and Tank B.
I have tried so many things to add the GIF image but all the lines don’t work.
Sir Please tell me the lines which I have to delete and the lines which I have to add and one more thing sir that I am running this code in MacOS Terminal .