From: fred-boy Date: Fri, 28 Sep 2018 12:10:56 +0000 (+0700) Subject: Add drop picking X-Git-Tag: alpha0.4~84 X-Git-Url: https://deadsoftware.ru/gitweb?p=cavedroid.git;a=commitdiff_plain;h=3fb849898964a43a51cc6483ac72f5e3abbd01f0 Add drop picking --- diff --git a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java index c387bab..e38e3b0 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java @@ -1,6 +1,5 @@ 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; @@ -181,16 +180,22 @@ public class GamePhysics { } public void update(float delta) { - for (Drop drop : gameProc.drops) dropPhy(drop); - for (Mob mob : gameProc.mobs) { - mob.ai(); - mobPhy(mob); + for (Iterator 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 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 5ff36e4..e967f88 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/objects/Drop.java +++ b/core/src/ru/deadsoftware/cavecraft/game/objects/Drop.java @@ -7,23 +7,25 @@ import java.io.Serializable; 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; }