I found information about pygame, but i cant interpret this in tkinter.
icons - https://i.stack.imgur.com/ZcRvh.jpg
pastebin - https://pastebin.com/ykUzj9Pc
def key_pressed(event):
global e
if event.keysym == 'Up':
move_wrap(player, (0, -step))
if event.keysym == 'Down':
move_wrap(player, (0, step))
if event.keysym == 'Left':
move_wrap(player, (-step, 0))
if event.keysym == 'Right':
move_wrap(player, (step, 0))
check_move()
# for enemy in enemies:
# direction = enemy[1]() # вызвать функцию перемещения у "врага"
# move_wrap(enemy[0], direction) # произвести перемещение
# print(e)
for enemy in enemies:
direction = enemy[1]()
move_wrap(enemy[0], direction)
list_ = [(step, 0), (-step, 0), (0, step), (0, -step)]
predictions = []
for i in list_:
predictions.append([canvas.coords(enemy[0])[0] + i[0], canvas.coords(enemy[0])[1] + i[1]])
for i in predictions:
if i[0] - canvas.coords(player)[0] > i[1] - canvas.coords(player)[1]:
if predictions.index(i) == 1:
move_wrap(enemy[0], (step, 0))
elif predictions.index(i) == 2:
move_wrap(enemy[0], (-step, 0))
elif predictions.index(i) == 3:
move_wrap(enemy[0], (0, step))
elif predictions.index(i) == 4:
move_wrap(enemy[0], (0, -step))
predictions.clear()
I have a list with enemies. In this list i have tuple with (enemy, random_move function).