package ru.deadsoftware.cavecraft.game;
-import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Rectangle;
}
public void update(float delta) {
- for (Drop drop : gameProc.drops) dropPhy(drop);
- for (Mob mob : gameProc.mobs) {
- mob.ai();
- mobPhy(mob);
+ for (Iterator<Drop> it = gameProc.drops.iterator(); it.hasNext(); ) {
+ Drop drop = it.next();
+ dropPhy(drop);
+ if (Intersector.overlaps(drop.getRect(), gameProc.player.getRect()))
+ drop.pickUpDrop(gameProc.player);
+ if (drop.pickedUp) it.remove();
}
+
for (Iterator<Mob> it = gameProc.mobs.iterator(); it.hasNext();) {
- Mob m = it.next();
- if (m.dead)
+ Mob mob = it.next();
+ mob.ai();
+ mobPhy(mob);
+ if (mob.dead)
it.remove();
}
+
playerPhy(gameProc.player);
gameProc.renderer.camera.position.set(
public class Drop implements Serializable {
private int id;
+ public boolean pickedUp = false;
public Vector2 move, position;
- public static void pickUpDrop(Player pl, int id) {
+ public Drop(float x, float y, int id) {
+ this.id = id;
+ position = new Vector2(x, y);
+ move = new Vector2(0, -1);
+ }
+
+ public void pickUpDrop(Player pl) {
for (int i = 0; i < pl.inventory.length; i++) {
- if (pl.inventory[i] == 0) {
+ if (pl.inventory[i] == 0 || pl.inventory[i] == id) {
pl.inventory[i] = id;
+ pickedUp = true;
break;
}
}
}
- public Drop(float x, float y, int id) {
- this.id = id;
- position = new Vector2(x, y);
- move = new Vector2(0, -1);
- }
-
public int getId() {
return id;
}