Exemple #1
0
  /**
   * Create a world with a specified component and entity manager.
   *
   * @param cm ComponentManager to use.
   * @param em EntityManager to use.
   */
  public World(ComponentManager cm, EntityManager em) {
    managers = new Array<Manager>();
    systems = new Array<EntitySystem>();

    added = new ObjectSet<Entity>();
    changed = new ObjectSet<Entity>();
    deleted = new ObjectSet<Entity>();
    enable = new ObjectSet<Entity>();
    disable = new ObjectSet<Entity>();

    addedPerformer =
        new Performer() {
          @Override
          public void perform(EntityObserver observer, Entity e) {
            observer.added(e);
          }
        };
    changedPerformer =
        new Performer() {
          @Override
          public void perform(EntityObserver observer, Entity e) {
            observer.changed(e);
          }
        };
    deletedPerformer =
        new Performer() {
          @Override
          public void perform(EntityObserver observer, Entity e) {
            observer.deleted(e);
          }
        };
    enablePerformer =
        new Performer() {
          @Override
          public void perform(EntityObserver observer, Entity e) {
            observer.enabled(e);
          }
        };
    disablePerformer =
        new Performer() {
          @Override
          public void perform(EntityObserver observer, Entity e) {
            observer.disabled(e);
          }
        };

    this.cm = cm;
    setManager(cm);

    this.em = em;
    setManager(em);
  }
  public Overworld() {
    assetManager = new AssetManager();

    camera = new HelixCamera(30, new Vector3(16, 16, 0), .1f, 35);

    WorldConfiguration worldConfiguration =
        new WorldConfiguration().register(assetManager).register(camera);

    world = new World(worldConfiguration);

    world.setSystem(new PlayerMovementSystem());
    world.setSystem(new CameraClientsUpdateSystem());
    world.setSystem(new AnimationProcessingSystem());
    world.setSystem(new RenderingSystem());
    world.setSystem(new ScreenFadingSystem());

    world.setManager(new UuidEntityManager());
    world.setManager(new TextureManager());
    world.setManager(new GroupManager());
    world.setManager(new TagManager());
    world.setManager(new AreaManager());
    world.setManager(new PlayerManager());
    world.setManager(new LocalAmbienceManager());
    world.setManager(new WeatherMan());
    world.initialize();

    world.getManager(WeatherMan.class).setToType(WeatherMan.WeatherType.RAINSTORM);
    world.getManager(AreaManager.class).load("area1");
    // Temporary
    world
        .getManager(LocalAmbienceManager.class)
        .setAmbience(world.getManager(WeatherMan.class).getWeather());
  }
  public MenuScreen(Game game) {
    camera = new OrthographicCamera();
    this.game = game;
    camera.setToOrtho(false, 480, 640);

    world = new World();
    world.setManager(new GroupManager());

    menuRenderSystem = world.setSystem(new MenuRenderSystem(camera), true);
    world.setSystem(new MenuInputSystem(camera, game));

    world.initialize();

    if (MenuScreen.playerName.isEmpty()) {
      Gdx.input.getTextInput(
          new TextInputListener() {

            @Override
            public void input(String text) {
              if (text.length() > 10) {
                playerName = text.substring(0, 10);
              } else if (text.length() == 10) {
                playerName = text;
              } else {
                playerName = text + "          ".substring(text.length());
              }
            }

            @Override
            public void canceled() {}
          },
          "Enter your name:",
          "");

      try {
        BufferedReader in =
            new BufferedReader(new FileReader(Gdx.files.local("scores.txt").file()));
        while (in.ready()) {
          String[] line = in.readLine().split(",");
          Highscore.scoreTable.add(line);
        }
        in.close();
      } catch (IOException ioe) {
      }
    }
  }
  @Override
  public void init(GameContainer container) throws SlickException {
    world = new World();

    world.setManager(new PlayerManager());
    world.setManager(new TagManager());
    world.setManager(new GroupManager());

    world.setSystem(new SoundSystem());
    world.setSystem(new HealthSystem());
    world.setSystem(new PhysicsSystem());
    world.setSystem(new ExpirationSystem());
    world.setSystem(new PlayerTankTowerSystem(container));
    world.setSystem(new PlayerTankMovementSystem(container));
    world.setSystem(new BoundarySystem(0, 0, 4096, 4096));
    world.setSystem(new CameraSystem(container));
    world.setSystem(new AmmoRegenerationSystem());

    terrainRenderSystem = world.setSystem(new TerrainRenderSystem(container), true);
    renderSystem = world.setSystem(new RenderSystem(container), true);
    hudRenderSystem = world.setSystem(new HudRenderSystem(container), true);
    healthRenderSystem = world.setSystem(new HealthRenderSystem(container), true);
    crosshairRenderSystem = world.setSystem(new CrosshairRenderSystem(container), true);

    world.initialize();

    Entity playerTank = EntityFactory.createMammothTank(world, 300f, 400f);
    world.getManager(PlayerManager.class).setPlayer(playerTank, "APPEL");
    world.getManager(TagManager.class).register("PLAYER", playerTank);
    playerTank.addToWorld();

    {
      Entity e = EntityFactory.createMammothTank(world, 600f, 800f);
      world.getManager(PlayerManager.class).setPlayer(e, "COMPUTER 1");
      e.addToWorld();
    }
    {
      Entity e = EntityFactory.createMammothTank(world, 1000, 200);
      world.getManager(PlayerManager.class).setPlayer(e, "COMPUTER 2");
      e.addToWorld();
    }

    EntityFactory.createWall(world, 756, 540);
    EntityFactory.createWall(world, 756 + (5 * 108), 540);
    EntityFactory.createWall(world, 756 + (10 * 108), 540);

    EntityFactory.createWall(world, 756, 540 + (10 * 108));
    EntityFactory.createWall(world, 756 + (5 * 108), 540 + (10 * 108));
    EntityFactory.createWall(world, 756 + (10 * 108), 540 + (10 * 108));

    rand = new Random(3);
    for (int i = 0; 50 > i; i++) {
      int gx = rand.nextInt(4096);
      int gy = rand.nextInt(4096);
      int g = rand.nextInt(5);

      for (int a = 0; g > a; a++) {
        EntityFactory.createCrate(
            world, gx + rand.nextInt(100), gy + rand.nextInt(100), rand.nextInt(360));
      }
    }
  }
Exemple #5
0
  GameScreen(TestGame game) {
    stage = new Stage();
    this.game = game;

    camera = new OrthographicCamera();
    stage.setCamera(camera);

    world = new World();

    world.setManager(new GroupManager());
    world.setManager(new TagManager());

    Random rand = new Random();

    // Game world.
    Entity root = world.createEntity();
    root.addComponent(new GameWorld());
    root.addToWorld();

    // Four-Direction controller /w keyboard bindings.
    ActionTrigger up = new ActionTrigger("up");
    ActionTrigger down = new ActionTrigger("down");
    ActionTrigger left = new ActionTrigger("left");
    ActionTrigger right = new ActionTrigger("right");
    FourDirectionController fourDirController =
        new FourDirectionController(1500, up, down, left, right);
    KeyboardBindingMap kbMap = new KeyboardBindingMap();
    kbMap.addBinding(Keys.W, up);
    kbMap.addBinding(Keys.S, down);
    kbMap.addBinding(Keys.A, left);
    kbMap.addBinding(Keys.D, right);

    // Create a bunch of villagers.
    for (int i = 0; i < 12; i++) {
      Vector2 pos =
          new Vector2(rand.nextFloat() * stage.getWidth(), rand.nextFloat() * stage.getHeight());
      Entity villager = EntityFactory.createVillager(world, pos);
    }

    // Create a bunch of FREAKING GOBLINS.
    for (int i = 0; i < 4; i++) {
      Vector2 pos =
          new Vector2(rand.nextFloat() * stage.getWidth(), rand.nextFloat() * stage.getHeight());
      Entity goblin = EntityFactory.createGoblin(world, pos);
    }

    Entity player = EntityFactory.createHero(world, new Vector2(250, 250));
    player.addComponent(fourDirController);
    player.addComponent(kbMap);
    world.getManager(TagManager.class).register("player", player);

    world.setSystem(new GoblinRespawnerSystem());

    world.setSystem(new PhysicsMotionSystem());
    world.setSystem(new PhysicsScreenBounceSystem());

    world.setSystem(new WanderBehaviourSystem());
    world.setSystem(new HuntBehaviourSystem());

    world.setSystem(new RectangleRenderer(new ShapeRenderer()));

    world.setSystem(new KeyboardInputSystem());
    world.setSystem(new FourDirectionControllerSystem());

    world.initialize();
  }