fix: rolled back to when Planet didn't contain Moons

This commit is contained in:
Laureηt 2021-04-12 20:45:09 +02:00
parent f9c1f258bc
commit 613dc0a757
7 changed files with 32 additions and 69 deletions

View file

@ -3,7 +3,7 @@
[license-url]: https://git.inpt.fr/tobgang/sagittarius/-/blob/master/LICENSE [license-url]: https://git.inpt.fr/tobgang/sagittarius/-/blob/master/LICENSE
[![MIT License][license-shield]][license-url] [![MIT License][license-shield]][license-url]
A turn based game in wich players kill each others using bows, arrows and GRAVITY ! A turn based game in which players kill each others using bows, arrows and GRAVITY !
## Built with ## Built with
* [openJDK 15](https://openjdk.java.net/projects/jdk/15/) * [openJDK 15](https://openjdk.java.net/projects/jdk/15/)
@ -17,12 +17,13 @@ To run the game:
```bash ```bash
./gradlew desktop:run ./gradlew desktop:run
``` ```
or just press (Ctrl +) F5 in vscode.
To export the game to a .jar file: To export the game to a .jar file:
```bash ```bash
./gradlew desktop:dist ./gradlew desktop:dist
``` ```
The resulting .jar files should be in `*/build/libs/` The resulting .jar file should be in `desktop/build/libs/`
## TODO LIST ## TODO LIST
* create BaseActor to concatenate code * create BaseActor to concatenate code

View file

@ -31,16 +31,16 @@ public class Arrow extends Actor {
* Constructs an Arrow using its initial conditions. * Constructs an Arrow using its initial conditions.
* *
* @param angle initial angle of the Arrow (in degrees). * @param angle initial angle of the Arrow (in degrees).
* @param power power given to the Arrow a Bow. * @param power power given to the Arrow by the Bow.
* @param shooter Bow's shooter. * @param shooter Bow's shooter.
*/ */
Arrow(float angle, float power, Player shooter) { Arrow(float angle, float power, Player shooter) {
super(); super();
this.setPosition(shooter.getX() + shooter.getWidth() * MathUtils.cosDeg(shooter.getRotation()), this.setPosition(shooter.getX() + shooter.getWidth() * MathUtils.cosDeg(shooter.getRotation()), // TODO: possible to not do trigonometry ?
shooter.getY() + shooter.getWidth() * MathUtils.sinDeg(shooter.getRotation())); shooter.getY() + shooter.getWidth() * MathUtils.sinDeg(shooter.getRotation()));
this.velocity = new Vector2(power, 0).setAngleDeg(angle); this.velocity = new Vector2(power, 0).setAngleDeg(angle);
this.acceleration = new Vector2(); this.acceleration = new Vector2();
this.setOrigin(80, 0); this.setOrigin(80, 2);
this.setSize(100, 4); this.setSize(100, 4);
this.force = computeForce(); this.force = computeForce();
} }
@ -63,18 +63,18 @@ public class Arrow extends Actor {
@Override @Override
public void draw(Batch batch, float parentAlpha) { public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha); super.draw(batch, parentAlpha);
fontDebug.draw(batch, "TTL=" + this.TTL, getX(), getY() + fontDebug.getCapHeight()*5); fontDebug.draw(batch, "TTL=" + (int)TTL, getX(), getY() + fontDebug.getCapHeight()*5);
fontDebug.draw(batch, "pos=" + getX() + "," + getY(), getX(), getY() + fontDebug.getCapHeight()*4); fontDebug.draw(batch, "pos=" + (int)getX() + "," + (int)getY(), getX(), getY() + fontDebug.getCapHeight()*4);
fontDebug.draw(batch, "speed=" + this.velocity, getX(), getY() + fontDebug.getCapHeight()*3); fontDebug.draw(batch, "speed=" + (int)velocity.x + "," + (int)velocity.y, getX(), getY() + fontDebug.getCapHeight()*3);
fontDebug.draw(batch, "accel=" + this.acceleration, getX(), getY() + fontDebug.getCapHeight()*2); fontDebug.draw(batch, "accel=" + (int)acceleration.x + "," + (int)acceleration.y, getX(), getY() + fontDebug.getCapHeight()*2);
fontDebug.draw(batch, "force=" + this.force, getX(), getY() + fontDebug.getCapHeight()*1); fontDebug.draw(batch, "force=" + (int)force.x + "," + (int)force.y, getX(), getY() + fontDebug.getCapHeight()*1);
fontDebug.draw(batch, "angle=" + getRotation(), getX(), getY()); fontDebug.draw(batch, "angle=" + (int)getRotation(), getX(), getY());
} }
@Override @Override
public void drawDebug(ShapeRenderer shapes) { public void drawDebug(ShapeRenderer shapes) {
super.drawDebug(shapes); super.drawDebug(shapes);
for (Actor actor : GameScreen.planets.getChildren()) { for (Actor actor : GameScreen.attractors.getChildren()) {
shapes.line(getX(), getY(), actor.getX(), actor.getY()); shapes.line(getX(), getY(), actor.getX(), actor.getY());
} }
} }
@ -85,7 +85,7 @@ public class Arrow extends Actor {
shapes.set(ShapeType.Line); shapes.set(ShapeType.Line);
if (getStage() != null) shapes.setColor(getStage().getDebugColor()); if (getStage() != null) shapes.setColor(getStage().getDebugColor());
shapes.rect(getX() - getOriginX(), getY(), shapes.rect(getX() - getOriginX(), getY() - getOriginY(),
getOriginX(), getOriginY(), getOriginX(), getOriginY(),
getWidth(), getHeight(), getWidth(), getHeight(),
getScaleX(), getScaleY(), getScaleX(), getScaleY(),
@ -99,7 +99,7 @@ public class Arrow extends Actor {
*/ */
private Vector2 computeForce() { private Vector2 computeForce() {
Vector2 force = new Vector2(); Vector2 force = new Vector2();
for (Actor actor : GameScreen.planets.getChildren()) { for (Actor actor : GameScreen.attractors.getChildren()) {
float dx = actor.getX() - this.getX(); float dx = actor.getX() - this.getX();
float dy = actor.getY() - this.getY(); float dy = actor.getY() - this.getY();

View file

@ -1,54 +1,32 @@
package sagittarius.model; package sagittarius.model;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
public class Moon extends Actor { public class Moon extends Planet {
private BitmapFont fontDebug = new BitmapFont();
private float mass;
private Planet sun; private Planet sun;
private float altitude; private float altitude;
private float radius;
// ---------- CONSTRUCTORs ---------- // ---------- CONSTRUCTORs ----------
public Moon(Planet sun, float mass, float radius, float altitude, Color color) { public Moon(Planet sun, float mass, float radius, float altitude, Color color) {
super(); super(new Vector2(), mass, radius, color);
this.sun = sun; this.sun = sun;
this.mass = mass;
this.setColor(color);
this.altitude = altitude; this.altitude = altitude;
this.radius = radius;
} }
// ---------- METHODs ---------- // ---------- METHODs ----------
@Override @Override
public void act(float dt) { public void act(float dt) {
this.rotateBy(10.0f / this.altitude); this.rotateBy(10.0f / this.altitude);
this.setX(sun.getX() + this.altitude*MathUtils.cosDeg(this.getRotation())); this.setX(sun.getX() + this.altitude*MathUtils.cosDeg(this.getRotation()));
this.setY(sun.getY() + this.altitude*MathUtils.sinDeg(this.getRotation())); this.setY(sun.getY() + this.altitude*MathUtils.sinDeg(this.getRotation()));
}
@Override
public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
fontDebug.draw(batch, "radius=" + (int)radius, getX(), getY() + fontDebug.getCapHeight()*2);
fontDebug.draw(batch, "mass=" + (int)mass, getX(), getY() + fontDebug.getCapHeight());
fontDebug.draw(batch, "pos=" + (int)getX() + "," + (int)getY(), getX(), getY());
}
@Override
public void drawDebug(ShapeRenderer shapes) {
super.drawDebug(shapes);
shapes.setColor(this.getColor());
shapes.circle(this.getX(), this.getY(), this.radius);
} }
/** /**
@ -58,12 +36,4 @@ public class Moon extends Actor {
return this.sun; return this.sun;
} }
public float getMass() {
return mass;
}
public Vector2 getPosition() {
return new Vector2( getX(), getY() );
}
} }

View file

@ -15,7 +15,6 @@ public class Planet extends Actor {
private BitmapFont fontDebug = new BitmapFont(); private BitmapFont fontDebug = new BitmapFont();
private float radius; private float radius;
private float mass; private float mass;
private Group moons;
// ---------- CONSTRUCTORs ---------- // ---------- CONSTRUCTORs ----------
@ -25,7 +24,6 @@ public class Planet extends Actor {
this.radius = radius; this.radius = radius;
this.mass = mass; this.mass = mass;
this.setColor(color); this.setColor(color);
moons = new Group();
} }
// ---------- METHODs ---------- // ---------- METHODs ----------
@ -33,8 +31,6 @@ public class Planet extends Actor {
@Override @Override
public void act(float dt) { public void act(float dt) {
super.act(dt); super.act(dt);
moons.setDebug(getDebug(), true);
moons.act(dt);
} }
@Override @Override
@ -43,7 +39,6 @@ public class Planet extends Actor {
fontDebug.draw(batch, "radius=" + (int)radius, getX(), getY() + fontDebug.getCapHeight()*2); fontDebug.draw(batch, "radius=" + (int)radius, getX(), getY() + fontDebug.getCapHeight()*2);
fontDebug.draw(batch, "mass=" + (int)mass, getX(), getY() + fontDebug.getCapHeight()); fontDebug.draw(batch, "mass=" + (int)mass, getX(), getY() + fontDebug.getCapHeight());
fontDebug.draw(batch, "pos=" + (int)getX() + "," + (int)getY(), getX(), getY()); fontDebug.draw(batch, "pos=" + (int)getX() + "," + (int)getY(), getX(), getY());
moons.draw(batch, parentAlpha);
} }
@Override @Override
@ -51,7 +46,6 @@ public class Planet extends Actor {
super.drawDebug(shapes); super.drawDebug(shapes);
shapes.setColor(this.getColor()); shapes.setColor(this.getColor());
shapes.circle(this.getX(), this.getY(), this.radius); shapes.circle(this.getX(), this.getY(), this.radius);
moons.drawDebug(shapes);
} }
/** /**
@ -61,10 +55,6 @@ public class Planet extends Actor {
return this.radius; return this.radius;
} }
public void addMoon(Moon moon) {
moons.addActor(moon);
}
public float getMass() { public float getMass() {
return mass; return mass;
} }

View file

@ -22,7 +22,7 @@ public class Player extends Actor {
public Player(Planet home, Color color) { public Player(Planet home, Color color) {
super(); super();
this.setSize(100, 50); this.setSize(100, 50); // TODO: fix this ? (width & height inverted)
this.setRotation(MathUtils.random(360)); this.setRotation(MathUtils.random(360));
this.setColor(color); this.setColor(color);
this.setOrigin(0, getHeight()/2); this.setOrigin(0, getHeight()/2);

View file

@ -1,7 +1,7 @@
package sagittarius.view; package sagittarius.view;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL30;
import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.Screen; import com.badlogic.gdx.Screen;
@ -31,7 +31,7 @@ public abstract class BaseScreen implements Screen {
// clear screen // clear screen
Gdx.gl.glClearColor(0,0,0,1); Gdx.gl.glClearColor(0,0,0,1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);
// draw actors on screnn // draw actors on screnn
mainStage.draw(); mainStage.draw();

View file

@ -18,7 +18,7 @@ public class GameScreen extends BaseScreen {
public static Vector2 worldCursor; public static Vector2 worldCursor;
// Groups // TODO: move this in SagittariusGame ? // Groups // TODO: move this in SagittariusGame ?
public static Group planets; public static Group attractors;
public static Group arrows; public static Group arrows;
// ---------- METHODs ---------- // ---------- METHODs ----------
@ -26,17 +26,19 @@ public class GameScreen extends BaseScreen {
@Override @Override
public void initialize() { public void initialize() {
// planets // planets & moons
planets = new Group(); attractors = new Group();
Planet planet1 = new Planet(new Vector2(400, 400), 1000, 50, Color.BLUE); Planet planet1 = new Planet(new Vector2(400, 400), 1000, 50, Color.BLUE);
planets.addActor(planet1); attractors.addActor(planet1);
Planet planet2 = new Planet(new Vector2(1400, 700), 1000, 100, Color.ORANGE); Planet planet2 = new Planet(new Vector2(1400, 700), 1000, 100, Color.ORANGE);
planet2.addMoon(new Moon(planet2, 100, 10, 300, Color.MAGENTA)); attractors.addActor(planet2);
planets.addActor(planet2);
mainStage.addActor(planets); Moon moon2_1 = new Moon(planet2, 100, 10, 300, Color.MAGENTA);
attractors.addActor(moon2_1);
mainStage.addActor(attractors);
// players // players
Player player1 = new Player(planet1, Color.WHITE); Player player1 = new Player(planet1, Color.WHITE);