import arcade WIDTH = 1280 HEIGHT = 800 x = 210 y = 235 SPEED = 270 keys = set() star_x, star_y = 1070, 540 meteor_x, meteor_y = 720, 385 meteor_speed = 200 state = "playing" window = arcade.Window(WIDTH, HEIGHT, "Звезда и Метеор") background = arcade.load_texture("assets/background.png") hero = arcade.load_texture("assets/astronaut.png") star = arcade.load_texture("assets/star.png") meteor = arcade.load_texture("assets/meteor.png") message = arcade.Text("", 640, 710, (255, 226, 136), 30, anchor_x="center", font_name="Arial") def draw_image(texture, x, y, size): arcade.draw_texture_rect(texture, arcade.XYWH(x, y, size, size)) def touches(ax, ay, bx, by): return abs(ax - bx) < 60 and abs(ay - by) < 60 def restart(): global x, y, meteor_x, meteor_speed, state x, y = 210, 235 meteor_x = 720 meteor_speed = 200 state = "playing" keys.clear() def draw(): window.clear() arcade.draw_texture_rect(background, arcade.LBWH(0, 0, WIDTH, HEIGHT)) draw_image(hero, x, y, 132) draw_image(star, star_x, star_y, 90) draw_image(meteor, meteor_x, meteor_y, 132) message.text = "" if state == "won": message.text = "Звезда найдена!" elif state == "lost": message.text = "Столкновение." message.draw() def key_pressed(key, modifiers): keys.add(key) if key == arcade.key.R: restart() def key_released(key, modifiers): keys.discard(key) def update(delta_time): global x, y global meteor_x, meteor_speed global state if state != "playing": return if arcade.key.RIGHT in keys: x += SPEED * delta_time if arcade.key.LEFT in keys: x -= SPEED * delta_time if arcade.key.UP in keys: y += SPEED * delta_time if arcade.key.DOWN in keys: y -= SPEED * delta_time x = max(96, min(1184, x)) y = max(171, min(589, y)) meteor_x += meteor_speed * delta_time if meteor_x > 1110: meteor_x = 1110 meteor_speed = -200 elif meteor_x < 340: meteor_x = 340 meteor_speed = 200 if touches(x, y, meteor_x, meteor_y): state = "lost" elif touches(x, y, star_x, star_y): state = "won" window.on_draw = draw window.on_key_press = key_pressed window.on_key_release = key_released window.on_update = update window.on_deactivate = keys.clear arcade.run()