fix: turn system, kinda broken and ugly
This commit is contained in:
parent
eff5fc1f99
commit
715e5971ae
|
@ -55,7 +55,7 @@ public class Arrow extends BaseActor {
|
|||
this.TTL -= dt;
|
||||
this.setRotation(this.velocity.angleDeg());
|
||||
verifyLanding();
|
||||
verifyHittingPlayer();
|
||||
verifyHitting();
|
||||
|
||||
if (TTL <= 0) {
|
||||
GameScreen.arrows.removeActor(this);
|
||||
|
@ -133,22 +133,23 @@ 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() {
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
private void verifyHitting() {
|
||||
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.removePlayer(player);
|
||||
GameScreen.arrows.removeActor(this);
|
||||
Bow.changeShooter(GameScreen.nextTurn());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ public class Bow extends Actor {
|
|||
|
||||
// ---------- ATTRIBUTEs ----------
|
||||
|
||||
private static Player shooter;
|
||||
private Player shooter;
|
||||
private boolean aimAssist = false;
|
||||
private boolean pressed = false;
|
||||
private float angle;
|
||||
|
@ -34,6 +34,9 @@ public class Bow extends Actor {
|
|||
|
||||
@Override
|
||||
public void act(float dt) {
|
||||
|
||||
this.shooter = GameScreen.actualPlayer;
|
||||
|
||||
// TODO: probably can do better with an eventListener
|
||||
if (Gdx.input.isButtonJustPressed(Buttons.LEFT) && !pressed) {
|
||||
this.anchor = GameScreen.worldCursor.cpy();
|
||||
|
@ -43,6 +46,7 @@ public class Bow extends Actor {
|
|||
} else if (pressed) {
|
||||
pressed = false;
|
||||
GameScreen.arrows.addActor(getArrow());
|
||||
GameScreen.nextPlayer();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,8 +83,4 @@ public class Bow extends Actor {
|
|||
return new Arrow(angle, power, shooter);
|
||||
}
|
||||
|
||||
public static void changeShooter(Player newShooter) {
|
||||
shooter = newShooter;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package sagittarius.model;
|
||||
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
|
||||
import sagittarius.view.GameScreen;
|
||||
|
||||
public class MouseInfo extends BaseActor {
|
||||
|
|
|
@ -24,6 +24,7 @@ public class GameScreen extends BaseScreen {
|
|||
public static Group players;
|
||||
|
||||
public static int playerTurn;
|
||||
public static Player actualPlayer;
|
||||
|
||||
// ---------- METHODs ----------
|
||||
|
||||
|
@ -76,7 +77,6 @@ public class GameScreen extends BaseScreen {
|
|||
// game turns
|
||||
playerTurn = 0;
|
||||
player1.setActive(true);
|
||||
Bow.changeShooter(player1);
|
||||
|
||||
}
|
||||
|
||||
|
@ -87,40 +87,42 @@ 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);
|
||||
actualPlayer = (Player) players.getChild(playerTurn);
|
||||
// if (actualPlayer.isActive()) {
|
||||
// actualPlayer.setActive(true);
|
||||
// actualPlayer.setActive(false);
|
||||
// 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);
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @param player
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public static void nextPlayer() {
|
||||
actualPlayer.setActive(false);
|
||||
playerTurn++;
|
||||
playerTurn %= players.getChildren().size;
|
||||
actualPlayer = (Player) players.getChild(playerTurn);
|
||||
actualPlayer.setActive(true);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue