Difficult-Rocket/bin/client.py

108 lines
2.8 KiB
Python
Raw Normal View History

2020-12-13 18:39:12 +08:00
"""
writen by shenjackyuanjie
mail: 3695888@qq.com
"""
2021-01-21 15:05:29 +08:00
import multiprocessing as mp
2020-12-13 18:39:12 +08:00
2021-02-03 22:04:34 +08:00
import re
import pyglet
2021-01-11 22:54:41 +08:00
import pyglet.app
2020-12-13 18:39:12 +08:00
from pyglet.resource import image
from pyglet.window import Window
2020-12-13 18:39:12 +08:00
2021-02-03 22:04:34 +08:00
try:
# editing use
import configs
import tools
except ModuleNotFoundError:
# ben import use
from bin import configs
from bin import tools
2020-12-16 06:33:33 +08:00
2021-01-21 15:05:29 +08:00
class RenderThread(mp.Process, pyglet.window.Window):
2021-01-11 21:58:51 +08:00
2021-01-25 12:22:55 +08:00
def __init__(self, dev_list, dev_dic, logger, net_mode='local'):
2021-02-03 22:04:34 +08:00
"""
:param dev_list: 共享内存
:param dev_dic: 共享内存
:param logger: logger
:param net_mode: 网络模式 # local / ip
"""
2021-01-23 21:35:20 +08:00
# do father class __init__()
2020-12-21 18:46:20 +08:00
Window.__init__(self)
2021-01-21 15:05:29 +08:00
mp.Process.__init__(self)
2021-01-25 12:22:55 +08:00
# logging
self.logger = logger
# share memory
2021-01-21 15:05:29 +08:00
self.dev_list = dev_list
self.dev_dic = dev_dic
2021-02-03 22:04:34 +08:00
# value
self.process_id = 'Client'
self.process_name = 'Client process'
self.view = 'space'
self.net_mode = net_mode
# image
self.b_g = image("back_ground_space.png")
# configs
self.window_config = tools.config('sys_value/window.json5')
self.part_list = tools.config('sys_value/parts.json5')
self.map_view = [configs.basic_poi(poi_type='view')]
2020-12-16 06:33:33 +08:00
# dic
2021-02-03 22:04:34 +08:00
self.ships = {} # all ship
2020-12-16 06:33:33 +08:00
self.planet_system = {} # hole planet system
# list
2021-02-03 22:04:34 +08:00
# re stuff
self.ipv4_re = re.compile("""^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}$""")
# window
self.window = Window(width=int(self.window_config['width']),
height=int(self.window_config['height']),
fullscreen=tools.mbool(self.window_config['full_screen']),
caption=str(self.window_config['caption']),
visible=tools.mbool(self.window_config['visible']))
# setup
self.setup()
2020-12-16 06:33:33 +08:00
def start_game(self):
2021-01-11 22:54:41 +08:00
pyglet.app.run()
2020-12-16 06:33:33 +08:00
return
def setup(self):
2021-02-03 22:04:34 +08:00
# net_mode
if self.net_mode == 'local':
pass
elif re.match(self.ipv4_re, self.net_mode): # net_mode != 'local' and ,can is a ipv4 ip
pass
# textures
2020-12-16 06:33:33 +08:00
2021-01-29 14:07:40 +08:00
"""
draws
"""
2020-12-16 06:33:33 +08:00
def on_draw(self):
2021-02-03 22:04:34 +08:00
if self.view in list:
pass
2021-01-29 14:07:40 +08:00
def part_draw(self):
2021-01-28 19:43:26 +08:00
# render parts
2021-02-02 16:45:20 +08:00
for ship in self.ships:
2021-02-03 22:04:34 +08:00
# get ship poi
2021-01-28 22:50:28 +08:00
ship_poi = ship['brain'][3]
2021-02-03 22:04:34 +08:00
distances = tools.distance(ship_poi, self.map_view)
2021-01-28 22:07:57 +08:00
for part in ship:
pass
2020-12-16 06:33:33 +08:00
2021-01-28 22:50:28 +08:00
"""
keyboard and mouse input
"""
def on_mouse_motion(self, x, y, dx, dy):
2020-12-16 06:33:33 +08:00
pass
def on_key_press(self, symbol, modifiers):
2020-12-16 06:33:33 +08:00
pass
def on_key_release(self, symbol, modifiers):
2020-12-16 06:33:33 +08:00
pass