feat!: camera now follows arrows and players

This commit is contained in:
Laureηt 2021-04-23 17:03:40 +02:00
parent ce3b1e265a
commit 939ceaed4a
5 changed files with 41 additions and 13 deletions

View file

@ -3,10 +3,7 @@ package sagittarius;
import com.badlogic.gdx.Game;
import com.kotcrab.vis.ui.VisUI;
import sagittarius.view.BaseScreen;
import sagittarius.view.GameScreen;
import sagittarius.view.SettingsScreen;
import sagittarius.view.StartScreen;
import sagittarius.view.*;
public class SagittariusGame extends Game {
@ -31,7 +28,7 @@ public class SagittariusGame extends Game {
@Override
public void create() {
VisUI.load();
game.setScreen(new GameScreen());
game.setScreen(new StartScreen());
}
}

View file

@ -59,6 +59,7 @@ public class Arrow extends EntityQuad {
if (TTL <= 0) {
GameScreen.arrows.removeActor(this);
GameScreen.nextPlayer();
GameScreen.setFocus(GameScreen.playerCurrent);
}
} else {
this.setPosition(crash.getPosition().cpy().add(offset));
@ -123,6 +124,7 @@ public class Arrow extends EntityQuad {
this.crash = planet;
this.offset = this.getPosition().sub( planet.getPosition() );
GameScreen.nextPlayer();
GameScreen.setFocus(GameScreen.playerCurrent);
break;
}
}
@ -149,6 +151,7 @@ public class Arrow extends EntityQuad {
GameScreen.removePlayer(player);
GameScreen.arrows.removeActor(this);
GameScreen.nextPlayer();
GameScreen.setFocus(GameScreen.playerCurrent);
break;
}
}

View file

@ -35,17 +35,19 @@ public class Bow extends Actor {
@Override
public void act(float dt) {
super.act(dt);
if (GameScreen.playerCurrent.isActive() && Gdx.input.isButtonJustPressed(Buttons.LEFT) && !pressed) {
if (GameScreen.playerCurrent.isActive() && Gdx.input.isButtonJustPressed(Buttons.RIGHT) && !pressed) {
this.anchor = GameScreen.worldCursor.cpy();
pressed = true;
} else if (Gdx.input.isButtonPressed(Buttons.LEFT) && pressed) {
} else if (Gdx.input.isButtonPressed(Buttons.RIGHT) && pressed) {
aim = this.anchor.cpy().sub(GameScreen.worldCursor);
angle = aim.angleDeg();
power = MathUtils.clamp(aim.len(), 0, 1000);
} else if (pressed && power > 50) {
pressed = false;
GameScreen.playerCurrent.setActive(false);
GameScreen.arrows.addActor(new Arrow(angle, power, GameScreen.playerCurrent));
Arrow arrowShot = new Arrow(angle, power, GameScreen.playerCurrent);
GameScreen.setFocus(arrowShot); // do not use constructor 2 times
GameScreen.arrows.addActor(arrowShot);
} else {
pressed = false;
}

View file

@ -7,6 +7,8 @@ import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.Group;
import org.omg.CORBA.Current;
import sagittarius.SagittariusGame;
import sagittarius.model.*;
@ -26,9 +28,16 @@ public class GameScreen extends BaseScreen {
public static Group arrows;
public static Group players;
// turn system stuff
public static int playerIndex;
public static Player playerCurrent;
// camera stuff
private Vector3 mainCameraPosition;
private final float speed = 0.05f;
private final float ispeed = 1.0f - speed;
private static Entity focus;
// ---------- METHODs ----------
@Override
@ -40,7 +49,7 @@ public class GameScreen extends BaseScreen {
Planet planet1 = new Planet(new Vector2(300, 200), 1000, 50, Color.BLUE);
attractors.addActor(planet1);
Planet planet2 = new Planet(new Vector2(1200, 700), 4000, 200, Color.ORANGE);
Planet planet2 = new Planet(new Vector2(1200, 700), 3000, 200, Color.ORANGE);
attractors.addActor(planet2);
Moon moon2_1 = new Moon(planet2, 100, 70, 500, Color.MAGENTA);
@ -88,6 +97,10 @@ public class GameScreen extends BaseScreen {
player1.setActive(true);
playerCurrent = player1;
// camera stuff
mainCameraPosition = mainStage.getCamera().position;
focus = playerCurrent;
}
@Override
@ -101,11 +114,16 @@ public class GameScreen extends BaseScreen {
SagittariusGame.setActiveScreen( new StartScreen() );
}
// camera follow focus
mainCameraPosition.scl(ispeed);
mainCameraPosition.add(new Vector3(focus.getPosition(), 0).scl(speed));
}
/**
* TODO
* @param player
* Removes a Player from the Game.
*
* @param player Player to remove from the active list.
*/
public static void removePlayer(Player player) {
player.setActive(false);
@ -124,6 +142,9 @@ public class GameScreen extends BaseScreen {
}
}
/**
* Used to allows the next Player in the list to play.
*/
public static void nextPlayer() {
playerCurrent.setActive(false);
playerIndex++;
@ -131,4 +152,8 @@ public class GameScreen extends BaseScreen {
playerCurrent = (Player) players.getChild(playerIndex);
playerCurrent.setActive(true);
}
public static void setFocus(Entity entity) {
focus = entity;
}
}

View file

@ -1,5 +1,6 @@
package sagittarius.view;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.scenes.scene2d.Actor;
@ -10,8 +11,8 @@ public class MouseInfo extends Actor {
@Override
public void act(float dt) {
super.act(dt);
setX(GameScreen.worldCursor.x); // use direct method
setY(GameScreen.worldCursor.y);
setX(GameScreen.screenCursor.x);
setY(Gdx.graphics.getHeight() - GameScreen.screenCursor.y);
}
@Override