fix: Entity.java
This commit is contained in:
parent
20315c3ee2
commit
a4ed374a4c
|
@ -1,187 +1,108 @@
|
|||
package sagittarius.model;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import com.badlogic.gdx.math.Vector;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
|
||||
public abstract class Entity {
|
||||
|
||||
// Attributs.
|
||||
// ---------- ATTRIBUTEs ----------
|
||||
|
||||
/** Angle associé à l'entité. */
|
||||
protected float angle;
|
||||
|
||||
/** Masse de l'entité. */
|
||||
protected float mass;
|
||||
|
||||
/** Couleur de l'entité. */
|
||||
protected Color color;
|
||||
|
||||
/** Position de l'entité. */
|
||||
protected Vector2 position;
|
||||
|
||||
// ---------- CONSTRUCTORs ----------
|
||||
|
||||
|
||||
|
||||
// Constructeur.
|
||||
|
||||
/** Créer une entité.
|
||||
* @param vangle angle associé à l'entité
|
||||
* @param vmass masse de l'entité
|
||||
* @param vcolor couleur de l'entité
|
||||
* @param vposition position de l'entité
|
||||
/** Creates an {@link #Entity}.
|
||||
* @param angle angle associated to the {@link #Entity}.
|
||||
* @param mass mass of the {@link #Entity}.
|
||||
* @param color color of the {@link #Entity}.
|
||||
* @param position position of the {@link #Entity}.
|
||||
*/
|
||||
public Planet(float vangle, float vmass, Color vcolor, Vector2 vposition) {
|
||||
this.angle = vangle;
|
||||
this.mass = vmass;
|
||||
this.color = vcolor;
|
||||
this.position.setX() = vposition.getX();
|
||||
this.position.setY() = vposition.getY();
|
||||
public Entity(float angle, float mass, Color color, Vector2 position) {
|
||||
this.angle = angle;
|
||||
this.mass = mass;
|
||||
this.color = color;
|
||||
this.position = position.cpy();
|
||||
}
|
||||
|
||||
// ---------- GETTERs ----------
|
||||
|
||||
|
||||
|
||||
// Méthodes.
|
||||
|
||||
|
||||
/** Méthode abstraite. */
|
||||
protected abstract String getInfo();
|
||||
|
||||
|
||||
/** Obtenir l'angle associé à l'entité.
|
||||
* @return angle associé à l'entité
|
||||
/**
|
||||
* @return angle associated to the {@link #Entity}.
|
||||
*/
|
||||
public float getAngle() {
|
||||
return this.angle;
|
||||
}
|
||||
|
||||
|
||||
/** Obtenir la masse de l'entité.
|
||||
* @return masse de l'entité
|
||||
/**
|
||||
* @return mass of the {@link #Entity}.
|
||||
*/
|
||||
public float getMass() {
|
||||
return this.mass;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Obtenir la couleur de l'entité.
|
||||
* @return couleur de l'entité
|
||||
/**
|
||||
* @return color of the {@link #Entity}.
|
||||
*/
|
||||
public Color getColor() {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Obtenir la position de l'entité.
|
||||
* @return position de l'entité
|
||||
/**
|
||||
* @return position of the {@link #Entity}.
|
||||
*/
|
||||
public Color getPosition() {
|
||||
this.position.getX();
|
||||
this.position.getY();
|
||||
public Vector2 getPosition() {
|
||||
return this.position.cpy();
|
||||
}
|
||||
|
||||
// ---------- SETTERs ----------
|
||||
|
||||
|
||||
|
||||
/** Changer l'angle associé à l'entité.
|
||||
* @param vangle angle associé à l'entité
|
||||
/**
|
||||
* Sets the angle associated to the {@link #Entity}.
|
||||
*
|
||||
* @param angle new angle.
|
||||
*/
|
||||
public void setAngle(float vangle) {
|
||||
this.angle = vangle;
|
||||
public void setAngle(float angle) {
|
||||
this.angle = angle;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Changer la masse de l'entité.
|
||||
* @param vcolor couleur de la planète
|
||||
/**
|
||||
* Sets the mass of the {@link #Entity}.
|
||||
*
|
||||
* @param mass new mass.
|
||||
*/
|
||||
public void setMass(float vmass) {
|
||||
assert (vmass > 0);
|
||||
this.mass = vmass;
|
||||
public void setMass(float mass) {
|
||||
this.mass = mass;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Changer la couleur de l'entité.
|
||||
* @param vcolor couleur de l'entité
|
||||
/**
|
||||
* Sets the color of the {@link #Entity}.
|
||||
*
|
||||
* @param color new color.
|
||||
*/
|
||||
public void setColor(Color vcolor) {
|
||||
assert (vcouleur != null);
|
||||
this.color = vcolor;
|
||||
public void setColor(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
|
||||
/** Changer la position de l'entité.
|
||||
* @param vposition position de l'entité
|
||||
/**
|
||||
* Sets the Position of the {@link #Entity}.
|
||||
*
|
||||
* @param position new position.
|
||||
*/
|
||||
public void setPosition(Vector2 vposition) {
|
||||
this.position.setX() = vposition.getX();
|
||||
this.position.setY() = vposition.getY();
|
||||
public void setPosition(Vector2 position) {
|
||||
this.position = position.cpy();
|
||||
}
|
||||
|
||||
// ---------- METHODs ----------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/***
|
||||
|
||||
public void draw(Batch batch, float parentAlpha) {
|
||||
super.draw(batch, parentAlpha);
|
||||
if (getDebug()) {
|
||||
fontDebug(batch, getInfo(), getX(), getY());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Dessine les lignes de bord de cette entité si {@link #getDebug()} est vraie. */
|
||||
/* public void drawDebug (ShapeRenderer shapes) {
|
||||
drawDebugBounds(shapes);
|
||||
}
|
||||
|
||||
/** Dessine un rectangle pour les limites de l'entité si {@link #getDebug()} est vraie. */
|
||||
/* protected void drawDebugBounds (ShapeRenderer shapes) {
|
||||
if (!debug) return;
|
||||
shapes.set(ShapeType.Line);
|
||||
if (stage != null) {
|
||||
shapes.setColor(stage.getDebugColor());
|
||||
shapes.rect(x, y, originX, originY, width, height, scaleX, scaleY, rotation);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Met à jour l'entité en fonction du temps. Called each frame by {@link Stage#act(float)}.
|
||||
* <p>
|
||||
* The default implementation calls {@link Action#act(float)} on each action and removes actions that are complete.
|
||||
* @param delta Time in seconds since the last frame. */
|
||||
/* public void act (float delta) {
|
||||
Array<Action> actions = this.actions;
|
||||
if (actions.size == 0) return;
|
||||
if (stage != null && stage.getActionsRequestRendering()) Gdx.graphics.requestRendering();
|
||||
try {
|
||||
for (int i = 0; i < actions.size; i++) {
|
||||
Action action = actions.get(i);
|
||||
if (action.act(delta) && i < actions.size) {
|
||||
Action current = actions.get(i);
|
||||
int actionIndex = current == action ? i : actions.indexOf(action, true);
|
||||
if (actionIndex != -1) {
|
||||
actions.removeIndex(actionIndex);
|
||||
action.setActor(null);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (RuntimeException ex) {
|
||||
String context = toString();
|
||||
throw new RuntimeException("Actor: " + context.substring(0, Math.min(context.length(), 128)), ex);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @return String containing informations about the {@link #Entity}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
protected abstract String getInfo();
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue