提交 31d10b7c 编写于 作者: 三月三net's avatar 三月三net

太阳系三体模拟器

上级 fb197fa0
......@@ -7,7 +7,7 @@
# python_version :3.8
# ==============================================================================
# pip install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com ursina
from ursina import Ursina, window, Entity, Grid, Mesh, camera, color, mouse, Vec2, Vec3, load_texture, held_keys
from ursina import Ursina, window, Entity, Grid, Mesh, camera, Text, application, color, mouse, Vec2, Vec3, load_texture, held_keys
from ursina.prefabs.first_person_controller import FirstPersonController
from simulators.views.ursina_view import UrsinaView, UrsinaPlayer
......@@ -110,6 +110,32 @@ class UrsinaSimulator(Simulator):
self.cosmic_background(cosmic_bg)
EditorCamera()
pause_handler = Entity(ignore_paused=True)
# 按空格键则暂停
def pause_handler_input(key):
time_scales = [1, 10, 20, 30]
if key == 'space':
application.paused = not application.paused # Pause/unpause the game.
elif key == 'tab':
# application.time_scale 属性控制游戏时间流逝的速度。
# 具体来说,它是一个浮点数,用于调整游戏时间流逝速度的比例,其默认值为 1.0,表示正常速度。
# 当你将它设置为小于 1.0 的值时,游戏时间会变慢,而设置为大于 1.0 的值时,游戏时间则会变快。
for idx, time_scale in enumerate(time_scales):
if int(application.time_scale) == time_scale:
if idx < len(time_scales) - 1:
application.time_scale = time_scales[idx + 1]
break
else:
application.time_scale = 1
print(application.time_scale)
pause_handler.input = pause_handler_input
# 加载中文字体文件
Text.default_font = 'simsun.ttc'
key_info_str = "方位控制[QWEASD + 鼠标] 暂停控制[空格] 移动速度[Tab]"
key_info = Text(text=key_info_str, position=(-0.8, 0.5), origin=(-1, 1), background=True)
self.app.run()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册