コード例 #1
0
ファイル: Overworld.java プロジェクト: CaptainSly/HelixEngine
  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());
  }
コード例 #2
0
  @Test
  public void packed_component_mappers_return_new_instance_on_request() {
    world.initialize();

    Entity e1 = createEntity(Packed.class);
    Entity e2 = createEntity(Packed.class);
    Packed packed1 = packedMapper.get(e1, true);
    Packed packed2 = packedMapper.get(e2, true);

    assertNotEquals(packed1.entityId, packed2.entityId);
  }
コード例 #3
0
  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) {
      }
    }
  }
コード例 #4
0
  @Test
  public void packed_components_are_known_to_mapper() {
    world.initialize();

    List<Entity> packed = new ArrayList<Entity>();
    packed.add(createEntity(Packed.class));
    packed.add(createEntity(Packed.class));
    packed.add(createEntity(Packed.class));
    Entity notPresent = createEntity();
    packed.add(createEntity(Packed.class));
    packed.add(createEntity(Packed.class));

    for (Entity e : packed) {
      assertTrue(packedMapper.has(e));
    }
    assertFalse(packedMapper.has(notPresent));

    packed.get(1).edit().remove(Packed.class);
    for (int i = 0; packed.size() > i; i++) {
      if (i != 1) assertTrue(packedMapper.has(packed.get(i)));
    }
    assertFalse(packedMapper.has(packed.get(1)));
  }
コード例 #5
0
ファイル: GameXYZ.java プロジェクト: haibuo1981/javagamexyz
  public GameXYZ(Game game) {
    this.game = game;

    batch = new SpriteBatch();
    camera = new OrthographicCamera();

    world = new World();
    spriteRenderSystem = world.setSystem(new SpriteRenderSystem(camera), true);
    mapRenderSystem = world.setSystem(new MapRenderSystem(camera), true);
    hudRenderSystem = world.setSystem(new HudRenderSystem(camera), true);

    world.setSystem(new SpriteAnimationSystem());
    world.setSystem(new PlayerInputSystem(camera));
    world.initialize();

    EntityFactory.createMap(world).addToWorld();
    EntityFactory.createPlayer(world, 11, 14).addToWorld();
    for (int i = 0; i < 100; i++)
      EntityFactory.createWarrior(
              world,
              MathUtils.random(MapTools.width() - 1),
              MathUtils.random(MapTools.height() - 1))
          .addToWorld();
  }
コード例 #6
0
 @Before
 public void setup() {
   world = new World();
   world.initialize();
 }
コード例 #7
0
  @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));
      }
    }
  }
コード例 #8
0
  public void Create() {
    // set tilemap file name
    m_MapFileName = "map/test.tmx";

    // set up the tilemap
    m_TiledMap = new TmxMapLoader().load(m_MapFileName);
    m_TiledMapRenderer = new OrthogonalTiledMapRenderer(m_TiledMap, 1f);

    // set up the box2d physics
    m_PhysicsWorld = new com.badlogic.gdx.physics.box2d.World(new Vector2(0, 0), true);

    // attach contact listener to physics world
    m_PhysicsWorld.setContactListener(new GameContactListener(this));

    // set up box2dlights
    m_RayHandler = new RayHandler(m_PhysicsWorld);
    m_RayHandler.setAmbientLight(0.0f);

    // add tilemap collision boxes to physics world
    for (int i = 0; i < m_TiledMap.getLayers().getCount(); i++) {
      if (m_TiledMap.getLayers().get(i) instanceof TiledMapTileLayer) {
        TiledMapTileLayer layer = (TiledMapTileLayer) m_TiledMap.getLayers().get(i);
        for (int j = 0; j < layer.getWidth(); j++) {
          for (int k = 0; k < layer.getHeight(); k++) {
            Cell cell = layer.getCell(j, k);
            if (cell != null) {
              TiledMapTile tile = cell.getTile();
              if (tile != null) {
                MapProperties props = tile.getProperties();
                if (props.containsKey("blocked")) {
                  float worldX = j * 64 + 32;
                  float worldY = k * 64 + 32;
                  BodyDef bodyDef = new BodyDef();
                  bodyDef.type = BodyType.StaticBody;
                  bodyDef.position.set(new Vector2(worldX * WORLD_TO_BOX, worldY * WORLD_TO_BOX));

                  Body newBody = m_PhysicsWorld.createBody(bodyDef);

                  PolygonShape boxShape = new PolygonShape();
                  boxShape.setAsBox(32 * WORLD_TO_BOX, 32 * WORLD_TO_BOX);

                  // Create a fixture definition to apply our shape to
                  FixtureDef fixtureDef = new FixtureDef();
                  fixtureDef.shape = boxShape;

                  newBody.createFixture(fixtureDef);

                  boxShape.dispose();
                }

                if (props.containsKey("rotate")) {
                  // flip some random tiles to break pattern
                  if (k * j % 3 == 0) layer.getCell(j, k).setFlipVertically(true);
                  if (k * j % 2 == 0) layer.getCell(j, k).setFlipHorizontally(true);
                }
              }
            }
          }
        }
      }
    }

    // set up artemis entity system
    m_ArtemisWorld = new com.artemis.World();

    // add the passive systems
    m_SpineRenderSystem = new SpineRenderSystem(m_GameScreen);
    m_ArtemisWorld.setSystem(m_SpineRenderSystem, true);

    // add the systems
    m_ArtemisWorld.setSystem(new PlayerInputSystem(this));
    m_ArtemisWorld.setSystem(new CameraSystem(m_GameScreen.m_Camera));
    m_ArtemisWorld.setSystem(new PhysicsSystem());
    m_ArtemisWorld.setSystem(new LifecycleSystem(this));
    m_ArtemisWorld.setSystem(new SteeringSystem());

    // init the world
    m_ArtemisWorld.initialize();
    EntityHelper.LoadObjects(
        m_GameScreen, m_ArtemisWorld, m_TiledMap, m_PhysicsWorld, m_RayHandler);

    // add player to entity list
    m_PlayerEntity = new PlayerEntity();
    m_PlayerEntity.AddToWorld(this);
    checkpointPos = new Vector2(0, 0);
    checkpointPos.x = m_PlayerEntity.m_Entity.getComponent(PositionComponent.class).m_X;
    checkpointPos.y = m_PlayerEntity.m_Entity.getComponent(PositionComponent.class).m_Y;

    // hud items are special cases since they needs to draw on top of border
    m_VialOne = new SpineComponent("map/vial", 5, 0.75f, -25);
    m_VialTwo = new SpineComponent("map/vial", 5, 0.65f, -5);
    m_VialThree = new SpineComponent("map/vial", 5, 0.75f, -50);
    m_WatchSpine = new SpineComponent("map/watch", 4, 0.75f, 0);

    if (m_GameScreen.m_Settings.m_WatchFound) {
      ActivateWatch();
      BodyComponent bodyComponent = m_PlayerEntity.m_Entity.getComponent(BodyComponent.class);
      bodyComponent.m_Body.setTransform(621 * WORLD_TO_BOX, 5961 * WORLD_TO_BOX, 0);
    }
    if (m_GameScreen.m_Settings.m_WeaponFound) {
      ActivateSword();
      BodyComponent bodyComponent = m_PlayerEntity.m_Entity.getComponent(BodyComponent.class);
      bodyComponent.m_Body.setTransform(1965 * WORLD_TO_BOX, 4842 * WORLD_TO_BOX, 0);
    }
    if (m_GameScreen.m_Settings.m_WeaponLightFound) {
      ActivateSwordLight();
      BodyComponent bodyComponent = m_PlayerEntity.m_Entity.getComponent(BodyComponent.class);
      bodyComponent.m_Body.setTransform(6390 * WORLD_TO_BOX, 6462 * WORLD_TO_BOX, 0);
    }
  }
コード例 #9
0
ファイル: GameScreen.java プロジェクト: noffle/ECSTalk
  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();
  }