/** * Move object to free point or follow for target * * @param newX - target position x * @param newY - target position y * @param target - target */ private void moveToPoint(float newX, float newY, SuperFigure target) { String command; if (target == null) { command = "MovM"; } else { command = "FolM"; } messageText = "From" + 1 + command + (int) newX + "-" + (int) newY + ":"; Boolean isFirst = true; for (Mob mob : mobs) { if (mob.getIsSelected()) { if (isFirst) { messageText += mob.getID(); isFirst = false; } else { messageText += "," + mob.getID(); } float k = (newX - mob.getFigure().x) / Math.abs(newY - mob.getFigure().y); mob.setStepX(k); mob.setStepY(newY - mob.getFigure().y > 0 ? 1 : -1); mob.setIsSelected(false); mob.setNewX(newX); mob.setNewY(newY); mob.setTarget(target); mob.setIsMove(true); } } if (target == null) { command = "MovP"; } else { command = "FolP"; } messageText = "From" + 1 + command + (int) newX + "-" + (int) newY + ":"; for (Planet mob : planets) { if (mob.getIsSelected()) { if (isFirst) { messageText += mob.getID(); isFirst = false; } else { messageText += "," + mob.getID(); } float k = (newX - mob.getFigure().x) / Math.abs(newY - mob.getFigure().y); mob.setStepX(k); mob.setStepY(newY - mob.getFigure().y > 0 ? 1 : -1); mob.setIsSelected(false); mob.setNewX(newX); mob.setNewY(newY); mob.setTarget(target); mob.setIsMove(true); } } System.out.println(messageText); }
/** * Click on game field * * @param screenX - screen position click X * @param screenY - screen position click Y */ public void clickOnWorld(int screenX, int screenY) { screenY = (int) (game.getScreenHeight() - screenY); Circle helpCircle = new Circle(screenX, screenY, 1); if (checkOnTouch(helpCircle) == null && isSelected) { moveToPoint(screenX, screenY, null); } else if (checkOnTouch(helpCircle) instanceof Planet) { Planet planet = (Planet) checkOnTouch(helpCircle); if (planet.getHostName().equals(playerName)) { isSelected = true; planet.setIsSelected(true); } else { moveToPoint(planet.getFigure().x, planet.getFigure().y, planet); } } else if (checkOnTouch(helpCircle) instanceof Mob) { Mob mob = (Mob) checkOnTouch(helpCircle); if (mob.getHostName().equals(playerName)) { isSelected = true; mob.setIsSelected(true); } else { moveToPoint(mob.getFigure().x, mob.getFigure().y, mob); } } }