From 715e5971ae83e596c42568b9acf64f409220b10a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Fri, 16 Apr 2021 14:30:25 +0200 Subject: [PATCH] fix: turn system, kinda broken and ugly --- core/src/sagittarius/model/Arrow.java | 21 ++++----- core/src/sagittarius/model/Bow.java | 10 ++--- core/src/sagittarius/model/MouseInfo.java | 2 - core/src/sagittarius/view/GameScreen.java | 54 ++++++++++++----------- 4 files changed, 44 insertions(+), 43 deletions(-) diff --git a/core/src/sagittarius/model/Arrow.java b/core/src/sagittarius/model/Arrow.java index 8097e21..2489060 100644 --- a/core/src/sagittarius/model/Arrow.java +++ b/core/src/sagittarius/model/Arrow.java @@ -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); @@ -86,13 +86,13 @@ public class Arrow extends BaseActor { float dx = actor.getX() - this.getX(); float dy = actor.getY() - this.getY(); - + float len2 = dx*dx + dy*dy; - + float coeff = SagittariusGame.G * ((Planet) actor).getMass() * (float) Math.pow(len2, -3/2); float gravityX = coeff * dx; - float gravityY = coeff * dy; + float gravityY = coeff * dy; force.add(gravityX, gravityY); } @@ -125,7 +125,7 @@ public class Arrow extends BaseActor { */ private void verifyLanding() { for (Actor actor : GameScreen.attractors.getChildren()) { - + Planet planet = (Planet) actor; float dist = this.getPosition().sub( planet.getPosition() ).len(); @@ -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; } } diff --git a/core/src/sagittarius/model/Bow.java b/core/src/sagittarius/model/Bow.java index bfd4ff9..8769dba 100644 --- a/core/src/sagittarius/model/Bow.java +++ b/core/src/sagittarius/model/Bow.java @@ -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; - } - } diff --git a/core/src/sagittarius/model/MouseInfo.java b/core/src/sagittarius/model/MouseInfo.java index 41116d4..851a829 100644 --- a/core/src/sagittarius/model/MouseInfo.java +++ b/core/src/sagittarius/model/MouseInfo.java @@ -1,7 +1,5 @@ package sagittarius.model; -import com.badlogic.gdx.scenes.scene2d.Actor; - import sagittarius.view.GameScreen; public class MouseInfo extends BaseActor { diff --git a/core/src/sagittarius/view/GameScreen.java b/core/src/sagittarius/view/GameScreen.java index 17c614e..e1269ad 100644 --- a/core/src/sagittarius/view/GameScreen.java +++ b/core/src/sagittarius/view/GameScreen.java @@ -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); + // actualPlayer.setActive(true); // } } - public static Player nextTurn() { - ((Player) players.getChild(playerTurn++)).setActive(false); - if ( playerTurn % players.getChildren().size == 0 ) { - playerTurn = 0; + /** + * 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); } - 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); - // } - // } + public static void nextPlayer() { + actualPlayer.setActive(false); + playerTurn++; + playerTurn %= players.getChildren().size; + actualPlayer = (Player) players.getChild(playerTurn); + actualPlayer.setActive(true); + } } \ No newline at end of file