teromakotero icon

Python_from_Scratch_07_ratkaisu

teromakotero | PRO | 05/13/19 03:09:52 PM UTC | 0 ⭐ | 371 👁️ | Never ⏰ | []
Python |

1.01 KB

|

None

|

0 👍

/

0 👎

import turtle
import background
import time
import random
 
pycat = turtle.Turtle()
pycat.hideturtle()
screen = turtle.Screen()
image = ()
image = ["pycat_small_left.png","pycat_2_left_small.png","Angelo-Gemmi-stone_100_px_left.png"]
screen.addshape(image[0])
pycat.shape(image[0])
pycat.penup()
pycat.goto(-150,0)
pycat.showturtle()
pycat_2 = turtle.Turtle()
pycat_2.hideturtle()
 
stone = turtle.Turtle()
stone.hideturtle()
screen.addshape(image[2])
stone.shape(image[2])
stone.penup()
stone.goto(random.randrange(10,150,20),0)
stone.showturtle()
 
screen.addshape(image[1])
pycat_2.shape(image[1])
pycat_2.penup()
pycat_2.goto(-140,0)
pycat_2.hideturtle()
 
# KIRJOITA TÄMÄN RIVIN ALAPUOLELLE OMA KOODISI
kivi_x = stone.xcor()
while True:
  if(pycat.xcor() == kivi_x - 80):
    pycat.write("Kivi!")
    break
  pycat_2.showturtle()
  pycat.hideturtle()
  pycat.forward(20)
  time.sleep(0.5)
  pycat.showturtle()
  pycat_2.hideturtle()
  pycat_2.forward(20)
  time.sleep(0.5)

Comments