private void updateMoveString() { Move move = createMove(); String message = ""; if (placedTiles.size() > 0) { message = "Invalid Move"; } if (move != null) { MoveResult result = game.getMoveEngine().testMove(game.getBoard(), move); if (result != null) { message = result.toString(); } } setStatusMessage(message); }
private void walk( final CharacterMovementComponent movementComp, final CharacterStateEvent state, CharacterMoveInputEvent input, EntityRef entity) { Vector3f desiredVelocity = new Vector3f(input.getMovementDirection()); float lengthSquared = desiredVelocity.lengthSquared(); // If the length of desired movement is > 1, normalise it to prevent movement being faster than // allowed. // (Desired velocity < 1 is allowed, as the character may wish to walk/crawl/otherwise move // slowly) if (lengthSquared > 1) { desiredVelocity.normalize(); } desiredVelocity.scale(movementComp.speedMultiplier); float maxSpeed = getMaxSpeed(entity, movementComp); if (input.isRunning()) { maxSpeed *= movementComp.runFactor; } // As we can't use it, remove the y component of desired movement while maintaining speed. if (movementComp.grounded && desiredVelocity.y != 0) { float speed = desiredVelocity.length(); desiredVelocity.y = 0; if (desiredVelocity.x != 0 || desiredVelocity.z != 0) { desiredVelocity.normalize(); desiredVelocity.scale(speed); } } desiredVelocity.scale(maxSpeed); if (movementComp.mode == MovementMode.CLIMBING) { climb(state, input, desiredVelocity); } // Modify velocity towards desired, up to the maximum rate determined by friction Vector3f velocityDiff = new Vector3f(desiredVelocity); velocityDiff.sub(state.getVelocity()); velocityDiff.scale(Math.min(movementComp.mode.scaleInertia * input.getDelta(), 1.0f)); Vector3f endVelocity = new Vector3f(state.getVelocity()); endVelocity.x += velocityDiff.x; endVelocity.z += velocityDiff.z; if (movementComp.mode.scaleGravity == 0) { // apply the velocity without gravity endVelocity.y += velocityDiff.y; } else if (movementComp.mode.applyInertiaToVertical) { endVelocity.y += Math.max( -TERMINAL_VELOCITY, velocityDiff.y - (GRAVITY * movementComp.mode.scaleGravity) * input.getDelta()); } else { endVelocity.y = Math.max( -TERMINAL_VELOCITY, state.getVelocity().y - (GRAVITY * movementComp.mode.scaleGravity) * input.getDelta()); } Vector3f moveDelta = new Vector3f(endVelocity); moveDelta.scale(input.getDelta()); CharacterCollider collider = movementComp.mode.useCollision ? physics.getCharacterCollider(entity) : null; MoveResult moveResult = move( state.getPosition(), moveDelta, (state.getMode() != MovementMode.CLIMBING && state.isGrounded() && movementComp.mode.canBeGrounded) ? movementComp.stepHeight : 0, movementComp.slopeFactor, collider); Vector3f distanceMoved = new Vector3f(moveResult.getFinalPosition()); distanceMoved.sub(state.getPosition()); state.getPosition().set(moveResult.getFinalPosition()); if (input.isFirstRun() && distanceMoved.length() > 0) { entity.send(new MovedEvent(distanceMoved, state.getPosition())); } if (moveResult.isBottomHit()) { if (!state.isGrounded() && movementComp.mode.canBeGrounded) { if (input.isFirstRun()) { Vector3f landVelocity = new Vector3f(state.getVelocity()); landVelocity.y += (distanceMoved.y / moveDelta.y) * (endVelocity.y - state.getVelocity().y); logger.debug("Landed at " + landVelocity); entity.send(new VerticalCollisionEvent(state.getPosition(), landVelocity)); } state.setGrounded(true); } endVelocity.y = 0; // Jumping is only possible, if the entity is standing on ground if (input.isJumpRequested()) { state.setGrounded(false); endVelocity.y += movementComp.jumpSpeed; if (input.isFirstRun()) { entity.send(new JumpEvent()); } } } else { if (moveResult.isTopHit() && endVelocity.y > 0) { endVelocity.y = -0.5f * endVelocity.y; } state.setGrounded(false); } state.getVelocity().set(endVelocity); if (input.isFirstRun() && moveResult.isHorizontalHit()) { entity.send(new HorizontalCollisionEvent(state.getPosition(), state.getVelocity())); } if (state.isGrounded() || movementComp.mode == MovementMode.SWIMMING || movementComp.mode == MovementMode.DIVING) { state.setFootstepDelta( state.getFootstepDelta() + distanceMoved.length() / movementComp.distanceBetweenFootsteps); if (state.getFootstepDelta() > 1) { state.setFootstepDelta(state.getFootstepDelta() - 1); if (input.isFirstRun()) { switch (movementComp.mode) { case WALKING: entity.send(new FootstepEvent()); break; case DIVING: case SWIMMING: entity.send(new SwimStrokeEvent(worldProvider.getBlock(state.getPosition()))); break; } } } } }
private void drawTile(IBoard b, GC gc, int x, int y, int xo, int yo, int size) { gc.setClipping(xo, yo, size + 1, size + 1); Color c = background; if (b.getLetterMultiplier(y, x) == 2) c = doubleLetter; else if (b.getLetterMultiplier(y, x) == 3) c = tripleLetter; else if (b.getLetterMultiplier(y, x) == 4) c = quadLetter; else if (b.getWordMultiplier(y, x) == 2) c = doubleWord; else if (b.getWordMultiplier(y, x) == 3) c = tripleWord; else if (b.getWordMultiplier(y, x) == 4) c = quadWord; gc.setBackground(c); gc.fillRectangle(xo, yo, size, size); c = light; if (b.getLetterMultiplier(y, x) == 2) c = doubleLetterLight; else if (b.getLetterMultiplier(y, x) == 3) c = tripleLetterLight; else if (b.getLetterMultiplier(y, x) == 4) c = quadLetterLight; else if (b.getWordMultiplier(y, x) == 2) c = doubleWordLight; else if (b.getWordMultiplier(y, x) == 3) c = tripleWordLight; else if (b.getWordMultiplier(y, x) == 4) c = quadWordLight; gc.setForeground(c); gc.drawLine(xo, yo, xo + size, yo); gc.drawLine(xo, yo, xo, yo + size); gc.setForeground(dark); gc.drawLine(xo + size, yo + size, xo + size, yo); gc.drawLine(xo + size, yo + size, xo, yo + size); Tile tile = b.getTile(y, x); if (tile.equals(Tile.NONE)) { for (Iterator i = placedTiles.entrySet().iterator(); i.hasNext(); ) { Map.Entry entry = (Map.Entry) i.next(); Point point = (Point) entry.getKey(); if (point.x == x && point.y == y) { tile = (Tile) entry.getValue(); DragSource source = new DragSource(); source.rectangle = new Rectangle(xo, yo, size + 1, size + 1); source.x = x; source.y = y; source.tile = tile; dragSources.put(source.rectangle, source); } } } boolean highlight = false; IGameAction action = game.getLastAction(); if (action != null && action instanceof MoveAction) { MoveAction moveAction = (MoveAction) action; MoveResult result = moveAction.getMoveResult(); Tile[] tiles = result.getPreviousBoardState(); Move move = result.getMove(); Orientation orientation = move.getOrientation(); int dx = orientation.getDx(); int dy = orientation.getDy(); int mx = move.getColumn(); int my = move.getRow(); for (int i = 0; i < tiles.length; i++) { Tile t = tiles[i]; if (mx == x && my == y && t.equals(Tile.NONE)) { highlight = true; } mx += dx; my += dy; } } drawTile(gc, new Rectangle(xo, yo, size + 1, size + 1), tile, highlight); if (arrow != null && arrow.x == x && arrow.y == y) { drawArrow(gc, xo, yo, size); } }