package sagittarius.view; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.scenes.scene2d.Group; import sagittarius.model.*; public class GameScreen extends BaseScreen { // ---------- ATTRIBUTEs ---------- // Cursors public static Vector2 screenCursor; private static Vector3 unprojectedCursor; public static Vector2 worldCursor; // Groups // TODO: move this in SagittariusGame ? public static Group attractors; public static Group arrows; public static Group players; // Constants public static float G = 100; public static int playerTurn; // ---------- METHODs ---------- @Override public void initialize() { // planets & moons attractors = new Group(); Planet planet1 = new Planet(new Vector2(400, 400), 1000, 50, Color.BLUE); attractors.addActor(planet1); Planet planet2 = new Planet(new Vector2(1400, 700), 1000, 100, Color.ORANGE); attractors.addActor(planet2); Moon moon2_1 = new Moon(planet2, 100, 10, 300, Color.MAGENTA); attractors.addActor(moon2_1); mainStage.addActor(attractors); // players players = new Group(); Player player1 = new Player(planet1, Color.WHITE); players.addActor(player1); Player player2 = new Player(planet2, Color.WHITE); players.addActor(player2); mainStage.addActor(players); // arrows arrows = new Group(); mainStage.addActor(arrows); // The one and only Bow Bow bow = new Bow(true); mainStage.addActor(bow); // others FPS fpsCounter = new FPS(uiStage); uiStage.addActor(fpsCounter); MouseInfo mouseInfo = new MouseInfo(); uiStage.addActor(mouseInfo); mainStage.setDebugAll(true); // TODO: disable later uiStage.setDebugAll(true); // TODO: disable later // game turns playerTurn = 0; player1.setActive(true); Bow.changeShooter(player1); } @Override public void update(float dt) { screenCursor = new Vector2(Gdx.input.getX(), Gdx.input.getY()); unprojectedCursor = mainStage.getCamera().unproject(new Vector3(screenCursor, 0)); worldCursor = new Vector2(unprojectedCursor.x, unprojectedCursor.y); // Player actualPlayer = (Player) players.getChild(playerTurn); // if (actualPlayer.isActive()) { // actualPlayer.setActive(true); // playerTurn++; // playerTurn %= players.getChildren().size; // actualPlayer = (Player) players.getChild(playerTurn); // actualPlayer.setActive(false); // } } public static Player nextTurn() { ((Player) players.getChild(playerTurn++)).setActive(false); if ( playerTurn % players.getChildren().size == 0 ) { playerTurn = 0; } Player newPlayer = (Player) players.getChild(playerTurn); newPlayer.setActive(true); return newPlayer; } // public void removePlayer(Player player) { // int index = players.getChildren().indexOf(player, true); // if (index < playerTurn) { // players.removeActor(player); // playerTurn++; // playerTurn %= players.getChildren().size; // } else if (index == playerTurn) { // players.removeActor(player); // playerTurn %= players.getChildren().size; // Player actualPlayer = (Player) players.getChild(playerTurn); // actualPlayer.setActive(true); // } else { // players.removeActor(player); // } // } }