feat: minor modifications

This commit is contained in:
Laureηt 2021-05-03 15:16:10 +02:00
parent 7817353e15
commit a18d8cfaf7
4 changed files with 88 additions and 23 deletions

View file

@ -6,7 +6,7 @@
A turn based game in which players kill each others using bows, arrows and GRAVITY !
## Built with
* [openJDK 15](https://openjdk.java.net/projects/jdk/15/)
* [openJDK 8](https://openjdk.java.net/projects/jdk/8/)
* [libGDX](https://libgdx.com/)
## Usage
@ -26,14 +26,16 @@ To export the game to a .jar file:
The resulting .jar file should be in `desktop/build/libs/`
## TODO LIST
* create BaseActor to concatenate code
* player turn
* kill player
* generate random map (with parameters)
* move freely camera
* lerp camera arrow
* menus test
* faire des textures (+ background)
* particules de flèche, quand un joueur meurt...
* faire le gestionnaire de keybinds
* faire des sons et musique
* astéroïdes
* bonus/gadgets
* améliorer trajectoires arrows en simulant tout n'univers
* rotating planets and moons (on themselves)
* petites phrases vision
## Contributing
Please use [conventionnal commits](https://www.conventionalcommits.org/).

View file

@ -146,7 +146,7 @@ public class Arrow extends EntityQuad {
private void verifyHitting() {
for (Actor actor : GameScreen.players.getChildren()) {
Player player = (Player) actor;
if (player == GameScreen.playerCurrent && TTL > 19.5) break;
if (player == GameScreen.playerCurrent && TTL > 19.5) continue;
if (Intersector.overlapConvexPolygons(player.hitbox, this.hitbox)) {
landed = true;
GameScreen.removePlayer(player);
@ -158,10 +158,11 @@ public class Arrow extends EntityQuad {
}
}
private boolean hasHit() {
private boolean hasHit() { // doesn't work
for (Actor actor : GameScreen.players.getChildren()) {
Player player = (Player) actor;
if (TTL < 19 && Intersector.overlapConvexPolygons(player.hitbox, this.hitbox)) {
if (player == GameScreen.playerCurrent) continue;
if (player.hitbox.contains(this.getPosition())) {
return true;
}
}
@ -181,16 +182,16 @@ public class Arrow extends EntityQuad {
Arrow dummyArrow = new Arrow(angle, power, shooter);
for (int i = 0; i < iterations; i++) {
dummyArrow.integrationVerlet(timeStep);
if (dummyArrow.hasLanded() || dummyArrow.hasHit() ) { break; }
path.add(dummyArrow.getX());
path.add(dummyArrow.getY());
if ( dummyArrow.hasLanded() || dummyArrow.hasHit() ) { break; }
}
// TODO : optimize, lots of useless stuff + change name
// or ignore and use adapters
final float[] arr = new float[path.size()]; // utiliser le count de la fonction, faire tab size iteration*2, et draw avec count
int index = 0;
int index = 0; // TODO: créer objet Trajectory, avec un float[iteration*2] et un actualSize;
for (final Float value: path) {
arr[index++] = value;
}

View file

@ -60,7 +60,7 @@ public class Bow extends Actor {
if (power > 50) shapes.setColor(Color.RED);
shapes.line(this.anchor, GameScreen.worldCursor);
if (aimAssist) {
float[] traj = Arrow.traj(angle, power, GameScreen.playerCurrent, 400, 0.05f);
float[] traj = Arrow.traj(angle, power, GameScreen.playerCurrent, 500, 0.03f);
if (traj.length > 2) {
shapes.polyline(traj);
}

View file

@ -1,10 +1,12 @@
package sagittarius.view;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Buttons;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.Group;
@ -12,7 +14,7 @@ import com.badlogic.gdx.scenes.scene2d.Group;
import sagittarius.SagittariusGame;
import sagittarius.model.*;
public class GameScreen extends BaseScreen {
public class GameScreen extends BaseScreen implements InputProcessor {
// ---------- ATTRIBUTEs ----------
@ -38,12 +40,15 @@ public class GameScreen extends BaseScreen {
private final float ispeed = 1.0f - speed;
private static Entity focus;
// test
private OrthographicCamera gameCam;
// ---------- METHODs ----------
@Override
public void initialize() {
Gdx.input.setInputProcessor(null); // on a pas de boutons
Gdx.input.setInputProcessor(this);
// planets & moons
attractors = new Group();
@ -102,6 +107,7 @@ public class GameScreen extends BaseScreen {
// camera stuff
mainCameraPosition = mainStage.getCamera().position;
focus = playerCurrent;
gameCam = ((OrthographicCamera) mainStage.getCamera());
}
@ -116,16 +122,21 @@ public class GameScreen extends BaseScreen {
SagittariusGame.setActiveScreen( new StartScreen() );
}
// camera zoom using keys
if (Gdx.input.isKeyPressed( Keys.DOWN)) {
gameCam.zoom += dt;
}
if (Gdx.input.isKeyPressed( Keys.UP)) {
gameCam.zoom -= dt;
}
// clamp zoom
gameCam.zoom = MathUtils.clamp(gameCam.zoom, 1f, 3f);
// camera follow focus
mainCameraPosition.scl(ispeed);
mainCameraPosition.add(new Vector3(focus.getPosition(), 0).scl(speed));
if (Gdx.input.isButtonPressed(Buttons.LEFT)) {
((OrthographicCamera) mainStage.getCamera()).zoom = 2f;
} else {
((OrthographicCamera) mainStage.getCamera()).zoom = 1f;
}
}
/**
@ -164,4 +175,55 @@ public class GameScreen extends BaseScreen {
public static void setFocus(Entity entity) {
focus = entity;
}
}
// ---------- InputProcessor METHODs ----------
@Override
public boolean keyDown(int keycode) {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean keyUp(int keycode) {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean keyTyped(char character) {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean mouseMoved(int screenX, int screenY) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean scrolled(float amountX, float amountY) {
gameCam.zoom += 2 * amountY * Gdx.graphics.getDeltaTime();
return false;
}
}