com.badlogic.gdx.ai.msg.MessageManager Java Examples
The following examples show how to use
com.badlogic.gdx.ai.msg.MessageManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GameEngine.java From GdxDemo3D with Apache License 2.0 | 6 votes |
public void update(float deltaTime) { // Update AI time GdxAI.getTimepiece().update(deltaTime); // Dispatch delayed messages MessageManager.getInstance().update(); // Update Bullet simulation // On default fixedTimeStep = 1/60, small objects (the stick) will fall through // the ground (the ground has relatively big triangles). dynamicsWorld.stepSimulation(deltaTime, 10, 1f / 240f); for (GameObject object : objectsById.values()) { if (object != null) { object.update(deltaTime); } } }
Example #2
Source File: LevelScreen.java From ninja-rabbit with GNU General Public License v2.0 | 6 votes |
@Override public void render(final float delta) { accumulator += Math.min(delta, 0.25f); while (accumulator >= TIME_STEP) { world.step(TIME_STEP, VELOCITY_ITERATIONS, POSITION_ITERATIONS); accumulator -= TIME_STEP; } ninjaRabbit.update(viewport.getCamera()); viewport.getCamera().update(); game.getBatch().setProjectionMatrix(viewport.getCamera().combined); environment.update(viewport.getCamera()); game.getBatch().begin(); ninjaRabbit.step(game.getBatch()); environment.step(game.getBatch()); game.getBatch().end(); MessageManager.getInstance().update(delta); hud.render(); }
Example #3
Source File: NinjaRabbitInputProcessor.java From ninja-rabbit with GNU General Public License v2.0 | 6 votes |
@Override public boolean keyDown(final int keycode) { switch (keycode) { case JUMP_KEY: character.changeState(NinjaRabbitState.JUMP); break; case LEFT_KEY: character.changeState(NinjaRabbitState.LEFT); break; case RIGHT_KEY: character.changeState(NinjaRabbitState.RIGHT); break; case DUCK_KEY: // character.execute(NinjaRabbit.DUCK); break; case RESET_KEY: MessageManager.getInstance().dispatchMessage(null, MessageType.DEAD.code(), character); break; default: break; } return super.keyDown(keycode); }
Example #4
Source File: HumanCharacter.java From GdxDemo3D with Apache License 2.0 | 6 votes |
@Override public void update(HumanCharacter entity) { if (entity.isMoving()) { // Keep on updating movement animation updateAnimation(entity); } else { GameScreen.screen.sounds.whistle.play(); // If the entity owns a dog send it a delayed message to emulate reaction time if (entity.dog != null) { MessageManager.getInstance().dispatchMessage(MathUtils.randomTriangular(.8f, 2f, 1.2f), null, entity.dog, Constants.MSG_DOG_LETS_PLAY); } // Transition to the appropriate idle state depending on the previous state HumanState previousState = entity.stateMachine.getPreviousState(); HumanState nextState = HumanState.IDLE_STAND; if (previousState != null) { if (previousState.isMovementState()) { nextState = previousState.idleState; } else if (previousState.isIdleState()) { nextState = previousState; } } entity.stateMachine.changeState(nextState); } }
Example #5
Source File: HumanCharacter.java From GdxDemo3D with Apache License 2.0 | 6 votes |
@Override public void enter(HumanCharacter entity) { // Turn off animation entity.animations.setAnimation("armature|idle_stand", -1); entity.animations.paused = true; // Stop steering and let friction and gravity arrest the entity entity.stopSteering(false); // Set ragdoll control entity.setRagdollControl(true); // Dog owners inform the dog of the death and clear dog button if (entity.dog != null) { MessageManager.getInstance().dispatchMessage(MathUtils.randomTriangular(.8f, 2f, 1.2f), null, entity.dog, Constants.MSG_DOG_HUMAN_IS_DEAD); MessageManager.getInstance().dispatchMessage(Constants.MSG_GUI_CLEAR_DOG_BUTTON, entity); } }
Example #6
Source File: HumanCharacter.java From GdxDemo3D with Apache License 2.0 | 6 votes |
protected void prepareToMove(HumanCharacter entity, float steeringMultiplier) { entity.moveState = this; // Apply the multiplier to steering limits entity.setMaxLinearSpeed(HumanSteerSettings.maxLinearSpeed * steeringMultiplier); entity.setMaxLinearAcceleration(HumanSteerSettings.maxLinearAcceleration * steeringMultiplier); entity.setMaxAngularSpeed(HumanSteerSettings.maxAngularSpeed * steeringMultiplier); entity.setMaxAngularAcceleration(HumanSteerSettings.maxAngularAcceleration * steeringMultiplier); entity.followPathSteerer.followPathSB.setDecelerationRadius(HumanSteerSettings.decelerationRadius * steeringMultiplier); // If the entity owns a dog tell him you don't want to play and re-enable whistle if (entity.dog != null) { MessageManager.getInstance().dispatchMessage(MathUtils.randomTriangular(.8f, 2f, 1.2f), null, entity.dog, Constants.MSG_DOG_LETS_STOP_PLAYING); MessageManager.getInstance().dispatchMessage(Constants.MSG_GUI_SET_DOG_BUTTON_TO_WHISTLE, entity); } }
Example #7
Source File: StateMachineTest.java From gdx-ai with Apache License 2.0 | 6 votes |
@Override public void render () { float delta = Gdx.graphics.getDeltaTime(); elapsedTime += delta; // Update time GdxAI.getTimepiece().update(delta); if (elapsedTime > 0.8f) { // Update Bob and his wife bob.update(elapsedTime); elsa.update(elapsedTime); // Dispatch any delayed messages MessageManager.getInstance().update(); elapsedTime = 0; } }
Example #8
Source File: GameStage.java From GdxDemo3D with Apache License 2.0 | 6 votes |
public CharacterController(TextureAtlas buttonAtlas) { whistleButton = new CharacterButton(HumanState.WHISTLE, buttonAtlas, "whistle-up", "whistle-down", "whistle-down"); throwButton = new CharacterButton(HumanState.THROW, buttonAtlas, "throw-up", "throw-down", "throw-down"); radioGroup = new ButtonGroup<CharacterButton>( new CharacterButton(HumanState.MOVE_RUN, buttonAtlas, "run-up", "run-down", "run-down"), new CharacterButton(HumanState.MOVE_WALK, buttonAtlas, "walk-up", "walk-down", "walk-down"), new CharacterButton(HumanState.MOVE_CROUCH, buttonAtlas, "crouch-up", "crouch-down", "crouch-down"), //new CharacterButton(CharacterState.MOVE_CRAWL, buttonAtlas, "crawl-up", "crawl-down", "crawl-down"), new CharacterButton(HumanState.DEAD, buttonAtlas, "kill-up", "kill-down", "kill-down") ); // Add whistle button and save the reference to the 1st cell this.dogCell = add(whistleButton); // Add radio buttons for (CharacterButton btn : radioGroup.getButtons()) { add(btn); } // Register this controller's interests MessageManager.getInstance().addListeners(this, Constants.MSG_GUI_CLEAR_DOG_BUTTON, Constants.MSG_GUI_SET_DOG_BUTTON_TO_WHISTLE, Constants.MSG_GUI_SET_DOG_BUTTON_TO_THROW); }
Example #9
Source File: NinjaRabbitInputProcessor.java From ninja-rabbit with GNU General Public License v2.0 | 5 votes |
public NinjaRabbitInputProcessor(final Entity ninjaRabbit) { if (ninjaRabbit == null) { throw new IllegalArgumentException("'character' cannot be null"); } this.character = ninjaRabbit; MessageManager.getInstance().addListener(this, MessageType.EXIT.code()); }
Example #10
Source File: NinjaRabbitControllerProcessor.java From ninja-rabbit with GNU General Public License v2.0 | 5 votes |
@Override public boolean buttonDown(final Controller controller, final int buttonCode) { if (buttonCode == JUMP_KEY) { character.changeState(NinjaRabbitState.JUMP); } else if (buttonCode == RESET_KEY) { MessageManager.getInstance().dispatchMessage(null, MessageType.DEAD.code(), character); } return super.buttonDown(controller, buttonCode); }
Example #11
Source File: CarrotPhysicsProcessor.java From ninja-rabbit with GNU General Public License v2.0 | 5 votes |
/** * @param contact */ private void collectCarrot(final Fixture fixture) { Collectible carrot = (Collectible) fixture.getBody().getUserData(); if (!carrot.isCollected()) { carrot.setCollected(true); MessageManager.getInstance().dispatchMessage(null, MessageType.COLLECTED.code(), carrot); } }
Example #12
Source File: TelegramProviderTest.java From gdx-ai with Apache License 2.0 | 5 votes |
@Override public void create () { super.create(); MessageManager.getInstance().clear(); elapsedTime = 0; // build a new city city = new City(); }
Example #13
Source File: TelegramProviderTest.java From gdx-ai with Apache License 2.0 | 5 votes |
@Override public void update () { elapsedTime += GdxAI.getTimepiece().getDeltaTime(); if (elapsedTime > 1.5f) { MessageManager.getInstance().dispatchMessage(null, MSG_TIME_TO_ACT); elapsedTime = 0; } }
Example #14
Source File: TelegramProviderTest.java From gdx-ai with Apache License 2.0 | 5 votes |
public House (City city) { this.id = city.houses.size + 1; citizens = new Array<Citizen>(); Gdx.app.log(toString(), "New house in town"); // Mr & Mrs citizens.add(new Citizen(this)); citizens.add(new Citizen(this)); MessageManager.getInstance().addListeners(this, TelegramProviderTest.MSG_TIME_TO_ACT); }
Example #15
Source File: TelegramProviderTest.java From gdx-ai with Apache License 2.0 | 5 votes |
public Citizen (House house) { this.id = house.citizens.size + 1; this.house = house; Gdx.app.log(toString(), "Hi there, I'm new in town and I live in house number " + house.id); MessageManager.getInstance().addListener(this, TelegramProviderTest.MSG_EXISTING_CITIZEN); MessageManager.getInstance().addProvider(this, TelegramProviderTest.MSG_EXISTING_CITIZEN); }
Example #16
Source File: BulletJumpTest.java From gdx-ai with Apache License 2.0 | 5 votes |
@Override public void update () { MessageManager.getInstance().update(); character.update(GdxAI.getTimepiece().getDeltaTime()); super.update(); }
Example #17
Source File: InterruptibleFlatTiledAStarTest.java From gdx-ai with Apache License 2.0 | 5 votes |
@Override public void dispose () { renderer.dispose(); worldMap = null; activePath = null; workPath = null; heuristic = null; pathFinder = null; pathSmoother = null; scheduler = null; MessageManager.getInstance().clear(); }
Example #18
Source File: InterruptibleHierarchicalTiledAStarTest.java From gdx-ai with Apache License 2.0 | 5 votes |
@Override public void dispose () { renderer.dispose(); worldMap = null; paths = null; heuristic = null; pathFinder = null; pathSmoother = null; scheduler = null; MessageManager.getInstance().clear(); }
Example #19
Source File: InterruptibleHierarchicalTiledAStarTest.java From gdx-ai with Apache License 2.0 | 5 votes |
private void requestNewPathFinding (HierarchicalTiledNode startNode, HierarchicalTiledNode endNode, int pathIndex) { TiledSmoothableGraphPath<HierarchicalTiledNode> path = paths[pathIndex]; MyPathFinderRequest pfRequest = requestPool.obtain(); pfRequest.startNode = startNode; pfRequest.endNode = endNode; pfRequest.heuristic = heuristic; pfRequest.resultPath = path; pfRequest.pathIndex = pathIndex; pfRequest.responseMessageCode = PF_RESPONSE; MessageManager.getInstance().dispatchMessage(this, PF_REQUEST, pfRequest); }
Example #20
Source File: NinjaRabbitGame.java From ninja-rabbit with GNU General Public License v2.0 | 5 votes |
/** * Clears all remaining messages and listeners in the {@link MessageManager} instance and * re-adds the ones from related to this {@link Telegraph}. */ private void addListeners() { MessageManager manager = MessageManager.getInstance(); manager.clear(); manager.addListeners(this, MessageType.GAME_OVER.code(), MessageType.RESET.code(), MessageType.BEGIN_LEVEL.code()); }
Example #21
Source File: SetThrowButtonTask.java From GdxDemo3D with Apache License 2.0 | 5 votes |
@Override public Status execute () { DogCharacter dog = getObject(); HumanCharacter human = dog.human; if (human.selected && dog.humanWantToPlay) { int msg = enabled ? Constants.MSG_GUI_SET_DOG_BUTTON_TO_THROW : Constants.MSG_GUI_CLEAR_DOG_BUTTON; boolean sendTelegram = enabled && dog.humanWantToPlay && !dog.stickThrown; if (!enabled) sendTelegram = dog.humanWantToPlay && dog.stickThrown; if (sendTelegram) { MessageManager.getInstance().dispatchMessage(msg, human); } } return Status.SUCCEEDED; }
Example #22
Source File: DogCharacter.java From GdxDemo3D with Apache License 2.0 | 5 votes |
@Override public boolean handleMessage(Telegram telegram) { switch (telegram.message) { case Constants.MSG_DOG_LETS_PLAY: humanWantToPlay = true; stickThrown = false; break; case Constants.MSG_DOG_LETS_STOP_PLAYING: humanWantToPlay = false; break; case Constants.MSG_DOG_HUMAN_IS_DEAD: humanIsDead = true; humanWantToPlay = false; alreadyCriedForHumanDeath = false; break; case Constants.MSG_DOG_HUMAN_IS_RESURRECTED: humanIsDead = false; alreadyCriedForHumanDeath = false; break; case Constants.MSG_DOG_STICK_THROWN: stickThrown = true; break; } // Update GUI buttons if the dog's owner is selected if (this.human != null && this.human.selected) { MessageManager.getInstance().dispatchMessage(Constants.MSG_GUI_UPDATE_DOG_BUTTON, this.human); } return true; }
Example #23
Source File: LevelPlayerStatusProcessor.java From ninja-rabbit with GNU General Public License v2.0 | 5 votes |
@Override public boolean handleMessage(final Telegram msg) { getStatus().setLevel((byte) (getStatus().getLevel() + 1)); getStatus().setTime(PlayerStatus.DEFAULT_TIME); MessageManager.getInstance().dispatchMessage(this, MessageType.BEGIN_LEVEL.code()); return true; }
Example #24
Source File: LevelPlayerStatusProcessor.java From ninja-rabbit with GNU General Public License v2.0 | 5 votes |
@Override protected void doUpdate(final Entity entity) { // No time or lives left: game over if (getStatus().getTime() < 0 || getStatus().getLives() < 1 && !gameOverSignaled) { MessageManager.getInstance().dispatchMessage(this, MessageType.GAME_OVER.code()); gameOverSignaled = true; } }
Example #25
Source File: HumanCharacter.java From GdxDemo3D with Apache License 2.0 | 5 votes |
@Override public void enter(HumanCharacter entity) { // Stop steering and let friction and gravity arrest the entity entity.stopSteering(false); HumanState prevState = entity.stateMachine.getPreviousState(); if (prevState != null && prevState.isMovementState()) { // Save animation speed multiplier entity.animationSpeedMultiplier = prevState.animationMultiplier; } MessageManager.getInstance().dispatchMessage(Constants.MSG_GUI_CLEAR_DOG_BUTTON, entity); }
Example #26
Source File: HumanCharacter.java From GdxDemo3D with Apache License 2.0 | 5 votes |
@Override public void exit(HumanCharacter entity) { entity.animations.paused = false; entity.setRagdollControl(false); // Dog owners inform the dog of the resurrection and enable whistle button if (entity.dog != null) { MessageManager.getInstance().dispatchMessage(MathUtils.randomTriangular(.8f, 1.5f), null, entity.dog, Constants.MSG_DOG_HUMAN_IS_RESURRECTED); MessageManager.getInstance().dispatchMessage(Constants.MSG_GUI_SET_DOG_BUTTON_TO_WHISTLE, entity); } }
Example #27
Source File: HumanCharacter.java From GdxDemo3D with Apache License 2.0 | 5 votes |
public void onStickLanded() { stick.hasLanded = true; // If the entity owns a dog send it a delayed message to emulate reaction time if (dog != null) { MessageManager.getInstance().dispatchMessage(MathUtils.randomTriangular(.3f, 1.2f, .6f), null, dog, Constants.MSG_DOG_STICK_THROWN); } }
Example #28
Source File: PathFinderRequest.java From gdx-ai with Apache License 2.0 | 4 votes |
/** Creates a {@code PathFinderRequest} with the given arguments that uses the singleton message dispatcher provided by * {@link MessageManager}. */ public PathFinderRequest (N startNode, N endNode, Heuristic<N> heuristic, GraphPath<N> resultPath) { this(startNode, endNode, heuristic, resultPath, MessageManager.getInstance()); }
Example #29
Source File: InterruptibleFlatTiledAStarTest.java From gdx-ai with Apache License 2.0 | 4 votes |
private void updatePath (boolean forceUpdate) { getCamera().unproject(tmpUnprojection.set(lastScreenX, lastScreenY, 0)); int tileX = (int)(tmpUnprojection.x / width); int tileY = (int)(tmpUnprojection.y / width); if (forceUpdate || tileX != lastEndTileX || tileY != lastEndTileY) { final FlatTiledNode startNode = worldMap.getNode(startTileX, startTileY); FlatTiledNode endNode = worldMap.getNode(tileX, tileY); if (forceUpdate || endNode.type == TiledNode.TILE_FLOOR) { if (endNode.type == TiledNode.TILE_FLOOR) { lastEndTileX = tileX; lastEndTileY = tileY; } else { endNode = worldMap.getNode(lastEndTileX, lastEndTileY); } MyPathFinderRequest pfRequest = requestPool.obtain(); pfRequest.startNode = startNode; pfRequest.endNode = endNode; pfRequest.heuristic = heuristic; pfRequest.responseMessageCode = PF_RESPONSE; MessageManager.getInstance().dispatchMessage(this, PF_REQUEST, pfRequest); // worldMap.startNode = startNode; // long startTime = nanoTime(); // pathFinder.searchNodePath(startNode, endNode, heuristic, path); // if (pathFinder.metrics != null) { // float elapsed = (TimeUtils.nanoTime() - startTime) / 1000000f; // System.out.println("----------------- Indexed A* Path Finder Metrics -----------------"); // System.out.println("Visited nodes................... = " + pathFinder.metrics.visitedNodes); // System.out.println("Open list additions............. = " + pathFinder.metrics.openListAdditions); // System.out.println("Open list peak.................. = " + pathFinder.metrics.openListPeak); // System.out.println("Path finding elapsed time (ms).. = " + elapsed); // } // if (smooth) { // startTime = nanoTime(); // pathSmoother.smoothPath(path); // if (pathFinder.metrics != null) { // float elapsed = (TimeUtils.nanoTime() - startTime) / 1000000f; // System.out.println("Path smoothing elapsed time (ms) = " + elapsed); // } // } } } }
Example #30
Source File: BulletJumpTest.java From gdx-ai with Apache License 2.0 | 4 votes |
@Override public void dispose () { super.dispose(); shapeRenderer.dispose(); MessageManager.getInstance().clear(); }