public void startGame() {
   space.remove(car_con[index]);
   localRootNode.detachChild(cars[index]);
   localRootNode.detachChild(floor);
   carView.detachScene(localRootNode);
   stateManager.detach(this);
   gameState.setName(playerName);
   gameState.setCar(car_names[index]);
   gameState.setLevel(1, false);
   gameState.setDefeatedCars(0);
   stateManager.attach(gameState);
 }
Beispiel #2
0
  private void closeGame(boolean isServerRestart) {
    try {
      if (!isServerRestart) {
        clientState.cleanup();
        setupNetwork();
      }

      playersContainer.clear();
      syncState.cleanup();

      teamsContainer.clear();

      bulletAppState.setEnabled(false);
      physicsWrapper.cleanup(ingameState.getRootNode());

      ingameState.cleanup();

      initInput();
      stateManager.detach(hudState);
      stateManager.detach(spawnMenuState);
      stateManager.detach(scoreBoardState);

      ingameState.setEnabled(false);
      loadingState.setEnabled(false);
      syncState.setEnabled(false);

      localPlayer = null;

      if (endState != null) {
        stateManager.detach(endState);
        endState = null;
      }

      menuState.setEnabled(!isServerRestart);
    } catch (IllegalAccessException e) {
      // TODO
      e.printStackTrace();
    }
  }
Beispiel #3
0
  @Override
  public void init(SimpleApplication app) {
    AppStateManager stateManager = app.getStateManager();

    app.getFlyByCamera().setMoveSpeed(10f);

    app.getCamera().setLocation(new Vector3f(4.497525f, 6.3693237f, 4.173162f));
    app.getCamera().setRotation(new Quaternion(0.5199084f, 0.42191547f, -0.32954147f, 0.6656463f));
    app.getFlyByCamera().setDragToRotate(true);

    BulletAppState bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    // bulletAppState.setDebugEnabled(true);

    seAPI = SpatialEnvironmentAPI.createSpatialEnvironmentAPI(app);

    seAPI.getWorldAppState().setCalendar(2013, 1, 1, 12, 0, 0);
    seAPI.getWorldAppState().setLandType(WorldAppState.LandType.Basic);
    seAPI
        .getHouseAppState()
        .runCommand(new CreateHouseCommand("House1", HouseFactory.HouseType.BrickHouse60m));

    bodiesAppState = new BodiesAppState();
    stateManager.attach(bodiesAppState);

    bodiesAppState.createBody(BodiesAppState.BodyType.Elder, "Patient");
    bodiesAppState.setInSpace("Patient", "House1", "Kitchen");
    // haveAShower();
    // sitDown("WC1");
    goToUse("WC1");
    // bodiesAppState.runCommand(new GoToSpaceCommand("Patient", "Kitchen"));
    // sitDown("Sofa3Seats");
    bodiesAppState.runCommand(new TremblingHeadCommand("Patient", true));
    bodiesAppState.runCommand(new TremblingHandCommand("Patient", true, true));
    bodiesAppState.runCommand(new TremblingHandCommand("Patient", true, false));
    // bodiesAppState.runCommand(new SetCameraToBodyCommand("Patient"));
    bodiesAppState.runCommand(new SetPCListenerToBodyCommand("Patient"));
    // bodiesAppState.runCommand(new BodyLabelCommand("Patient", true));
  }
Beispiel #4
0
  @Override
  public void run() {
    while (!Thread.currentThread().isInterrupted()) {
      long time = System.currentTimeMillis();
      stateManager.update((float) 0.02);
      long nextTick = (long) (time + 20);
      long towait = nextTick - System.currentTimeMillis();

      tickCount++;
      waitTime += towait;

      if (towait > 0)
        try {
          Thread.sleep(towait);
        } catch (InterruptedException e) {
          break;
        }
    }
  }
Beispiel #5
0
  public LogicLoop(EntityData ed, Command command) {
    stateManager = new AppStateManager(null);

    stateManager.attach(new DataState(ed, command));

    stateManager.attach(new ChasingCameraProc());
    stateManager.attach(new RotationThrusterProc());
    stateManager.attach(new ThrusterProc());
    // forces
    stateManager.attach(new NeededRotationProc());
    stateManager.attach(new NeededThrustProc());
    stateManager.attach(new RandomDraggingProc());
    stateManager.attach(new DraggingProc());
    stateManager.attach(new PhysicForceProc());
    stateManager.attach(new RandomVelocityApplicationProc());
    stateManager.attach(new BoostProc());
    stateManager.attach(new VelocityApplicationProc());
    // collisions
    stateManager.attach(new TouchingClearingProc());
    stateManager.attach(new CircleCircleCollisionProc());
    stateManager.attach(new CircleEdgeCollisionProc());
    stateManager.attach(new EdgeEdgeCollisionProc());
    stateManager.attach(new CollisionResolutionProc());
    // relations
    stateManager.attach(new BoneHoldingProc());
    stateManager.attach(new PlanarHoldingProc());
    stateManager.attach(new LightThrusterProc());

    // ability
    stateManager.attach(new PlayerAbilityControlProc());
    stateManager.attach(new BehaviorTreeProc());
    stateManager.attach(new AbilityProc());
    stateManager.attach(new AbilityTriggerResetProc());
    stateManager.attach(new AbilityCoolDownProc());
    stateManager.attach(new TriggerRepeaterProc());

    stateManager.attach(new SpawnMultipleOnBornProc());
    stateManager.attach(new ProjectileLauncherProc());

    stateManager.attach(new DamagingProc());
    stateManager.attach(new DamagingOverTimeProc());
    stateManager.attach(new AttritionProc());
    stateManager.attach(new ShieldProc());
    stateManager.attach(new SpawnOnShieldDepletedProc());

    stateManager.attach(new SightProc());

    stateManager.attach(new SpawnOnTouchProc());
    stateManager.attach(new DamageOnTouchProc());
    stateManager.attach(new DestroyedOnTouchProc());
    stateManager.attach(new ShockwaveOnTouchProc());

    stateManager.attach(new LifeTimeProc());
    stateManager.attach(new SpawnOnDecayProc());

    stateManager.attach(new RemovedCleanerProc());
    stateManager.attach(new RemoverProc());
    stateManager.attach(new ParentingCleanerProc());
  }
Beispiel #6
0
  private void loadGame(GameInfoInitData data) throws Exception {
    final GameInfo gameInfo = data.getGameInfo();

    enableDebug = gameInfo.isEnableDebug();

    final long localPlayerId = data.getPlayerId();
    final Faction localPlayerFaction = data.getFaction();
    final long initMoney = gameInfo.getInitMoney();

    final Faction[] playerFactions = data.getPlayerFactions();
    final String[] playerNames = data.getPlayerNames();
    final String[] playerShipNames = data.getPlayerShipNames();
    final long[] playerShipIds = data.getPlayerShipIds();
    final long[] playerIds = data.getPlayerIds();

    final List<WeaponAddedMessage> weaponAddedMessages = data.getWeaponAddedMessages();

    syncState.setTickRate(gameInfo.getServerTickRate());

    loadingState = new LoadingStateImpl(screen, rootNode, guiNode);
    stateManager.attach(loadingState);

    final String mapName = gameInfo.getMapName();
    final MapData mapData =
        JsonHelper.get()
            .toPOJO(
                FileConstants.MAPS_PATH_COMPLETE + mapName + FileConstants.MAP_DATA_FILE,
                MapData.class);

    short teamId = 1;
    Team team1 = new Team(teamId, mapData.getFaction1(), playerIds.length);
    teamId++;
    Team team2 = new Team(teamId, mapData.getFaction2(), playerIds.length);

    teamsContainer.setTeam1(team1);
    teamsContainer.setTeam2(team2);

    final ClientLoadingStepsBuilder builder =
        new ClientLoadingStepsBuilder(
            assetManager,
            mapData,
            entityFactory,
            ingameState.getRootNode(),
            gameInfo,
            cam,
            entityAttacher,
            teamsContainer);
    final List<LoadingStep> steps = builder.createLoadingSteps();

    for (int i = 0; i < playerFactions.length; i++) {
      final int a = i;

      steps.add(
          new LoadingStep(10f, true) {
            @Override
            public void load() throws Exception {
              final long playerId = playerIds[a];

              if (localPlayerId != playerId) {
                final Faction faction = playerFactions[a];
                final String playerName = playerNames[a];
                final String shipName = playerShipNames[a];
                final long entityId = playerShipIds[a];

                final Team team = teamsContainer.getTeam(faction);
                final Player player =
                    new Player(
                        playerName,
                        playerId,
                        team,
                        initMoney,
                        false,
                        teamsContainer.getEnemyTeam(team));
                playersContainer.addPlayer(player);
                team.addPlayer(player);

                if (shipName != null) {
                  final Node ship = entityFactory.createShip(shipName);
                  ship.setUserData(EntityConstants.ID, entityId);
                  ship.setUserData(EntityConstants.PLAYER, player);
                  player.setShip(ship);
                }
              }
            }
          });
    }

    for (final WeaponAddedMessage wam : weaponAddedMessages) {
      final WeaponAddedMessageHandler handler = new WeaponAddedMessageHandler(dataContainer);

      steps.add(
          new LoadingStep(5f, true) {

            @Override
            public void load() throws Exception {
              handler.handleMessage(null, wam);
            }
          });
    }

    steps.add(
        new LoadingStep(1f, true) {
          @Override
          public void load() throws Exception {
            final Team team = teamsContainer.getTeam(localPlayerFaction);
            localPlayer =
                new Player(
                    ClientConfig.getString(ClientConfigConstants.c_username),
                    localPlayerId,
                    team,
                    initMoney,
                    true,
                    teamsContainer.getEnemyTeam(team));
            playersContainer.addPlayer(localPlayer);
            team.addPlayer(localPlayer);

            spawnMenuState = new SpawnMenuStateImpl(screen, rootNode, guiNode);
            stateManager.attach(spawnMenuState);

            hudState =
                new HUDStateImpl(screen, rootNode, guiNode, enqueueHelper, cam, assetManager);
            stateManager.attach(hudState);

            scoreBoardState =
                new ScoreBoardStateImpl(
                    screen, rootNode, guiNode, team, teamsContainer.getEnemyTeam(team));
            stateManager.attach(scoreBoardState);
            scoreBoardState.setEnabled(false);

            clientState.sendMessage(new GameStateRequestMessage());
          }
        });

    loadingThread = new LoadingThread(steps, enqueueHelper, loadingState);

    menuState.setEnabled(false);
    loadingState.setEnabled(true);
    loadingThread.start();
  }
Beispiel #7
0
  public void init(boolean clientConfigExisted) throws Exception {
    stateManager.detach(stateManager.getState(FlyCamAppState.class));
    stateManager.detach(stateManager.getState(StatsAppState.class));

    guiNode.detachAllChildren();

    guiNode.addControl(screen);

    consoleState = new ConsoleStateImpl(screen, rootNode, guiNode);
    stateManager.attach(consoleState);
    consoleState.setEnabled(false);

    menuState = new MenuStateImpl(screen, rootNode, guiNode);
    stateManager.attach(menuState);

    if (clientConfigExisted) {
      menuState.setEnabled(true);
    } else {
      usernameInputState = new UsernameInputStateImpl(screen, rootNode, guiNode);
      stateManager.attach(usernameInputState);
      usernameInputState.setEnabled(true);
      menuState.setEnabled(false);
    }

    playersContainer = new ClientPlayersContainer();
    entityIdProvider = new ClientEntityIdProvider();
    entityFactory = new ClientEntityFactory(assetManager, entityIdProvider);

    final ClientFactory clientFactory =
        new ClientFactory() {
          @Override
          public NetworkClient createClient() {
            return Network.createClient();
          }
        };

    clientState = new ClientStateImpl(clientFactory);
    syncState = new ClientSyncState(enqueueHelper, clientState, playersContainer);

    FPSState fpsState = new FPSStateImpl(screen, rootNode, guiNode);
    stateManager.attach(fpsState);
    fpsState.setEnabled(true);

    ingameState = new ClientIngameStateImpl(rootNode, guiNode);
    stateManager.attach(ingameState);
    ingameState.setEnabled(false);
    stateManager.attach(syncState);
    syncState.setEnabled(false);

    bulletAppState = new BulletAppState();
    bulletAppState.setThreadingType(ThreadingType.SEQUENTIAL);
    stateManager.attach(bulletAppState);
    bulletAppState.setEnabled(false);

    PhysicsSpace physicsSpace = bulletAppState.getPhysicsSpace();
    physicsSpace.setGravity(new Vector3f());

    physicsWrapper = new PhysicsWrapperImpl();
    physicsWrapper.setPhysicsSpace(physicsSpace);

    entityAttacher = new EntityAttacher(ingameState.getRootNode(), syncState, physicsWrapper);

    teamsContainer = new TeamsContainer();

    dataContainer =
        new ClientDataContainer(
            entityFactory,
            teamsContainer,
            enqueueHelper,
            entityAttacher,
            clientState,
            playersContainer,
            syncState);
    clientMessageListener = new ClientMessageListener(dataContainer);
    setupNetwork();
    stateManager.attach(clientState);

    respawnLocalPlayerHandler = new RespawnLocalPlayerHandler(cam);
    eventBus.addHandler(RespawnPlayerEvent.TYPE, respawnLocalPlayerHandler);

    initInput();

    initEventBus();
  }