Example #1
0
 def begin(self):
     if fsm.state == 'Nav':
         if sandbox.getSystem(shipSystem.ShipSystem).shipid is not None:
             shipid = sandbox.getSystem(shipSystem.ShipSystem).shipid
             physics = sandbox.entities[shipid].getComponent(shipComponents.BulletPhysicsComponent)
             t = "X: " + str(round(physics.getTruePos().getX(), 1)) + ", Y: " + str(round(physics.getTruePos().getY(), 1)) + ", H: " + str(round(physics.nodePath.getH(), 1))
             text['xyz'].setText(t)
             localtext = "X: " + str(round(physics.nodePath.getX(), 1)) + ", Y: " + str(round(physics.nodePath.getY(), 1))
             text['localxyz'].setText(localtext)
             speedText = "Speed: " + str(round(physics.node.getLinearVelocity().length(), 1)) + " km/s"
             text['speed'].setText(speedText)
Example #2
0
 def sendShipUpdates(self, task):
     ships = sandbox.getSystem(shipSystem.ShipSystem).getPlayerShipEntities()
     ships += sandbox.getEntitiesByComponentType(shipComponents.AIPilotComponent)
     #self.broadcastData(protocol.sendShipUpdates(ships))
     for ship in ships:
         self.broadcastData(protocol.sendShipUpdates([ship]))
     return task.again
Example #3
0
 def sendShipUpdates(self, task):
     ships = sandbox.getSystem(
         shipSystem.ShipSystem).getPlayerShipEntities()
     ships += sandbox.getEntitiesByComponentType(
         shipComponents.AIPilotComponent)
     #self.broadcastData(protocol.sendShipUpdates(ships))
     for ship in ships:
         self.broadcastData(protocol.sendShipUpdates([ship]))
     return task.again
Example #4
0
    def enterMainScreen(self):
        buildBars()
        sandbox.send('perspective')
        sandbox.send('showBG')
        widgets['cameras'] = {}
        shipid = sandbox.getSystem(shipSystem.ShipSystem).shipid
        renderComponent = sandbox.entities[shipid].getComponent(graphicsComponents.RenderComponent)
        for joint in renderComponent.mesh.getJoints():
            if 'camera' in joint.getName().lower():
                #widgets['cameras'][joint.getName()] = joint
                widgets['cameras'][joint.getName()] = renderComponent.mesh.exposeJoint(None, "modelRoot", joint.getName())
        #print "Cameras", widgets['cameras']

        #DirectOptionMenu(text="options", items=ships, command=stationContext, initialitem=-1)
        widgets['cameraMenu'] = DirectOptionMenu(
            items=widgets['cameras'].keys(), command=mainViewContext
        )
        bars['topBar'].pack(widgets['cameraMenu'])
Example #5
0
 def noSelected(self):
     if fsm.state == 'Nav':
         #x = sandbox.base.mouseWatcherNode.getMouseX()
         #y = sandbox.base.mouseWatcherNode.getMouseY()
         x = sandbox.base.mouseWatcherNode.getMouseY()
         y = -sandbox.base.mouseWatcherNode.getMouseX()
         # Rotate to screen coordinate system
         if x != 0:
             angle = math.degrees(math.atan2(y, x))  # - 90
         else:
             angle = 0
         if angle < 0:
             angle += 360
         shipid = sandbox.getSystem(shipSystem.ShipSystem).shipid
         physics = sandbox.entities[shipid].getComponent(shipComponents.BulletPhysicsComponent)
         currentAngle = physics.nodePath.getH() % 360
         trueDifference = abs(currentAngle - angle)
         distance = 180 - abs(trueDifference - 180)
         self.autoTurn = True
         self.autoTurnTarget = angle
         print math.degrees(math.atan2(y, x)), angle, currentAngle, trueDifference, distance
Example #6
0
def playerShipStations():
    shipSys = sandbox.getSystem(shipSystem.ShipSystem)
    playerShips = proto.Ships()
    entities = shipSys.getPlayerShipEntities()
    for entity in entities:
        playerShip = playerShips.ship.add()
        info = entity.getComponent(shipComponents.InfoComponent)
        shipPhysics = entity.getComponent(shipComponents.BulletPhysicsComponent)
        playerShip.name = info.name
        playerShip.className = info.shipClass
        playerShip.id = entity.id
        packFullPhysics(shipPhysics, playerShip)
        player = entity.getComponent(shipComponents.PlayerComponent)
        shipStations = playerShip.stations
        stations = vars(player)
        for stationName, status in stations.items():
            if status == 0:
                setattr(shipStations, stationName, 0)
            else:
                setattr(shipStations, stationName, 1)
    return sandbox.generatePacket(PLAYER_SHIPS, playerShips)
Example #7
0
    def autoTurnManager(self, task):
        if self.autoTurn:
            shipid = sandbox.getSystem(shipSystem.ShipSystem).shipid
            physicsComponent =\
                sandbox.entities[shipid].getComponent(shipComponents.BulletPhysicsComponent)
            currentAngle = physicsComponent.nodePath.getH() % 360

            directionDistance =\
                sandbox.mathextra.signedAngularDistance(
                    self.autoTurnTarget,
                    currentAngle
                )

            #print currentAngle, self.autoTurnTarget, trueDifference, distance, directionDistance
            #print currentAngle, self.autoTurnTarget, directionDistance

            #angularVelocity = physicsComponent.node.getAngularVelocity()

            #self.autoTurnPID.UpdateP(error, position)
            #self.autoTurnPID.UpdateI(error, position)
            #self.autoTurnPID.UpdateD(error, position)

            # Gaines -- tuned experimentally
            Kp = 10 ** 2 * (2 / 5.0 * physicsComponent.node.getMass() * 1 ** 2)
            Ki = 0
            Kd = 2 * 10 * (2 / 5.0 * physicsComponent.node.getMass() * 1 ** 2)

            #pError = self.autoTurnTarget - currentAngle
            pError = directionDistance
            iError = pError * globalClock.getDt()
            dError = (pError - self.lastPError) / globalClock.getDt()

            self.lastPError = pError

            torque = Kp * pError + Ki * iError + Kd * dError
            #print "Calculated Torque:", torque, currentAngle, self.autoTurnTarget, directionDistance
            heading = sandbox.mathextra.clamp(torque, -100, 100)
            widgets['heading']['value'] = -heading
        return task.cont
Example #8
0
def planetPositionDebug(task):
    log.debug("===== Day: " + str(universals.day) + " =====")
    for bod in sandbox.getSystem(solarSystem.SolarSystemSystem).bodies:
        log.debug(bod.getName() + ": " + str(bod.getPos()))
    return task.again
Example #9
0
def getPhysics():
    return sandbox.getSystem(PhysicsSystem)
Example #10
0
File: main.py Project: croxis/itf
def loginDebug(task):
    sandbox.getSystem(client_net.NetworkSystem).sendLogin(universals.username,
                                                          "Hash Password")
Example #11
0
def planetPositionDebug(task):
    log.debug("===== Day: " + str(universals.day) + " =====")
    for bod in sandbox.getSystem(solarSystem.SolarSystemSystem).bodies:
        log.debug(bod.getName() + ": " + str(bod.getPos()))
    return task.again