Mám problém s pohybem čtverce, který pronásleduje kuličku.
Vždy mi to vyhodí tuto chybovou hlášku:
File "C:\Python27\lib\site-packages\livewires\beginners.py", line 902, in move_to
ox,oy = object.coords()[:2]
AttributeError: 'tuple' object has no attribute 'coords'
Tady je ten prográmek:
from livewires import*
import random
import time
begin_graphics(width = 800, height = 600)
allow_moveables()
def vyrobHrace():
global kruh, hx, hy
hx = random.randint(50, 620)
hy = random.randint(50, 480)
kruh = circle(hx, hy, 6.5, filled = 1)
def posunHrace():
global kruh, hx, hy
klavesy = keys_pressed()
if "a" in klavesy and hx > 7:
hx = hx - 0.1
if "d" in klavesy and hx < 800:
hx = hx + 0.1
if "s" in klavesy and hy > 6.5:
hy = hy - 0.1
if "w" in klavesy and hy < 600:
hy = hy + 0.1
move_to(kruh, hx, hy)
def vyrobRobota():
global rx, ry, robot
rx = random.randint(50, 620)
ry = random.randint(50, 480)
robot = (rx, ry, rx + 25, ry + 25)
def posunRobota():
global rx, ry, robot, hx, hy
if rx > hx:
rx = rx - 0.1
if rx < hx:
rx = rx + 0.1
if ry > hy:
ry = ry - 0.1
if ry < hy:
ry = ry + 0.1
move_to(robot, rx, ry, rx + 25, ry + 25)
vyrobHrace()
vyrobRobota()
while 1:
posunHrace()
posunRobota()
end_graphics()