fix: turn system, kinda broken and ugly

This commit is contained in:
Laureηt 2021-04-16 14:30:25 +02:00
parent eff5fc1f99
commit 715e5971ae
4 changed files with 44 additions and 43 deletions

View file

@ -55,7 +55,7 @@ public class Arrow extends BaseActor {
this.TTL -= dt; this.TTL -= dt;
this.setRotation(this.velocity.angleDeg()); this.setRotation(this.velocity.angleDeg());
verifyLanding(); verifyLanding();
verifyHittingPlayer(); verifyHitting();
if (TTL <= 0) { if (TTL <= 0) {
GameScreen.arrows.removeActor(this); GameScreen.arrows.removeActor(this);
@ -133,22 +133,23 @@ public class Arrow extends BaseActor {
landed = true; landed = true;
this.crash = planet; this.crash = planet;
this.offset = this.getPosition().sub( planet.getPosition() ); this.offset = this.getPosition().sub( planet.getPosition() );
Bow.changeShooter(GameScreen.nextTurn());
break; break;
} }
} }
} }
private void verifyHittingPlayer() { /**
* TODO
*/
private void verifyHitting() {
for (Actor actor : GameScreen.players.getChildren()) { for (Actor actor : GameScreen.players.getChildren()) {
Player player = (Player) actor; Player player = (Player) actor;
if (TTL < 19 && player.hitbox.contains(getX(), getY())) { if (TTL < 19 && player.hitbox.contains(getX(), getY())) {
landed = true; landed = true;
GameScreen.players.removeActor(player); GameScreen.removePlayer(player);
GameScreen.arrows.removeActor(this); GameScreen.arrows.removeActor(this);
Bow.changeShooter(GameScreen.nextTurn());
break; break;
} }
} }

View file

@ -13,7 +13,7 @@ public class Bow extends Actor {
// ---------- ATTRIBUTEs ---------- // ---------- ATTRIBUTEs ----------
private static Player shooter; private Player shooter;
private boolean aimAssist = false; private boolean aimAssist = false;
private boolean pressed = false; private boolean pressed = false;
private float angle; private float angle;
@ -34,6 +34,9 @@ public class Bow extends Actor {
@Override @Override
public void act(float dt) { public void act(float dt) {
this.shooter = GameScreen.actualPlayer;
// TODO: probably can do better with an eventListener // TODO: probably can do better with an eventListener
if (Gdx.input.isButtonJustPressed(Buttons.LEFT) && !pressed) { if (Gdx.input.isButtonJustPressed(Buttons.LEFT) && !pressed) {
this.anchor = GameScreen.worldCursor.cpy(); this.anchor = GameScreen.worldCursor.cpy();
@ -43,6 +46,7 @@ public class Bow extends Actor {
} else if (pressed) { } else if (pressed) {
pressed = false; pressed = false;
GameScreen.arrows.addActor(getArrow()); GameScreen.arrows.addActor(getArrow());
GameScreen.nextPlayer();
} }
} }
@ -79,8 +83,4 @@ public class Bow extends Actor {
return new Arrow(angle, power, shooter); return new Arrow(angle, power, shooter);
} }
public static void changeShooter(Player newShooter) {
shooter = newShooter;
}
} }

View file

@ -1,7 +1,5 @@
package sagittarius.model; package sagittarius.model;
import com.badlogic.gdx.scenes.scene2d.Actor;
import sagittarius.view.GameScreen; import sagittarius.view.GameScreen;
public class MouseInfo extends BaseActor { public class MouseInfo extends BaseActor {

View file

@ -24,6 +24,7 @@ public class GameScreen extends BaseScreen {
public static Group players; public static Group players;
public static int playerTurn; public static int playerTurn;
public static Player actualPlayer;
// ---------- METHODs ---------- // ---------- METHODs ----------
@ -76,7 +77,6 @@ public class GameScreen extends BaseScreen {
// game turns // game turns
playerTurn = 0; playerTurn = 0;
player1.setActive(true); player1.setActive(true);
Bow.changeShooter(player1);
} }
@ -87,40 +87,42 @@ public class GameScreen extends BaseScreen {
unprojectedCursor = mainStage.getCamera().unproject(new Vector3(screenCursor, 0)); unprojectedCursor = mainStage.getCamera().unproject(new Vector3(screenCursor, 0));
worldCursor = new Vector2(unprojectedCursor.x, unprojectedCursor.y); worldCursor = new Vector2(unprojectedCursor.x, unprojectedCursor.y);
// Player actualPlayer = (Player) players.getChild(playerTurn); actualPlayer = (Player) players.getChild(playerTurn);
// if (actualPlayer.isActive()) { // if (actualPlayer.isActive()) {
// actualPlayer.setActive(true); // actualPlayer.setActive(false);
// playerTurn++; // playerTurn++;
// playerTurn %= players.getChildren().size; // playerTurn %= players.getChildren().size;
// actualPlayer = (Player) players.getChild(playerTurn); // actualPlayer = (Player) players.getChild(playerTurn);
// actualPlayer.setActive(false); // actualPlayer.setActive(true);
// } // }
} }
public static Player nextTurn() { /**
((Player) players.getChild(playerTurn++)).setActive(false); * TODO
if ( playerTurn % players.getChildren().size == 0 ) { * @param player
playerTurn = 0; */
public static 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;
actualPlayer = (Player) players.getChild(playerTurn);
actualPlayer.setActive(true);
} else {
players.removeActor(player);
} }
Player newPlayer = (Player) players.getChild(playerTurn);
newPlayer.setActive(true);
return newPlayer;
} }
// public void removePlayer(Player player) { public static void nextPlayer() {
// int index = players.getChildren().indexOf(player, true); actualPlayer.setActive(false);
// if (index < playerTurn) { playerTurn++;
// players.removeActor(player); playerTurn %= players.getChildren().size;
// playerTurn++; actualPlayer = (Player) players.getChild(playerTurn);
// playerTurn %= players.getChildren().size; actualPlayer.setActive(true);
// } else if (index == playerTurn) { }
// players.removeActor(player);
// playerTurn %= players.getChildren().size;
// Player actualPlayer = (Player) players.getChild(playerTurn);
// actualPlayer.setActive(true);
// } else {
// players.removeActor(player);
// }
// }
} }