Код:
Код:
acc_x = 0 acc_y = 0 player_x = 1 player_y = 1 enemy_x = 1 enemy_y = 1 enemy_sprite = game.create_sprite(5, 5) player_sprite = game.create_sprite(1, 1) game.set_score(0) def show_player(): global player_x global player_y global player_sprite player_x = randint(0, 5) player_y = randint(0, 5) player_sprite.set(LedSpriteProperty.X, player_x) player_sprite.set(LedSpriteProperty.Y, player_y) def show_enemy(): global enemy_x global enemy_y global enemy_sprite enemy_x = randint(0, 5) enemy_y = randint(0, 5) enemy_sprite.set(LedSpriteProperty.X, enemy_x) enemy_sprite.set(LedSpriteProperty.Y, enemy_y) show_enemy() show_player() def on_forever(): global player_x global player_y global acc_x global acc_y global player_sprite global enemy_sprite acc_x = input.acceleration(Dimension.X) acc_y = input.acceleration(Dimension.Y) if acc_x >= 1023: player_x = player_x + 0.1 elif acc_x <= -1023: player_x = player_x - 0.1 if acc_y >= 1023: player_y = player_y + 0.1 elif acc_y <= -1023: player_y = player_y - 0.1 if player_sprite.is_touching(enemy_sprite): game.add_score(1) basic.clear_screen() show_enemy() show_player() player_sprite.set(LedSpriteProperty.X, int(player_x)) player_sprite.set(LedSpriteProperty.Y, int(player_y)) basic.forever(on_forever) def on_button_pressed_a(): basic.show_number(game.score()) input.on_button_pressed(Button.A, on_button_pressed_a)
Результат работы алгоритма можете смотреть тут:
https://cloud.mail.ru/public/DBFR/FizrKvm1d