2021-04-08 19:34:17 +00:00
|
|
|
package sagittarius.view;
|
2021-04-05 16:45:57 +00:00
|
|
|
|
2021-04-09 13:03:24 +00:00
|
|
|
import com.badlogic.gdx.Gdx;
|
2021-04-05 16:45:57 +00:00
|
|
|
import com.badlogic.gdx.graphics.Color;
|
2021-04-09 09:57:52 +00:00
|
|
|
import com.badlogic.gdx.math.Vector2;
|
2021-04-09 13:03:24 +00:00
|
|
|
import com.badlogic.gdx.math.Vector3;
|
2021-04-09 13:49:33 +00:00
|
|
|
import com.badlogic.gdx.scenes.scene2d.Group;
|
2021-04-05 16:45:57 +00:00
|
|
|
|
2021-04-16 11:57:02 +00:00
|
|
|
import sagittarius.SagittariusGame;
|
2021-04-09 09:57:52 +00:00
|
|
|
import sagittarius.model.*;
|
2021-04-05 16:45:57 +00:00
|
|
|
|
2021-04-09 09:57:52 +00:00
|
|
|
public class GameScreen extends BaseScreen {
|
2021-04-05 16:45:57 +00:00
|
|
|
|
2021-04-09 09:57:52 +00:00
|
|
|
// ---------- ATTRIBUTEs ----------
|
2021-04-05 16:45:57 +00:00
|
|
|
|
2021-04-09 13:03:24 +00:00
|
|
|
// Cursors
|
|
|
|
public static Vector2 screenCursor;
|
|
|
|
private static Vector3 unprojectedCursor;
|
|
|
|
public static Vector2 worldCursor;
|
|
|
|
|
2021-04-09 14:45:43 +00:00
|
|
|
// Groups // TODO: move this in SagittariusGame ?
|
2021-04-12 18:45:09 +00:00
|
|
|
public static Group attractors;
|
2021-04-09 14:45:43 +00:00
|
|
|
public static Group arrows;
|
2021-04-13 17:45:49 +00:00
|
|
|
public static Group players;
|
|
|
|
|
2021-04-16 11:43:59 +00:00
|
|
|
public static int playerTurn;
|
2021-04-09 14:28:37 +00:00
|
|
|
|
2021-04-09 09:57:52 +00:00
|
|
|
// ---------- METHODs ----------
|
2021-04-05 16:45:57 +00:00
|
|
|
|
|
|
|
@Override
|
2021-04-09 09:57:52 +00:00
|
|
|
public void initialize() {
|
|
|
|
|
2021-04-12 18:45:09 +00:00
|
|
|
// planets & moons
|
|
|
|
attractors = new Group();
|
2021-04-13 19:24:36 +00:00
|
|
|
|
2021-04-09 13:49:33 +00:00
|
|
|
Planet planet1 = new Planet(new Vector2(400, 400), 1000, 50, Color.BLUE);
|
2021-04-12 18:45:09 +00:00
|
|
|
attractors.addActor(planet1);
|
2021-04-13 19:24:36 +00:00
|
|
|
|
2021-04-09 13:03:24 +00:00
|
|
|
Planet planet2 = new Planet(new Vector2(1400, 700), 1000, 100, Color.ORANGE);
|
2021-04-12 18:45:09 +00:00
|
|
|
attractors.addActor(planet2);
|
2021-04-09 13:03:24 +00:00
|
|
|
|
2021-04-12 18:45:09 +00:00
|
|
|
Moon moon2_1 = new Moon(planet2, 100, 10, 300, Color.MAGENTA);
|
|
|
|
attractors.addActor(moon2_1);
|
|
|
|
|
|
|
|
mainStage.addActor(attractors);
|
2021-04-09 13:49:33 +00:00
|
|
|
|
|
|
|
// players
|
2021-04-13 17:45:49 +00:00
|
|
|
players = new Group();
|
|
|
|
|
2021-04-09 09:57:52 +00:00
|
|
|
Player player1 = new Player(planet1, Color.WHITE);
|
2021-04-13 17:45:49 +00:00
|
|
|
players.addActor(player1);
|
2021-04-09 13:03:24 +00:00
|
|
|
|
2021-04-13 16:43:41 +00:00
|
|
|
Player player2 = new Player(planet2, Color.WHITE);
|
2021-04-13 17:45:49 +00:00
|
|
|
players.addActor(player2);
|
|
|
|
|
|
|
|
mainStage.addActor(players);
|
2021-04-13 16:43:41 +00:00
|
|
|
|
2021-04-09 14:45:43 +00:00
|
|
|
// arrows
|
|
|
|
arrows = new Group();
|
|
|
|
mainStage.addActor(arrows);
|
2021-04-09 13:49:33 +00:00
|
|
|
|
2021-04-13 19:55:14 +00:00
|
|
|
// The one and only Bow
|
2021-04-16 11:43:59 +00:00
|
|
|
Bow bow = new Bow(true);
|
2021-04-13 19:55:14 +00:00
|
|
|
mainStage.addActor(bow);
|
|
|
|
|
2021-04-09 14:45:43 +00:00
|
|
|
// others
|
2021-04-13 19:08:25 +00:00
|
|
|
FPS fpsCounter = new FPS(uiStage);
|
2021-04-09 13:03:24 +00:00
|
|
|
uiStage.addActor(fpsCounter);
|
|
|
|
|
|
|
|
MouseInfo mouseInfo = new MouseInfo();
|
|
|
|
uiStage.addActor(mouseInfo);
|
2021-04-09 13:10:39 +00:00
|
|
|
|
2021-04-16 11:57:02 +00:00
|
|
|
mainStage.setDebugAll(SagittariusGame.debugMode);
|
|
|
|
uiStage.setDebugAll(SagittariusGame.debugMode);
|
2021-04-10 10:22:48 +00:00
|
|
|
|
2021-04-13 19:55:14 +00:00
|
|
|
// game turns
|
|
|
|
playerTurn = 0;
|
2021-04-13 19:57:53 +00:00
|
|
|
player1.setActive(true);
|
2021-04-16 11:43:59 +00:00
|
|
|
Bow.changeShooter(player1);
|
2021-04-13 19:55:14 +00:00
|
|
|
|
2021-04-05 16:45:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-04-09 09:57:52 +00:00
|
|
|
public void update(float dt) {
|
2021-04-09 13:03:24 +00:00
|
|
|
|
|
|
|
screenCursor = new Vector2(Gdx.input.getX(), Gdx.input.getY());
|
|
|
|
unprojectedCursor = mainStage.getCamera().unproject(new Vector3(screenCursor, 0));
|
|
|
|
worldCursor = new Vector2(unprojectedCursor.x, unprojectedCursor.y);
|
|
|
|
|
2021-04-16 11:43:59 +00:00
|
|
|
// 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);
|
|
|
|
// }
|
2021-04-13 17:45:49 +00:00
|
|
|
|
2021-04-05 16:45:57 +00:00
|
|
|
}
|
|
|
|
|
2021-04-16 11:43:59 +00:00
|
|
|
public static Player nextTurn() {
|
|
|
|
((Player) players.getChild(playerTurn++)).setActive(false);
|
|
|
|
if ( playerTurn % players.getChildren().size == 0 ) {
|
|
|
|
playerTurn = 0;
|
2021-04-13 17:45:49 +00:00
|
|
|
}
|
2021-04-16 11:43:59 +00:00
|
|
|
Player newPlayer = (Player) players.getChild(playerTurn);
|
|
|
|
newPlayer.setActive(true);
|
|
|
|
return newPlayer;
|
2021-04-13 17:45:49 +00:00
|
|
|
}
|
2021-04-16 11:43:59 +00:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
// }
|
|
|
|
// }
|
2021-04-13 17:45:49 +00:00
|
|
|
}
|