@Test public void test_adding_to_systems() { archetypeEntity(arch1, 2); // never inserted archetypeEntity(arch2, 4); // es1 archetypeEntity(arch3, 8); // es1 + 2 world.process(); assertEquals(12, es1.getSubscription().getEntities().size()); assertEquals(8, es2.getSubscription().getEntities().size()); world.process(); }
@Test public void old_entities_are_recycled() { Set<Integer> ids = new HashSet<Integer>(); Entity e1 = world.createEntity(); Entity e2 = world.createEntity(); Entity e3 = world.createEntity(); ids.add(System.identityHashCode(e1)); ids.add(System.identityHashCode(e2)); ids.add(System.identityHashCode(e3)); assertEquals(3, ids.size()); e1.deleteFromWorld(); e2.deleteFromWorld(); e3.deleteFromWorld(); world.process(); Entity e1b = world.createEntity(); Entity e2b = world.createEntity(); Entity e3b = world.createEntity(); ids.add(System.identityHashCode(e1b)); ids.add(System.identityHashCode(e2b)); ids.add(System.identityHashCode(e3b)); assertEquals(3, ids.size()); }
@Test public void should_be_possible_to_re_add_texturecomponent_via_listener() throws Exception { final Entity enemy = createEnemy(Type.GREEN); createEnemyChangeEvent(); world .getAspectSubscriptionManager() .get(Aspect.all(TextureRef.class).exclude(TextureComponent.class)) .addSubscriptionListener( new EntitySubscription.SubscriptionListener() { @Override public void inserted(IntBag entities) { final int[] data = entities.getData(); for (int i = 0; i < entities.size(); i++) { world.getEntity(data[i]).edit().create(TextureComponent.class); } } @Override public void removed(IntBag entities) {} }); world.process(); assertThat(enemy.getComponent(TextureComponent.class)).isNotNull(); }
@Test public void should_change_type_of_enemy_when_an_enemychange_event_is_created() throws Exception { final Entity enemy = createEnemy(Type.GREEN); createEnemyChangeEvent(); world.process(); assertThat(enemy.getComponent(Enemy.class).type).isEqualTo(Type.BLUE); }
@Test public void should_remove_textures_when_type_is_changed() throws Exception { final Entity enemy = createEnemy(Type.GREEN); createEnemyChangeEvent(); world.process(); assertThat(enemy.getComponent(TextureComponent.class)).isNull(); assertThat(enemy.getComponent(NormalTextureComponent.class)).isNull(); }
@Test public void should_remove_update_texture_refs_when_type_is_changed() throws Exception { final Entity enemy = createEnemy(Type.GREEN); createEnemyChangeEvent(); world.process(); assertThat(enemy.getComponent(TextureRef.class).id).isEqualTo(Type.BLUE.image + ".png"); assertThat(enemy.getComponent(NormalRef.class).id).isEqualTo(Type.BLUE.image + "_n.png"); }
@Override public void render(float delta) { Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); Gdx.gl.glClearColor(0, 0, 0, 1); camera.update(); world.setDelta(delta); world.process(); menuRenderSystem.process(); Gdx.graphics.setTitle("Shape Breaker | Menu"); }
protected void createAndProcessWorld(BaseSystem system) { final World world = new World( new WorldConfigurationBuilder() .with(system) .with(new ExtendedComponentMapperPlugin()) .build()); world.createEntity().edit().create(TestMarker.class); world.process(); }
@Before public void setUp() throws Exception { world = new World( new WorldConfiguration() .setSystem(EnemyChangeSystem.class) .setSystem(EntityFactorySystem.class)); world.createEntity().edit().create(InteractionType.class); world.process(); }
@Override public void render(float delta) { Gdx.gl.glClearColor(0.1f, 0.1f, 0.1f, 1); Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); stage.draw(); stage.act(); world.setDelta(delta); world.process(); }
@Before public void init() { world = new World( new WorldConfiguration() .setSystem(new EntityFactory()) .setSystem(new TiledMapSystem())); world.inject(this); world.process(); }
@Test public void active_entities_never_negative() { EntityManager em = world.getEntityManager(); assertEquals(0, em.getActiveEntityCount()); Entity e = world.createEntity(); assertEquals(0, em.getActiveEntityCount()); e.deleteFromWorld(); assertEquals(0, em.getActiveEntityCount()); world.process(); assertEquals(0, em.getActiveEntityCount()); e = world.createEntity(); world.process(); assertEquals(1, em.getActiveEntityCount()); e.deleteFromWorld(); assertEquals(1, em.getActiveEntityCount()); world.process(); assertEquals(0, em.getActiveEntityCount()); }
@Override public void render(float delta) { Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); camera.update(); world.setDelta(delta); world.process(); mapRenderSystem.process(); spriteRenderSystem.process(); hudRenderSystem.process(); }
@Test public void should_recycle_entities_after_one_round() { ComponentMapper<ComponentX> mapper = world.getMapper(ComponentX.class); Entity e1 = world.createEntity(); e1.edit().add(new ComponentX()); assertTrue(mapper.has(e1)); int id1 = e1.getId(); e1.deleteFromWorld(); world.process(); Entity e2 = world.createEntity(); assertEquals(id1, e2.getId()); assertFalse("Error:" + mapper.getSafe(e2), mapper.has(e2)); }
@Override public void update(GameContainer container, int delta) throws SlickException { world.setDelta(delta); world.process(); }
@Override public void render(float delta) { world.setDelta(delta); world.process(); }
public void Update(float delta) { if (m_FadeIn < 1) { m_FadeIn += delta / 10; m_BackgroundMusic.setVolume(m_GameScreen.m_Settings.m_BackgroundMusicVolume * m_FadeIn); } // update and render the tilemap m_TiledMapRenderer.setView(m_GameScreen.m_Camera); m_TiledMapRenderer.render(); // update physics system m_PhysicsWorld.step(1f / 60f, 6, 2); // update and render the artemis entity system m_ArtemisWorld.setDelta(delta); m_ArtemisWorld.process(); m_SpineRenderSystem.process(); m_GameScreen.m_Camera.update(); m_GameScreen.GetSpriteBatch().setProjectionMatrix(m_GameScreen.m_Camera.combined); // update the player's light distance from watch float distance = 225; if (!m_WatchSpine.m_State.getAnimation().getName().contentEquals("tick")) { m_ClockTicking = false; } if (m_WatchSpine.m_State.getAnimation().getName().contentEquals("tick")) { if (!m_ClockTicking) { m_ClockTick.play(m_GameScreen.m_Settings.m_GameSoundVolume / 2); m_ClockTicking = true; } float time = m_WatchSpine.m_State.getTime(); if (time < 10.0f) { float timePercentageComplete = (10 - time) / 10.0f; distance += (timePercentageComplete * 300); m_LightPowerDistance = timePercentageComplete * 300; } } else if (m_WatchSpine.m_State.getAnimation().getName().contentEquals("wind")) { float time = m_WatchSpine.m_State.getTime(); float timePercentageComplete = time / m_WatchSpine.m_State.getAnimation().getDuration(); distance += (timePercentageComplete * 300); m_LightPowerDistance = timePercentageComplete * 300; } // update the players light distance sensor m_PlayerEntity .m_LightDistanceSensor .getShape() .setRadius((m_LightPowerDistance * WORLD_TO_BOX) / 2); if (m_PlayerEntity.m_Entity != null) { BodyComponent bodyComponent = m_PlayerEntity.m_Entity.getComponent(BodyComponent.class); if (bodyComponent != null) { bodyComponent.m_Light.setDistance(distance * WORLD_TO_BOX); } } // render the lighting m_RayHandler.setCombinedMatrix(m_GameScreen.m_Camera.combined.scl(BOX_TO_WORLD)); m_RayHandler.updateAndRender(); // draw border m_BorderSprite.setColor(1, 1, 1, m_FadeIn * 0.5f); m_BorderSprite.setPosition( m_GameScreen.m_Camera.position.x - 400, m_GameScreen.m_Camera.position.y - 300); m_GameScreen.GetSpriteBatch().begin(); m_BorderSprite.draw(m_GameScreen.GetSpriteBatch()); m_GameScreen.GetSpriteBatch().end(); // draw the vials m_VialOne.m_Skeleton.getColor().set(1, 1, 1, m_FadeIn * 0.75f); m_VialOne.m_Skeleton.setX(m_GameScreen.m_Camera.position.x - 375); m_VialOne.m_Skeleton.setY(m_GameScreen.m_Camera.position.y - 275); m_VialOne.m_Skeleton.getRootBone().setRotation(m_VialOne.m_Rotation); m_VialOne.m_State.update(Gdx.graphics.getDeltaTime()); m_VialOne.m_State.apply(m_VialOne.m_Skeleton); m_VialOne.m_Skeleton.updateWorldTransform(); m_VialTwo.m_Skeleton.getColor().set(1, 1, 1, m_FadeIn * 0.75f); m_VialTwo.m_Skeleton.setX(m_GameScreen.m_Camera.position.x - 305); m_VialTwo.m_Skeleton.setY(m_GameScreen.m_Camera.position.y - 275); m_VialTwo.m_Skeleton.getRootBone().setRotation(m_VialTwo.m_Rotation); m_VialTwo.m_State.update(Gdx.graphics.getDeltaTime()); m_VialTwo.m_State.apply(m_VialTwo.m_Skeleton); m_VialTwo.m_Skeleton.updateWorldTransform(); m_VialThree.m_Skeleton.getColor().set(1, 1, 1, m_FadeIn * 0.75f); m_VialThree.m_Skeleton.setX(m_GameScreen.m_Camera.position.x - 390); m_VialThree.m_Skeleton.setY(m_GameScreen.m_Camera.position.y - 205); m_VialThree.m_Skeleton.getRootBone().setRotation(m_VialThree.m_Rotation); m_VialThree.m_State.update(Gdx.graphics.getDeltaTime()); m_VialThree.m_State.apply(m_VialThree.m_Skeleton); m_VialThree.m_Skeleton.updateWorldTransform(); // draw watch last m_WatchSpine.m_Skeleton.setX(m_GameScreen.m_Camera.position.x + 300); m_WatchSpine.m_Skeleton.setY(m_GameScreen.m_Camera.position.y + 200); m_WatchSpine.m_State.update(Gdx.graphics.getDeltaTime()); m_WatchSpine.m_State.apply(m_WatchSpine.m_Skeleton); m_WatchSpine.m_Skeleton.updateWorldTransform(); m_GameScreen.GetSpriteBatch().begin(); m_SpineRenderSystem.m_Renderer.draw(m_GameScreen.GetSpriteBatch(), m_VialOne.m_Skeleton); m_SpineRenderSystem.m_Renderer.draw(m_GameScreen.GetSpriteBatch(), m_VialTwo.m_Skeleton); m_SpineRenderSystem.m_Renderer.draw(m_GameScreen.GetSpriteBatch(), m_VialThree.m_Skeleton); m_SpineRenderSystem.m_Renderer.draw(m_GameScreen.GetSpriteBatch(), m_WatchSpine.m_Skeleton); m_GameScreen.GetSpriteBatch().end(); }