feat: improved the menus, turn system still broken by me
This commit is contained in:
parent
bcfdc1e5d5
commit
91008f575b
|
@ -56,6 +56,5 @@ project(":core") {
|
|||
dependencies {
|
||||
api "com.badlogicgames.gdx:gdx:$gdxVersion"
|
||||
api "com.kotcrab.vis:vis-ui:1.3.0"
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,14 @@
|
|||
package sagittarius;
|
||||
|
||||
import com.badlogic.gdx.Game;
|
||||
import com.kotcrab.vis.ui.VisUI;
|
||||
|
||||
import sagittarius.view.BaseScreen;
|
||||
import sagittarius.view.GameScreen;
|
||||
import sagittarius.view.StartScreen;
|
||||
|
||||
public class SagittariusGame extends Game {
|
||||
|
||||
// Constants
|
||||
public static final int G = 100;
|
||||
|
||||
// Game
|
||||
public static GameScreen gameScreen;
|
||||
private static SagittariusGame game;
|
||||
private static Game game;
|
||||
|
||||
public SagittariusGame() {
|
||||
game = this;
|
||||
|
@ -26,9 +22,10 @@ public class SagittariusGame extends Game {
|
|||
return (BaseScreen) game.getScreen();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create() {
|
||||
gameScreen = new GameScreen();
|
||||
this.setScreen(gameScreen);
|
||||
}
|
||||
@Override
|
||||
public void create() {
|
||||
VisUI.load();
|
||||
game.setScreen(new StartScreen());
|
||||
}
|
||||
|
||||
}
|
|
@ -6,7 +6,6 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
|||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
|
||||
import sagittarius.SagittariusGame;
|
||||
import sagittarius.view.GameScreen;
|
||||
|
||||
public class Arrow extends BaseActor {
|
||||
|
@ -55,6 +54,7 @@ public class Arrow extends BaseActor {
|
|||
this.TTL -= dt;
|
||||
this.setRotation(this.velocity.angleDeg());
|
||||
verifyLanding();
|
||||
verifyHittingPlayer();
|
||||
|
||||
if (TTL <= 0) {
|
||||
GameScreen.arrows.removeActor(this);
|
||||
|
@ -88,7 +88,7 @@ public class Arrow extends BaseActor {
|
|||
|
||||
float len2 = dx*dx + dy*dy;
|
||||
|
||||
float coeff = SagittariusGame.G * ((Planet) actor).getMass() * (float) Math.pow(len2, -3/2);
|
||||
float coeff = GameScreen.G * ((Planet) actor).getMass() * (float) Math.pow(len2, -3/2);
|
||||
|
||||
float gravityX = coeff * dx;
|
||||
float gravityY = coeff * dy;
|
||||
|
@ -132,13 +132,25 @@ public class Arrow extends BaseActor {
|
|||
landed = true;
|
||||
this.crash = planet;
|
||||
this.offset = this.getPosition().sub( planet.getPosition() );
|
||||
Bow.changeShooter(GameScreen.nextTurn());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void verifyHittingPlayer() {
|
||||
for (Actor actor : GameScreen.players.getChildren()) {
|
||||
|
||||
Player player = (Player) actor;
|
||||
|
||||
if (TTL < 19 && player.hitbox.contains(getX(), getY())) {
|
||||
landed = true;
|
||||
GameScreen.players.removeActor(player);
|
||||
GameScreen.arrows.removeActor(this);
|
||||
Bow.changeShooter(GameScreen.nextTurn());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** // TODO : pass directly an Arrow instead of 3 arguments
|
||||
|
@ -154,6 +166,8 @@ public class Arrow extends BaseActor {
|
|||
Arrow dummyArrow = new Arrow(angle, power, shooter);
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
dummyArrow.integrationVerlet(timeStep);
|
||||
// dummyArrow.verifyLanding();
|
||||
// dummyArrow.verifyHittingPlayer(); // fix -> return booleans, take action after
|
||||
path.add(dummyArrow.getX());
|
||||
path.add(dummyArrow.getY());
|
||||
}
|
||||
|
@ -170,10 +184,6 @@ public class Arrow extends BaseActor {
|
|||
return arr;
|
||||
}
|
||||
|
||||
public Vector2 getPosition() {
|
||||
return new Vector2( getX(), getY() );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getInfo() {
|
||||
return
|
||||
|
|
|
@ -1,22 +1,34 @@
|
|||
package sagittarius.model;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
|
||||
import com.badlogic.gdx.math.Intersector;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.math.Polygon;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
|
||||
public abstract class BaseActor extends Actor {
|
||||
|
||||
// ---------- ATTRIBUTEs ----------
|
||||
|
||||
static private BitmapFont fontDebug = new BitmapFont();
|
||||
|
||||
/**
|
||||
* @return debug String displayed in {@link #draw()}
|
||||
*/
|
||||
protected abstract String getInfo();
|
||||
protected Polygon hitbox = new Polygon(test());
|
||||
|
||||
protected float angle; // encapsulate ?
|
||||
|
||||
// ---------- METHODs ----------
|
||||
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
super.act(delta);
|
||||
hitbox.setVertices(test());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Batch batch, float parentAlpha) {
|
||||
super.draw(batch, parentAlpha);
|
||||
|
@ -28,11 +40,63 @@ public abstract class BaseActor extends Actor {
|
|||
if (!getDebug()) return;
|
||||
shapes.set(ShapeType.Line);
|
||||
if (getStage() != null) shapes.setColor(getStage().getDebugColor());
|
||||
shapes.rect(getX() - getOriginX(), getY() - getOriginY(),
|
||||
getOriginX(), getOriginY(),
|
||||
getWidth(), getHeight(),
|
||||
getScaleX(), getScaleY(),
|
||||
getRotation());
|
||||
// shapes.rect(getX() - getOriginX(), getY() - getOriginY(),
|
||||
// getOriginX(), getOriginY(),
|
||||
// getWidth(), getHeight(),
|
||||
// getScaleX(), getScaleY(),
|
||||
// getRotation());
|
||||
shapes.setColor(Color.RED);
|
||||
shapes.polygon(test());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link ShapeRenderer#rect}
|
||||
* @return vertices of the hitbox polygon
|
||||
*/
|
||||
protected float[] test() { // convert position + rotation and other shit to polygon
|
||||
float cos = MathUtils.cosDeg(getRotation());
|
||||
float sin = MathUtils.sinDeg(getRotation());
|
||||
float fx = -getOriginX();
|
||||
float fy = -getOriginY();
|
||||
float fx2 = getWidth() - getOriginX();
|
||||
float fy2 = getHeight() - getOriginY();
|
||||
|
||||
if (getScaleX() != 1 || getScaleX() != 1) {
|
||||
fx *= getScaleX();
|
||||
fy *= getScaleY();
|
||||
fx2 *= getScaleX();
|
||||
fy2 *= getScaleY();
|
||||
}
|
||||
|
||||
float worldOriginX = getX();
|
||||
float worldOriginY = getY();
|
||||
|
||||
float x1 = cos * fx - sin * fy + worldOriginX;
|
||||
float y1 = sin * fx + cos * fy + worldOriginY;
|
||||
|
||||
float x2 = cos * fx2 - sin * fy + worldOriginX;
|
||||
float y2 = sin * fx2 + cos * fy + worldOriginY;
|
||||
|
||||
float x3 = cos * fx2 - sin * fy2 + worldOriginX;
|
||||
float y3 = sin * fx2 + cos * fy2 + worldOriginY;
|
||||
|
||||
float x4 = x1 + (x3 - x2);
|
||||
float y4 = y3 - (y2 - y1);
|
||||
|
||||
return new float[] { x1, y1, x2, y2, x3, y3, x4, y4 };
|
||||
}
|
||||
|
||||
/**
|
||||
* @return debug String displayed in {@link #draw()}
|
||||
*/
|
||||
protected abstract String getInfo();
|
||||
|
||||
protected boolean overlaps(BaseActor other) {
|
||||
return Intersector.overlapConvexPolygons(hitbox, other.hitbox);
|
||||
}
|
||||
|
||||
public Vector2 getPosition() {
|
||||
return new Vector2( getX(), getY() );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ public class Bow extends Actor {
|
|||
|
||||
// ---------- ATTRIBUTEs ----------
|
||||
|
||||
private Player shooter;
|
||||
private static Player shooter;
|
||||
private boolean aimAssist = false;
|
||||
private boolean pressed = false;
|
||||
private float angle;
|
||||
|
@ -25,9 +25,8 @@ public class Bow extends Actor {
|
|||
|
||||
// ---------- CONSTRUCTORs ----------
|
||||
|
||||
public Bow(Player shooter, boolean aimAssist) {
|
||||
public Bow(boolean aimAssist) {
|
||||
super();
|
||||
this.shooter = shooter;
|
||||
this.aimAssist = aimAssist;
|
||||
}
|
||||
|
||||
|
@ -42,8 +41,8 @@ public class Bow extends Actor {
|
|||
} else if (Gdx.input.isButtonPressed(Buttons.LEFT) && pressed) {
|
||||
computeArrow();
|
||||
} else if (pressed) {
|
||||
GameScreen.arrows.addActor(getArrow());
|
||||
pressed = false;
|
||||
GameScreen.arrows.addActor(getArrow());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,8 +79,8 @@ public class Bow extends Actor {
|
|||
return new Arrow(angle, power, shooter);
|
||||
}
|
||||
|
||||
public void changeShooter(Player newShooter) {
|
||||
this.shooter = newShooter;
|
||||
public static void changeShooter(Player newShooter) {
|
||||
shooter = newShooter;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package sagittarius.model;
|
||||
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
|
||||
import sagittarius.view.GameScreen;
|
||||
|
||||
public class MouseInfo extends BaseActor {
|
||||
|
@ -9,7 +11,7 @@ public class MouseInfo extends BaseActor {
|
|||
@Override
|
||||
public void act(float delta) {
|
||||
super.act(delta);
|
||||
setX(GameScreen.worldCursor.x);
|
||||
setX(GameScreen.worldCursor.x); // use direct method
|
||||
setY(GameScreen.worldCursor.y);
|
||||
}
|
||||
|
||||
|
|
|
@ -46,10 +46,6 @@ public class Planet extends BaseActor {
|
|||
return mass;
|
||||
}
|
||||
|
||||
public Vector2 getPosition() {
|
||||
return new Vector2( getX(), getY() );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getInfo() {
|
||||
return
|
||||
|
|
|
@ -4,8 +4,6 @@ import com.badlogic.gdx.Gdx;
|
|||
import com.badlogic.gdx.graphics.GL30;
|
||||
import com.badlogic.gdx.scenes.scene2d.Stage;
|
||||
|
||||
import sagittarius.model.BaseActor;
|
||||
|
||||
import com.badlogic.gdx.Screen;
|
||||
|
||||
public abstract class BaseScreen implements Screen {
|
||||
|
|
|
@ -22,7 +22,10 @@ public class GameScreen extends BaseScreen {
|
|||
public static Group arrows;
|
||||
public static Group players;
|
||||
|
||||
private int playerTurn;
|
||||
// Constants
|
||||
public static float G = 100;
|
||||
|
||||
public static int playerTurn;
|
||||
|
||||
// ---------- METHODs ----------
|
||||
|
||||
|
@ -59,7 +62,7 @@ public class GameScreen extends BaseScreen {
|
|||
mainStage.addActor(arrows);
|
||||
|
||||
// The one and only Bow
|
||||
Bow bow = new Bow(player1, true);
|
||||
Bow bow = new Bow(true);
|
||||
mainStage.addActor(bow);
|
||||
|
||||
// others
|
||||
|
@ -75,6 +78,7 @@ public class GameScreen extends BaseScreen {
|
|||
// game turns
|
||||
playerTurn = 0;
|
||||
player1.setActive(true);
|
||||
Bow.changeShooter(player1);
|
||||
|
||||
}
|
||||
|
||||
|
@ -85,30 +89,40 @@ public class GameScreen extends BaseScreen {
|
|||
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);
|
||||
}
|
||||
// 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 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);
|
||||
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);
|
||||
// }
|
||||
// }
|
||||
}
|
81
core/src/sagittarius/view/SettingsScreen.java
Normal file
81
core/src/sagittarius/view/SettingsScreen.java
Normal file
|
@ -0,0 +1,81 @@
|
|||
package sagittarius.view;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener;
|
||||
import com.kotcrab.vis.ui.VisUI;
|
||||
import com.kotcrab.vis.ui.util.form.SimpleFormValidator;
|
||||
import com.kotcrab.vis.ui.widget.VisLabel;
|
||||
import com.kotcrab.vis.ui.widget.VisTable;
|
||||
import com.kotcrab.vis.ui.widget.VisTextButton;
|
||||
import com.kotcrab.vis.ui.widget.VisValidatableTextField;
|
||||
|
||||
import sagittarius.SagittariusGame;
|
||||
|
||||
public class SettingsScreen extends BaseScreen {
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
|
||||
Gdx.input.setInputProcessor(mainStage);
|
||||
|
||||
// Table creation
|
||||
VisTable table = new VisTable(true);
|
||||
table.setFillParent(true);
|
||||
mainStage.addActor(table);
|
||||
|
||||
VisLabel errorLabel = new VisLabel();
|
||||
errorLabel.setColor(Color.RED);
|
||||
|
||||
VisValidatableTextField gConstField = new VisValidatableTextField();
|
||||
|
||||
VisTextButton saveButton = new VisTextButton("Save");
|
||||
saveButton.addListener(new ActorGestureListener() {
|
||||
@Override
|
||||
public void tap(InputEvent event, float x, float y, int count, int button) {
|
||||
super.tap(event, x, y, count, button);
|
||||
|
||||
GameScreen.G = Float.parseFloat(gConstField.getText());
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
VisTextButton returnButton = new VisTextButton("Go Back");
|
||||
returnButton.addListener(new ActorGestureListener() {
|
||||
@Override
|
||||
public void tap(InputEvent event, float x, float y, int count, int button) {
|
||||
super.tap(event, x, y, count, button);
|
||||
SagittariusGame.setActiveScreen( new StartScreen() );
|
||||
}
|
||||
});
|
||||
|
||||
SimpleFormValidator validator;
|
||||
validator = new SimpleFormValidator(saveButton, errorLabel, "smooth");
|
||||
validator.notEmpty(gConstField, "G cannot be empty");
|
||||
validator.floatNumber(gConstField, "G must be a float");
|
||||
validator.valueGreaterThan(gConstField, "G must be positive", 0, true);
|
||||
|
||||
// Table structure
|
||||
table.add(errorLabel);
|
||||
table.row();
|
||||
table.add(new VisLabel("G constant:"));
|
||||
table.add(gConstField);
|
||||
table.row();
|
||||
table.add(saveButton);
|
||||
table.row();
|
||||
table.add(returnButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float dt) {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
VisUI.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
}
|
34
core/src/sagittarius/view/SetupScreen.java
Normal file
34
core/src/sagittarius/view/SetupScreen.java
Normal file
|
@ -0,0 +1,34 @@
|
|||
package sagittarius.view;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.kotcrab.vis.ui.VisUI;
|
||||
import com.kotcrab.vis.ui.widget.VisTable;
|
||||
|
||||
|
||||
public class SetupScreen extends BaseScreen {
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
|
||||
Gdx.input.setInputProcessor(uiStage);
|
||||
|
||||
// Table creation
|
||||
VisUI.load();
|
||||
VisTable table = new VisTable(true);
|
||||
table.setFillParent(true);
|
||||
uiStage.addActor(table);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float dt) {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
VisUI.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
}
|
|
@ -14,17 +14,25 @@ public class StartScreen extends BaseScreen {
|
|||
@Override
|
||||
public void initialize() {
|
||||
|
||||
Gdx.input.setInputProcessor(mainStage);
|
||||
Gdx.input.setInputProcessor(uiStage);
|
||||
|
||||
// Table creation
|
||||
VisUI.load();
|
||||
VisTable table = new VisTable(true);
|
||||
table.setFillParent(true);
|
||||
mainStage.addActor(table);
|
||||
uiStage.addActor(table);
|
||||
|
||||
// Start Button
|
||||
VisTextButton startButton = new VisTextButton("start");
|
||||
startButton.addListener(new ActorGestureListener() {
|
||||
VisTextButton setupButton = new VisTextButton("Setup a game");
|
||||
setupButton.addListener(new ActorGestureListener() {
|
||||
@Override
|
||||
public void tap(InputEvent event, float x, float y, int count, int button) {
|
||||
super.tap(event, x, y, count, button);
|
||||
// TODO
|
||||
}
|
||||
});
|
||||
|
||||
// quick Button
|
||||
VisTextButton quickButton = new VisTextButton("Quick Game");
|
||||
quickButton.addListener(new ActorGestureListener() {
|
||||
@Override
|
||||
public void tap(InputEvent event, float x, float y, int count, int button) {
|
||||
super.tap(event, x, y, count, button);
|
||||
|
@ -32,8 +40,17 @@ public class StartScreen extends BaseScreen {
|
|||
}
|
||||
});
|
||||
|
||||
VisTextButton settingsButton = new VisTextButton("Settings");
|
||||
settingsButton.addListener(new ActorGestureListener() {
|
||||
@Override
|
||||
public void tap(InputEvent event, float x, float y, int count, int button) {
|
||||
super.tap(event, x, y, count, button);
|
||||
SagittariusGame.setActiveScreen( new SettingsScreen() );
|
||||
}
|
||||
});
|
||||
|
||||
// Quit button
|
||||
VisTextButton quitButton = new VisTextButton("quit");
|
||||
VisTextButton quitButton = new VisTextButton("Exit");
|
||||
quitButton.addListener(new ActorGestureListener() {
|
||||
@Override
|
||||
public void tap(InputEvent event, float x, float y, int count, int button) {
|
||||
|
@ -43,15 +60,19 @@ public class StartScreen extends BaseScreen {
|
|||
});
|
||||
|
||||
// Table structure
|
||||
table.add(startButton);
|
||||
table.add(setupButton).width(150);
|
||||
table.row();
|
||||
table.add(quitButton);
|
||||
table.add(quickButton).width(150);
|
||||
table.row();
|
||||
table.add(settingsButton).width(150);
|
||||
table.row();
|
||||
table.add(quitButton).width(150);
|
||||
table.row();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float dt) {
|
||||
//
|
||||
// nothing (?)
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue