提交 5552d087 编写于 作者: 三月三net's avatar 三月三net

Python超人-宇宙模拟器

上级 ada551d3
...@@ -307,11 +307,15 @@ def create_3d_card(left=-.885, top=0.495, width=0.02, height=0.02): ...@@ -307,11 +307,15 @@ def create_3d_card(left=-.885, top=0.495, width=0.02, height=0.02):
position=(left, top, 0) position=(left, top, 0)
) )
panel.switch_flag = 0
def switch_color(): def switch_color():
if panel.color == color.black: if panel.color == color.black:
panel.color = color.white panel.color = color.white
panel.switch_flag = 1
else: else:
panel.color = color.black panel.color = color.black
panel.switch_flag = 0
panel.switch_color = switch_color panel.switch_color = switch_color
......
...@@ -98,12 +98,18 @@ def on_timer_changed(time_data: TimeData): ...@@ -98,12 +98,18 @@ def on_timer_changed(time_data: TimeData):
distance = round(init.light_ship.position[2] / AU, 4) distance = round(init.light_ship.position[2] / AU, 4)
text = init.arrived_info.replace("${distance}", "%.4f AU" % distance) text = init.arrived_info.replace("${distance}", "%.4f AU" % distance)
init.text_panel.text = text.replace("${speed}", str(round(velocity / LIGHT_SPEED, 1)) + "倍光速") init.text_panel.text = text.replace("${speed}", str(round(velocity / LIGHT_SPEED, 1)) + "倍光速")
init._3d_card.switch_color()
light_ship.switch_position()
# if time_data.total_seconds > 20: # if time_data.total_seconds > 20:
# wait_for(0.03) # wait_for(0.03)
def on_before_evolving(evolve_args):
init._3d_card.switch_color()
light_ship.switch_position()
if init._3d_card.switch_flag == 1:
evolve_args["evolve_dt"] = 0.0
# 订阅重新开始事件 # 订阅重新开始事件
# 按键盘的 “O” 重置键会触发 on_reset # 按键盘的 “O” 重置键会触发 on_reset
UrsinaEvent.on_reset_subscription(on_reset) UrsinaEvent.on_reset_subscription(on_reset)
...@@ -113,6 +119,8 @@ UrsinaEvent.on_ready_subscription(on_ready) ...@@ -113,6 +119,8 @@ UrsinaEvent.on_ready_subscription(on_ready)
# 运行中,每时每刻都会触发 on_timer_changed # 运行中,每时每刻都会触发 on_timer_changed
UrsinaEvent.on_timer_changed_subscription(on_timer_changed) UrsinaEvent.on_timer_changed_subscription(on_timer_changed)
UrsinaEvent.on_before_evolving_subscription(on_before_evolving)
def body_arrived(body): def body_arrived(body):
# # 到达每个行星都会触发,对光速飞船进行加速,超光速前进(使用未来曲率引擎技术) # # 到达每个行星都会触发,对光速飞船进行加速,超光速前进(使用未来曲率引擎技术)
......
...@@ -36,6 +36,8 @@ class UrsinaEvent: ...@@ -36,6 +36,8 @@ class UrsinaEvent:
UrsinaEvent.on_body_size_changed_callback = [] UrsinaEvent.on_body_size_changed_callback = []
# 逐步演变触发的订阅事件 # 逐步演变触发的订阅事件
UrsinaEvent.on_evolving_callback = [] UrsinaEvent.on_evolving_callback = []
# 逐步演变触发前的订阅事件
UrsinaEvent.on_before_evolving_callback = []
# 计时器触发的订阅事件 # 计时器触发的订阅事件
UrsinaEvent.on_timer_changed_callback = [] UrsinaEvent.on_timer_changed_callback = []
...@@ -78,6 +80,19 @@ class UrsinaEvent: ...@@ -78,6 +80,19 @@ class UrsinaEvent:
for f in UrsinaEvent.on_evolving_callback: for f in UrsinaEvent.on_evolving_callback:
f(evolve_dt) f(evolve_dt)
@staticmethod
def on_before_evolving_subscription(fun):
UrsinaEvent.on_before_evolving_callback.append(fun)
@staticmethod
def on_before_evolving_unsubscription(fun):
UrsinaEvent.on_before_evolving_callback.remove(fun)
@staticmethod
def on_before_evolving(evolve_args):
for f in UrsinaEvent.on_before_evolving_callback:
f(evolve_args)
@staticmethod @staticmethod
def on_application_run_callback_subscription(fun): def on_application_run_callback_subscription(fun):
UrsinaEvent.on_application_run_callback.append(fun) UrsinaEvent.on_application_run_callback.append(fun)
......
...@@ -224,7 +224,10 @@ class UrsinaSimulator(Simulator): ...@@ -224,7 +224,10 @@ class UrsinaSimulator(Simulator):
UrsinaEvent.on_evolving(evolve_dt) UrsinaEvent.on_evolving(evolve_dt)
# interval_fator 能让更新天体运行状态(位置、速度)更精确 # interval_fator 能让更新天体运行状态(位置、速度)更精确
evolve_dt = evolve_dt * self.interval_fator evolve_dt = evolve_dt * self.interval_fator
super().evolve(evolve_dt) evolve_args = {"evolve_dt": evolve_dt}
UrsinaEvent.on_before_evolving(evolve_args)
# if evolve_args["evolve_dt"] > 0:
super().evolve(evolve_args["evolve_dt"])
if self.show_timer or self.timer_enabled: if self.show_timer or self.timer_enabled:
timer = BodyTimer() timer = BodyTimer()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册