def load_page(path, *callbacks): with open(path) as f: system = sandbox.get_system(GUISystem) if callbacks: system.load_string(f.read(), *callbacks) else: system.load_string(f.read())
def newPlayerShip(self, account, accountEntity): ship = sandbox.createEntity() component = ships.PilotComponent() component.account = account component.accountEntityID = accountEntity.id ship.addComponent(component) component = ships.BulletPhysicsComponent() component.bulletShape = BulletSphereShape(5) component.node = BulletRigidBodyNode(account.name) component.node.setMass(1.0) component.node.addShape(component.bulletShape) component.nodePath = universals.solarSystemRoot.attachNewNode(component.node) physics.addBody(component.node) position = sandbox.get_system(solarSystem.SolarSystemSystem).solarSystemRoot.find("**/Earth").getPos() component.nodePath.setPos(position + Point3(6671, 0, 0)) component.node.setLinearVelocity(Vec3(0, 7.72983, 0)) ship.addComponent(component) component = ships.ThrustComponent() ship.addComponent(component) component = ships.InfoComponent() ship.addComponent(component) messenger.send("shipGenerated", [ship]) messenger.send("putPlayerOnShip", [accountEntity.id, ship.id]) #TODO Transmit player's ship data #TODO Broadcast new ship data #TODO Prioritize updating new client of surroundings
def sendShipUpdates(self, task): ships = sandbox.get_system(shipSystem.ShipSystem).getPlayerShipEntities() ships += sandbox.get_entities_by_component_type(shipComponents.AIPilotComponent) #self.broadcastData(protocol.sendShipUpdates(ships)) for ship in ships: self.broadcastData(protocol_old.sendShipUpdates([ship])) return task.again
def addSpaceship(self, component, shipName, position, linearVelcocity): component.bulletShape = BulletSphereShape(5) component.node = BulletRigidBodyNode(shipName) component.node.setMass(1.0) component.node.addShape(component.bulletShape) component.nodePath = universals.solarSystemRoot.attachNewNode(component.node) addBody(component.node) position = sandbox.get_system(solarSystem.SolarSystemSystem).solarSystemRoot.find("**/Earth").getPos() #component.nodePath.setPos(position + Point3(6671, 0, 0)) component.nodePath.setPos(position) #component.node.setLinearVelocity(Vec3(0, 7.72983, 0)) component.node.setLinearVelocity(linearVelcocity)
def getPhysicsWorld(): return sandbox.get_system(PhysicsSystem).world
def getPhysics(): return sandbox.get_system(PhysicsSystem)
def setup_screen(screen): """Generates a screen and callbacks from a screen object.""" system = sandbox.get_system(GUISystem) system.setup_screen(screen)
def main_menu(): """Main menu management.""" import sandbox from panda3d.core import Vec3 from spacedrive.renderpipeline import DirectionalLight, PointLight import math import gui_manager spacedrive.gui_system.setup_screen(gui_manager.MainMenu()) solar_system_db = {'Sol': { 'Sol': {'spectral': 'G2V', 'absolute magnitude': 4.83, 'texture': 'sun_1k_tex.jpg', 'mass': 2e+30, 'radius': 695500000.0, 'rotation': 25.38, 'temperature': 5778, 'type': 'star', 'bodies': { 'Earth': {'atmosphere': {'height': 10000}, 'semimajor': 149598261, 'period': 365.256363004, 'textures': { 'diffuse': 'Planets/Earth/textures/earth_#.png', 'specular': 'Planets/Earth/textures/earth_spec_#.png', 'night': 'Planets/Earth/textures/earth_night_#.png'}, 'orbit': {'a': 1.00000018, 'e': 'lambda d: 0.01673163 - 3.661e-07 * d', 'w': 'lambda d: 108.04266274 + 0.0031795260 * d', 'i': 'lambda d: -0.00054346 + -0.0001337178 * d', 'M': 'lambda d: -2.4631431299999917', 'N': 'lambda d: -5.11260389 + -0.0024123856 * d'}, 'mass': 5.9742e+24, 'radius': 6371000.0, 'rotation': 1, 'type': 'solid'}}}}} def update(task=None): """ Main update task """ if True: animationTime = sandbox.base.taskMgr.globalClock.getFrameTime() * 0.6 # displace every light every frame - performance test! for i, light in enumerate(lights): lightAngle = float(math.sin(i * 1253325.0)) * \ math.pi * 2.0 + animationTime * 1.0 initialPos = initialLightPos[i] light.setPos(initialPos + Vec3(math.sin(lightAngle) * 0.0, math.cos(lightAngle) * 0.0, math.sin(animationTime) * 10.0)) if task is not None: return task.cont shuttle = sandbox.base.loader.loadModel("Ships/Shuttle MKI/shuttle") shuttle.reparent_to(sandbox.base.render) shuttle.set_pos(100, 0, 0) #shuttle.set_pos(00, 100, 0) #shuttle.set_pos(10, 50, 10) shuttle.set_hpr(-110, -30, 0) '''from direct.interval.LerpInterval import LerpHprInterval l = LerpHprInterval(shuttle, 10, Vec3(-110, -30, 360)) l.loop()''' skybox = sandbox.base.loader.loadModel("Skybox/Skybox") skybox.set_scale(sandbox.base.camLens.get_far()*0.8) skybox.reparent_to(sandbox.base.render) sandbox.render_pipeline.reloadShaders() skybox.setShader(Shader.load(Shader.SLGLSL, "Shader/DefaultShaders/Opaque/vertex.glsl", "Shader/Skybox/fragment.glsl")) lights = [] initialLightPos = [] colors = [ Vec3(1, 0, 0), Vec3(0, 1, 0), Vec3(0, 0, 1), Vec3(1, 1, 0), Vec3(1, 0, 1), Vec3(0, 1, 1), Vec3(1, 0.5, 0), Vec3(0, 0.5, 1.0), ] # Add some shadow casting lights '''for i in xrange(4): angle = float(i) / 8.0 * math.pi * 2.0 pos = Vec3(math.sin(angle) * 10.0, math.cos(angle) * 10.0 + 50, 7) light = PointLight() light.setRadius(10.0) light.setColor(colors[i] * 2.0) light.setPos(pos) light.setShadowMapResolution(1024) light.setCastsShadows(True) # add light sandbox.base.render_pipeline.addLight(light) lights.append(light) initialLightPos.append(pos)''' import spacedrive.utils.texture as texture_utils #texture_utils.prepare_srgb(sandbox.base.render) #sandbox.base.addTask(update, "update") from spacedrive import orbit_system key = 'Sol' orbit_system.create_solar_system(name=key, database=solar_system_db) import sandbox from spacedrive.celestial_components import CelestialComponent for component in sandbox.get_components(CelestialComponent): if component.name.lower() == 'earth': from panda3d.core import Point3D spawn = Point3D(component.true_pos) #spawn.set_y(spawn.get_y() - (6471000*1.5)) spawn.set_x(spawn.get_x() - (6471000*2)) #spawn.set_x(spawn.get_x() + 6471000) system = sandbox.get_system(spacedrive.GraphicsSystem) system.current_pos = spawn print("Spawn point:", spawn) print("Spawn delta:", spawn - component.true_pos) from spacedrive.renderpipeline.Code.MovementController import MovementController controller = MovementController(base) controller.setup() base.accept('new game screen', start_sp_game) base.camera.set_hpr(-90, 0, 0)