Skip to content

Commit

Permalink
fix style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Avalancs committed Mar 11, 2020
1 parent eee682a commit 100b660
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
4 changes: 2 additions & 2 deletions engine/src/main/java/org/destinationsol/game/SolCam.java
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ public Vector2 worldToScreen(SolShip ship) {

/** @return true if the camera matrix does not have Nan or infinite values */
public boolean isMatrixValid() {
for(float i : myCam.combined.val) {
if(!Float.isFinite(i)) {
for (float i : myCam.combined.val) {
if (!Float.isFinite(i)) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.destinationsol.game.input.Shooter;
import org.destinationsol.ui.SolInputManager;
import org.destinationsol.ui.SolUiControl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

Expand All @@ -39,15 +41,16 @@ public class ShipMixedControl implements ShipUiControl {
public final SolUiControl shoot2Ctrl;
public final SolUiControl abilityCtrl;
private final SolUiControl myDownCtrl;
private final Vector2 myMouseScreenPos;
private final Vector2 mouseScreenPos;
private final TextureAtlas.AtlasRegion myCursor;
private boolean myRight;
private boolean myLeft;
private boolean turnRight;
private boolean turnLeft;
private Logger logger = LoggerFactory.getLogger(ShipMixedControl.class);

ShipMixedControl(SolApplication solApplication, List<SolUiControl> controls) {
GameOptions gameOptions = solApplication.getOptions();
myCursor = Assets.getAtlasRegion("engine:uiCursorTarget");
myMouseScreenPos = new Vector2();
mouseScreenPos = new Vector2();
upCtrl = new SolUiControl(null, false, gameOptions.getKeyUpMouse());
controls.add(upCtrl);
myDownCtrl = new SolUiControl(null, false, gameOptions.getKeyDownMouse());
Expand All @@ -71,18 +74,18 @@ public void update(SolApplication solApplication, boolean enabled) {
SolInputManager im = solApplication.getInputManager();
Hero hero = game.getHero();
if (hero.isNonTranscendent()) {
myMouseScreenPos.set(Gdx.input.getX(), Gdx.input.getY());
mouseScreenPos.set(Gdx.input.getX(), Gdx.input.getY());
// project mouse coordinates [0;width] and [0;height] to screen coordinates [0,1], [0,1] by scaling down
myMouseScreenPos.scl(1.0f / Gdx.graphics.getWidth(), 1.0f / Gdx.graphics.getHeight());
mouseScreenPos.scl(1.0f / Gdx.graphics.getWidth(), 1.0f / Gdx.graphics.getHeight());
Vector2 shipOnScreen = game.getCam().worldToScreen(hero.getShip()); // unproject hero to screen coordinates
assertHeroAndMouseCoords(myMouseScreenPos, shipOnScreen);
float desiredAngle = SolMath.angle(shipOnScreen, myMouseScreenPos);
Boolean ntt = Mover.needsToTurn(hero.getAngle(), desiredAngle, hero.getRotationSpeed(), hero.getRotationAcceleration(), Shooter.MIN_SHOOT_AAD);
if (ntt != null) {
if (ntt) {
myRight = true;
assertHeroAndMouseCoords(mouseScreenPos, shipOnScreen);
float desiredAngle = SolMath.angle(shipOnScreen, mouseScreenPos);
Boolean needsToTurn = Mover.needsToTurn(hero.getAngle(), desiredAngle, hero.getRotationSpeed(), hero.getRotationAcceleration(), Shooter.MIN_SHOOT_AAD);
if (needsToTurn != null) {
if (needsToTurn) {
turnRight = true;
} else {
myLeft = true;
turnLeft = true;
}
}
if (!im.isMouseOnUi()) {
Expand Down Expand Up @@ -115,25 +118,23 @@ private boolean problemWithProjections(SolCam camera) {
* @param heroCoords hero coordinates projected to [0;1] screen space
*/
private void assertHeroAndMouseCoords(Vector2 mouseCoords, Vector2 heroCoords) {
if(Double.isNaN(mouseCoords.x) || Double.isNaN(mouseCoords.y)) {
System.err.println("Screen size: " + Gdx.graphics.getWidth() + " " + Gdx.graphics.getHeight());
if (Double.isNaN(mouseCoords.x) || Double.isNaN(mouseCoords.y)) {
throw new RuntimeException("Mouse coordinates are not valid: " + mouseCoords.x + " " + mouseCoords.y);
}

if(Double.isNaN(heroCoords.x) || Double.isNaN(heroCoords.y)) {
System.err.println("Screen size: " + Gdx.graphics.getWidth() + " " + Gdx.graphics.getHeight());
if (Double.isNaN(heroCoords.x) || Double.isNaN(heroCoords.y)) {
throw new RuntimeException("Hero coordinates are not valid: " + heroCoords.x + " " + heroCoords.y);
}
}

@Override
public boolean isLeft() {
return myLeft;
return turnLeft;
}

@Override
public boolean isRight() {
return myRight;
return turnRight;
}

@Override
Expand Down Expand Up @@ -168,7 +169,7 @@ public TextureAtlas.AtlasRegion getInGameTex() {

@Override
public void blur() {
myLeft = false;
myRight = false;
turnLeft = false;
turnRight = false;
}
}

0 comments on commit 100b660

Please sign in to comment.