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
[![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
* [openJDK 15](https://openjdk.java.net/projects/jdk/15/)
@ -17,12 +17,13 @@ To run the game:
```bash
./gradlew desktop:run
```
or just press (Ctrl +) F5 in vscode.
To export the game to a .jar file:
```bash
./gradlew desktop:dist
```
The resulting .jar files should be in `*/build/libs/`
The resulting .jar file should be in `desktop/build/libs/`
## TODO LIST
* create BaseActor to concatenate code

View file

@ -31,16 +31,16 @@ public class Arrow extends Actor {
* Constructs an Arrow using its initial conditions.
*
* @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.
*/
Arrow(float angle, float power, Player shooter) {
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()));
this.velocity = new Vector2(power, 0).setAngleDeg(angle);
this.acceleration = new Vector2();
this.setOrigin(80, 0);
this.setOrigin(80, 2);
this.setSize(100, 4);
this.force = computeForce();
}
@ -63,18 +63,18 @@ public class Arrow extends Actor {
@Override
public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
fontDebug.draw(batch, "TTL=" + this.TTL, getX(), getY() + fontDebug.getCapHeight()*5);
fontDebug.draw(batch, "pos=" + getX() + "," + getY(), getX(), getY() + fontDebug.getCapHeight()*4);
fontDebug.draw(batch, "speed=" + this.velocity, getX(), getY() + fontDebug.getCapHeight()*3);
fontDebug.draw(batch, "accel=" + this.acceleration, getX(), getY() + fontDebug.getCapHeight()*2);
fontDebug.draw(batch, "force=" + this.force, getX(), getY() + fontDebug.getCapHeight()*1);
fontDebug.draw(batch, "angle=" + getRotation(), getX(), getY());
fontDebug.draw(batch, "TTL=" + (int)TTL, getX(), getY() + fontDebug.getCapHeight()*5);
fontDebug.draw(batch, "pos=" + (int)getX() + "," + (int)getY(), getX(), getY() + fontDebug.getCapHeight()*4);
fontDebug.draw(batch, "speed=" + (int)velocity.x + "," + (int)velocity.y, getX(), getY() + fontDebug.getCapHeight()*3);
fontDebug.draw(batch, "accel=" + (int)acceleration.x + "," + (int)acceleration.y, getX(), getY() + fontDebug.getCapHeight()*2);
fontDebug.draw(batch, "force=" + (int)force.x + "," + (int)force.y, getX(), getY() + fontDebug.getCapHeight()*1);
fontDebug.draw(batch, "angle=" + (int)getRotation(), getX(), getY());
}
@Override
public void drawDebug(ShapeRenderer shapes) {
super.drawDebug(shapes);
for (Actor actor : GameScreen.planets.getChildren()) {
for (Actor actor : GameScreen.attractors.getChildren()) {
shapes.line(getX(), getY(), actor.getX(), actor.getY());
}
}
@ -85,7 +85,7 @@ public class Arrow extends Actor {
shapes.set(ShapeType.Line);
if (getStage() != null) shapes.setColor(getStage().getDebugColor());
shapes.rect(getX() - getOriginX(), getY(),
shapes.rect(getX() - getOriginX(), getY() - getOriginY(),
getOriginX(), getOriginY(),
getWidth(), getHeight(),
getScaleX(), getScaleY(),
@ -99,7 +99,7 @@ public class Arrow extends Actor {
*/
private Vector2 computeForce() {
Vector2 force = new Vector2();
for (Actor actor : GameScreen.planets.getChildren()) {
for (Actor actor : GameScreen.attractors.getChildren()) {
float dx = actor.getX() - this.getX();
float dy = actor.getY() - this.getY();

View file

@ -1,54 +1,32 @@
package sagittarius.model;
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.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 float altitude;
private float radius;
// ---------- CONSTRUCTORs ----------
public Moon(Planet sun, float mass, float radius, float altitude, Color color) {
super();
super(new Vector2(), mass, radius, color);
this.sun = sun;
this.mass = mass;
this.setColor(color);
this.altitude = altitude;
this.radius = radius;
}
// ---------- METHODs ----------
@Override
public void act(float dt) {
this.rotateBy(10.0f / this.altitude);
this.setX(sun.getX() + this.altitude*MathUtils.cosDeg(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;
}
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 float radius;
private float mass;
private Group moons;
// ---------- CONSTRUCTORs ----------
@ -25,7 +24,6 @@ public class Planet extends Actor {
this.radius = radius;
this.mass = mass;
this.setColor(color);
moons = new Group();
}
// ---------- METHODs ----------
@ -33,8 +31,6 @@ public class Planet extends Actor {
@Override
public void act(float dt) {
super.act(dt);
moons.setDebug(getDebug(), true);
moons.act(dt);
}
@Override
@ -43,7 +39,6 @@ public class Planet extends Actor {
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());
moons.draw(batch, parentAlpha);
}
@Override
@ -51,7 +46,6 @@ public class Planet extends Actor {
super.drawDebug(shapes);
shapes.setColor(this.getColor());
shapes.circle(this.getX(), this.getY(), this.radius);
moons.drawDebug(shapes);
}
/**
@ -61,10 +55,6 @@ public class Planet extends Actor {
return this.radius;
}
public void addMoon(Moon moon) {
moons.addActor(moon);
}
public float getMass() {
return mass;
}

View file

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

View file

@ -1,7 +1,7 @@
package sagittarius.view;
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.Screen;
@ -31,7 +31,7 @@ public abstract class BaseScreen implements Screen {
// clear screen
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
mainStage.draw();

View file

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