EnvironmentListener for Maps #734
Replies: 3 comments
-
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022). |
Beta Was this translation helpful? Give feedback.
-
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022). public class Client {
public static void main(String[] args) {
Game.info().setName("TestGame");
Game.info().setSubTitle("");
Game.info().setVersion("1.0.0");
Game.init(args);
Game.graphics().setBaseRenderScale(1.00f);
Game.world().addListener(new EnvironmentListener() {
@Override
public void loaded(Environment environment) {
try {
MapWarpsResponse response = RequestUtils.sendRequest(new MapWarpsRequest(GameResources.getMapId()), MapWarpsResponse.class, new URI("/maps/warps"), "POST");
for (MapWarp mapWarp : response.getMapWarps()) {
Trigger trigger = new Trigger(Trigger.TriggerActivation.COLLISION, pad(mapWarp.getId(), 6));
trigger.addActivatedListener(triggerEvent -> {
try {
// Ask where to Warp
MapWarpResponse warpResponse = RequestUtils.sendRequest(new MapWarpRequest(GameResources.getMapId(), mapWarp.getId()), MapWarpResponse.class, new URI("/maps/warp"), "POST");
// Load Warp Map
Game.world().loadEnvironment(Resources.maps().get("maps/" + pad(warpResponse.getMapId(), 6) + ".tmx"));
// Warp player to new map
Player.instance().setTileLocation(warpResponse.getCoord().getX(), warpResponse.getCoord().getY());
} catch (URISyntaxException e) {
e.printStackTrace();
}
});
trigger.addActivator(Player.instance());
trigger.setLocation(mapWarp.getWarpRect().getX() * TILE_DIM, mapWarp.getWarpRect().getY() * TILE_DIM);
trigger.setWidth(mapWarp.getWarpRect().getWidth() * TILE_DIM);
trigger.setHeight(mapWarp.getWarpRect().getHeight() * TILE_DIM);
Game.world().environment().add(trigger);
}
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
});
// Get Character Spawn
try {
CharacterLoginResponse loginResponse = RequestUtils.sendRequest(new CharacterLoginRequest("HanHa"), CharacterLoginResponse.class, new URI("/characters/login"), "POST");
GameResources.init();
Game.screens().add(new GameScreen());
PlayerLogic.init(loginResponse.getCoordinate());
Game.world().loadEnvironment(Resources.maps().get("maps/" + pad(loginResponse.getMapId(), 6) + ".tmx"));
} catch (URISyntaxException e) {
e.printStackTrace();
}
Game.start();
}
} On client load, I ask a game server where to spawn (at the bottom of the class). Before that, I create an |
Beta Was this translation helpful? Give feedback.
-
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022). |
Beta Was this translation helpful? Give feedback.
-
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022).
Posted: 2020-08-30 17:20:37
User: DizzyThermal [] (age: 798 days 🙌; posts: 7)
I'm trying to implement an ~~
~~EnvironmentListener
for all maps that get loaded.I've tried doing in the main before loading the first map:
When the first map loads, it adds the Triggers that it requests from the server - I can see them in debug mode, but when I try to enter the warp, it doesn't seem to be running the addActivatedListener's triggerEvent. Which needs to load the next map inside.
Is there a better way to do what I'm trying to do?
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions