diff --git a/src/main/java/cactusServer/models/CollisionManager.java b/src/main/java/cactusServer/models/CollisionManager.java index 3ffe8f1..8f089d1 100644 --- a/src/main/java/cactusServer/models/CollisionManager.java +++ b/src/main/java/cactusServer/models/CollisionManager.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; import org.ntlab.radishforandroidstudio.framework.model3D.CollisionResult; @@ -44,7 +45,7 @@ Instance instance = Instances.getInstance().getInstance(instanceId); instance.getUniverse().update(interval); collisionPlayersObjects(instanceId, instance); - collisionBulletsAndOthers(instanceId, instance); +// collisionBulletsAndOthers(instanceId, instance); } } @@ -92,35 +93,69 @@ object.setPosition(new Position3D(vec)); } +// private void collisionBulletsAndOthers(String instanceId, Instance instance) { +// System.out.println("a"); +// for (Map.Entry> playersBulletsEntry : instance.getBullets().entrySet()) { +// String bulletOwnerPlayerId = playersBulletsEntry.getKey(); +// Map bulletMap = playersBulletsEntry.getValue(); +// for (Map.Entry bulletEntry : bulletMap.entrySet()) { +// String bulletId = bulletEntry.getKey(); +// Bullet bullet = bulletEntry.getValue(); +// System.out.println("b"); +// collisionBulletAndPlayers(instanceId, instance, bulletOwnerPlayerId, bulletId, bullet); +// System.out.println("c"); +// collisionBulletAndObjects(instance, bulletOwnerPlayerId, bulletId, bullet); +// System.out.println("d"); +// } +// } +// } + private void collisionBulletsAndOthers(String instanceId, Instance instance) { - for (Map.Entry> playersBulletsEntry : instance.getBullets().entrySet()) { + System.out.println("a"); +// for (Map.Entry> playersBulletsEntry : instance.getBullets().entrySet()) { + Iterator>> playersBulletsEntryIt = instance.getBullets().entrySet().iterator(); + while (playersBulletsEntryIt.hasNext()) { + Map.Entry> playersBulletsEntry = playersBulletsEntryIt.next(); String bulletOwnerPlayerId = playersBulletsEntry.getKey(); Map bulletMap = playersBulletsEntry.getValue(); - for (Map.Entry bulletEntry : bulletMap.entrySet()) { +// for (Map.Entry bulletEntry : bulletMap.entrySet()) { + Iterator> bulletEntryIt = bulletMap.entrySet().iterator(); + while (bulletEntryIt.hasNext()) { + Map.Entry bulletEntry = bulletEntryIt.next(); String bulletId = bulletEntry.getKey(); Bullet bullet = bulletEntry.getValue(); - collisionBulletAndPlayers(instanceId, instance, bulletOwnerPlayerId, bulletId, bullet); - collisionBulletAndObjects(instance, bulletOwnerPlayerId, bulletId, bullet); + System.out.println("b"); + collisionBulletAndPlayers(instanceId, instance, bulletOwnerPlayerId, bulletId, bullet, bulletEntryIt); + System.out.println("c"); + collisionBulletAndObjects(instance, bulletOwnerPlayerId, bulletId, bullet, bulletEntryIt); + System.out.println("d"); } } } - private void collisionBulletAndPlayers(String instanceId, Instance instance, String bulletOwnerPlayerId, String bulletId, Bullet bullet) { + private void collisionBulletAndPlayers(String instanceId, Instance instance, String bulletOwnerPlayerId, String bulletId, Bullet bullet, Iterator> bulletEntryIt) { Instances instances = Instances.getInstance(); for (Map.Entry playersEntry : instances.getPlayers(instanceId).entrySet()) { if (isCollision(bullet, playersEntry.getValue())) { if (!(playersEntry.getKey().equals(bulletOwnerPlayerId))) { // Player(����������)�ƒe�������������̏��������� } - instance.destroyBullet(bulletOwnerPlayerId, bulletId); // Player(�������܂�)�ɓ��������e������ +// instance.destroyBullet(bulletOwnerPlayerId, bulletId); // Player(�������܂�)�ɓ��������e������ + bulletEntryIt.remove(); + instance.getUniverse().displace(bullet.getPlaceable()); } } } - private void collisionBulletAndObjects(Instance instance, String bulletOwnerPlayerId, String bulletId, Bullet bullet) { + private void collisionBulletAndObjects(Instance instance, String bulletOwnerPlayerId, String bulletId, Bullet bullet, Iterator> bulletEntryIt) { + System.out.println("c1"); for (Object object : instance.getObjects().values()) { if (isCollision(bullet, object)) { - instance.destroyBullet(bulletOwnerPlayerId, bulletId); + System.out.println("c2"); +// instance.destroyBullet(bulletOwnerPlayerId, bulletId); + bulletEntryIt.remove(); + instance.getUniverse().displace(bullet.getPlaceable()); + System.out.println("c3"); } } }