I'm making a game in LibGDX where the player dodges falling objects. At the moment, my code makes each object (in this case 'DROPS') fall at random speeds. I'm wondering if anyone can suggest how to amend this code to make all the objects start falling at the same speed and have this value increase over time. Here is my current code:
for (int i = 0; i < amount; i++) {
float x = MathUtils.random(0, ManicMeltdowns.WIDTH - TextureManager.DROPS.getWidth());
float y = MathUtils.random(ManicMeltdowns.HEIGHT, ManicMeltdowns.HEIGHT * 3);
float speed = MathUtils.random(2, 5);
addEntity(new Drops(new Vector2 (x, y), new Vector2(0, -speed)));
}
I assume you have to adjust 'float speed', but I'm not sure how.
Many thanks.
-Edit- Here is the drops class:
public class Drops extends Entity{
public Drops(Vector2 pos, Vector2 direction) {
super(TextureManager.DROPS, pos, direction);
}
@Override
public void update() {
pos.add(direction);
if (pos.y <= -TextureManager.DROPS.getHeight()) {
float x = MathUtils.random(0, ManicMeltdowns.WIDTH - TextureManager.DROPS.getWidth());
pos.set(x, ManicMeltdowns.HEIGHT);
}
}
}
And here is the entity class:
public abstract class Entity {
protected Texture texture;
protected Vector2 pos, direction;
public Entity(Texture texture, Vector2 pos, Vector2 direction) {
this.texture = texture;
this.pos = pos;
this.direction = direction;
}
public abstract void update();
public void render(SpriteBatch sb) {
sb.draw(texture, pos.x, pos.y);
}
public Vector2 getPosition() {
return pos;
}
public Rectangle getBounds() {
return new Rectangle(pos.x, pos.y, texture.getWidth(), texture.getHeight());
}
public void setDirection(float x, float y) {
direction.set(x, y);
direction.scl(Gdx.graphics.getDeltaTime());
}
}