feat!: camera now follows arrows and players
This commit is contained in:
parent
ce3b1e265a
commit
939ceaed4a
|
@ -3,10 +3,7 @@ package sagittarius;
|
||||||
import com.badlogic.gdx.Game;
|
import com.badlogic.gdx.Game;
|
||||||
import com.kotcrab.vis.ui.VisUI;
|
import com.kotcrab.vis.ui.VisUI;
|
||||||
|
|
||||||
import sagittarius.view.BaseScreen;
|
import sagittarius.view.*;
|
||||||
import sagittarius.view.GameScreen;
|
|
||||||
import sagittarius.view.SettingsScreen;
|
|
||||||
import sagittarius.view.StartScreen;
|
|
||||||
|
|
||||||
public class SagittariusGame extends Game {
|
public class SagittariusGame extends Game {
|
||||||
|
|
||||||
|
@ -31,7 +28,7 @@ public class SagittariusGame extends Game {
|
||||||
@Override
|
@Override
|
||||||
public void create() {
|
public void create() {
|
||||||
VisUI.load();
|
VisUI.load();
|
||||||
game.setScreen(new GameScreen());
|
game.setScreen(new StartScreen());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,7 @@ public class Arrow extends EntityQuad {
|
||||||
if (TTL <= 0) {
|
if (TTL <= 0) {
|
||||||
GameScreen.arrows.removeActor(this);
|
GameScreen.arrows.removeActor(this);
|
||||||
GameScreen.nextPlayer();
|
GameScreen.nextPlayer();
|
||||||
|
GameScreen.setFocus(GameScreen.playerCurrent);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.setPosition(crash.getPosition().cpy().add(offset));
|
this.setPosition(crash.getPosition().cpy().add(offset));
|
||||||
|
@ -123,6 +124,7 @@ public class Arrow extends EntityQuad {
|
||||||
this.crash = planet;
|
this.crash = planet;
|
||||||
this.offset = this.getPosition().sub( planet.getPosition() );
|
this.offset = this.getPosition().sub( planet.getPosition() );
|
||||||
GameScreen.nextPlayer();
|
GameScreen.nextPlayer();
|
||||||
|
GameScreen.setFocus(GameScreen.playerCurrent);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,6 +151,7 @@ public class Arrow extends EntityQuad {
|
||||||
GameScreen.removePlayer(player);
|
GameScreen.removePlayer(player);
|
||||||
GameScreen.arrows.removeActor(this);
|
GameScreen.arrows.removeActor(this);
|
||||||
GameScreen.nextPlayer();
|
GameScreen.nextPlayer();
|
||||||
|
GameScreen.setFocus(GameScreen.playerCurrent);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,17 +35,19 @@ public class Bow extends Actor {
|
||||||
@Override
|
@Override
|
||||||
public void act(float dt) {
|
public void act(float dt) {
|
||||||
super.act(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();
|
this.anchor = GameScreen.worldCursor.cpy();
|
||||||
pressed = true;
|
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);
|
aim = this.anchor.cpy().sub(GameScreen.worldCursor);
|
||||||
angle = aim.angleDeg();
|
angle = aim.angleDeg();
|
||||||
power = MathUtils.clamp(aim.len(), 0, 1000);
|
power = MathUtils.clamp(aim.len(), 0, 1000);
|
||||||
} else if (pressed && power > 50) {
|
} else if (pressed && power > 50) {
|
||||||
pressed = false;
|
pressed = false;
|
||||||
GameScreen.playerCurrent.setActive(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 {
|
} else {
|
||||||
pressed = false;
|
pressed = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@ import com.badlogic.gdx.math.Vector2;
|
||||||
import com.badlogic.gdx.math.Vector3;
|
import com.badlogic.gdx.math.Vector3;
|
||||||
import com.badlogic.gdx.scenes.scene2d.Group;
|
import com.badlogic.gdx.scenes.scene2d.Group;
|
||||||
|
|
||||||
|
import org.omg.CORBA.Current;
|
||||||
|
|
||||||
import sagittarius.SagittariusGame;
|
import sagittarius.SagittariusGame;
|
||||||
import sagittarius.model.*;
|
import sagittarius.model.*;
|
||||||
|
|
||||||
|
@ -26,9 +28,16 @@ public class GameScreen extends BaseScreen {
|
||||||
public static Group arrows;
|
public static Group arrows;
|
||||||
public static Group players;
|
public static Group players;
|
||||||
|
|
||||||
|
// turn system stuff
|
||||||
public static int playerIndex;
|
public static int playerIndex;
|
||||||
public static Player playerCurrent;
|
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 ----------
|
// ---------- METHODs ----------
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -40,7 +49,7 @@ public class GameScreen extends BaseScreen {
|
||||||
Planet planet1 = new Planet(new Vector2(300, 200), 1000, 50, Color.BLUE);
|
Planet planet1 = new Planet(new Vector2(300, 200), 1000, 50, Color.BLUE);
|
||||||
attractors.addActor(planet1);
|
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);
|
attractors.addActor(planet2);
|
||||||
|
|
||||||
Moon moon2_1 = new Moon(planet2, 100, 70, 500, Color.MAGENTA);
|
Moon moon2_1 = new Moon(planet2, 100, 70, 500, Color.MAGENTA);
|
||||||
|
@ -88,6 +97,10 @@ public class GameScreen extends BaseScreen {
|
||||||
player1.setActive(true);
|
player1.setActive(true);
|
||||||
playerCurrent = player1;
|
playerCurrent = player1;
|
||||||
|
|
||||||
|
// camera stuff
|
||||||
|
mainCameraPosition = mainStage.getCamera().position;
|
||||||
|
focus = playerCurrent;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -101,11 +114,16 @@ public class GameScreen extends BaseScreen {
|
||||||
SagittariusGame.setActiveScreen( new StartScreen() );
|
SagittariusGame.setActiveScreen( new StartScreen() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// camera follow focus
|
||||||
|
mainCameraPosition.scl(ispeed);
|
||||||
|
mainCameraPosition.add(new Vector3(focus.getPosition(), 0).scl(speed));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO
|
* Removes a Player from the Game.
|
||||||
* @param player
|
*
|
||||||
|
* @param player Player to remove from the active list.
|
||||||
*/
|
*/
|
||||||
public static void removePlayer(Player player) {
|
public static void removePlayer(Player player) {
|
||||||
player.setActive(false);
|
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() {
|
public static void nextPlayer() {
|
||||||
playerCurrent.setActive(false);
|
playerCurrent.setActive(false);
|
||||||
playerIndex++;
|
playerIndex++;
|
||||||
|
@ -131,4 +152,8 @@ public class GameScreen extends BaseScreen {
|
||||||
playerCurrent = (Player) players.getChild(playerIndex);
|
playerCurrent = (Player) players.getChild(playerIndex);
|
||||||
playerCurrent.setActive(true);
|
playerCurrent.setActive(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setFocus(Entity entity) {
|
||||||
|
focus = entity;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package sagittarius.view;
|
package sagittarius.view;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||||
|
|
||||||
|
@ -10,8 +11,8 @@ public class MouseInfo extends Actor {
|
||||||
@Override
|
@Override
|
||||||
public void act(float dt) {
|
public void act(float dt) {
|
||||||
super.act(dt);
|
super.act(dt);
|
||||||
setX(GameScreen.worldCursor.x); // use direct method
|
setX(GameScreen.screenCursor.x);
|
||||||
setY(GameScreen.worldCursor.y);
|
setY(Gdx.graphics.getHeight() - GameScreen.screenCursor.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue