Python - Alterando as imagens

De Aulas

Afluentes: Programação em Python; DAS5334 Introdução a Informática para Automação

Recursos

Código

from turtle import *
from random import *

up = "car_up.gif"
right = "car_right.gif"
down = "car_down.gif"
left = "car_left.gif"

screen = Screen()
screen.addshape(up)
screen.addshape(right)
screen.addshape(down)
screen.addshape(left)

speed(1)
SPEED = 100
while (True):
    direction = randint(0, 3)
    x, y = pos()
    if direction == 0:
        shape(up)
        sety(y + SPEED)
    elif direction == 1:
        shape(right)
        setx(x + SPEED)
    elif direction == 2:
        shape(down)
        sety(y - SPEED)
    elif direction == 3:
        shape(left)
        setx(x - SPEED)