summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0b8922b)
raw | patch | inline | side by side (parent: 0b8922b)
author | fred-boy <fred-boy@protonmail.com> | |
Fri, 28 Sep 2018 12:10:56 +0000 (19:10 +0700) | ||
committer | fred-boy <fred-boy@protonmail.com> | |
Fri, 28 Sep 2018 12:10:56 +0000 (19:10 +0700) |
core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java | patch | blob | history | |
core/src/ru/deadsoftware/cavecraft/game/objects/Drop.java | patch | blob | history |
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java
index c387bab3f84e816b87007acbd6b4aaa7b2bfe593..e38e3b0b3ef12e858795cb204a4d93cd9e271744 100644 (file)
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(
diff --git a/core/src/ru/deadsoftware/cavecraft/game/objects/Drop.java b/core/src/ru/deadsoftware/cavecraft/game/objects/Drop.java
index 5ff36e476584f6eaa9ac34733d76ba550df0d9ea..e967f880314480a1fd9b9d73c77aedea4729622f 100644 (file)
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;
}