diff --git a/src/main/java/cactusServer/models/CollisionManager.java b/src/main/java/cactusServer/models/CollisionManager.java index e1bb494..c3a37c9 100644 --- a/src/main/java/cactusServer/models/CollisionManager.java +++ b/src/main/java/cactusServer/models/CollisionManager.java @@ -44,8 +44,8 @@ for (String instanceId : instances.keySet()) { Instance instance = Instances.getInstance().getInstance(instanceId); instance.getUniverse().update(interval); - collisionPlayersObjects(instanceId, instance); - // collisionBulletsAndOthers(instanceId, instance); + collisionPlayersObjects(instanceId, instance); + collisionBulletsAndOthers(instanceId, instance); } } @@ -92,80 +92,54 @@ vec.add(result.normal); 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) { - System.out.println("a"); - // for (Map.Entry> playersBulletsEntry : - // instance.getBullets().entrySet()) { - Iterator>> playersBulletsEntryIt = instance.getBullets().entrySet() - .iterator(); + + private void collisionBulletsAndOthers(String instanceId, Instance instance) { + 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()) { + Map bulletMap = playersBulletsEntry.getValue(); Iterator> bulletEntryIt = bulletMap.entrySet().iterator(); while (bulletEntryIt.hasNext()) { Map.Entry bulletEntry = bulletEntryIt.next(); String bulletId = bulletEntry.getKey(); Bullet bullet = bulletEntry.getValue(); - 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"); + boolean isRemoved = collisionBulletAndPlayers(instanceId, instance, bulletOwnerPlayerId, bulletId, bullet, bulletEntryIt); + if (!isRemoved) { + collisionBulletAndObjects(instance, bulletOwnerPlayerId, bulletId, bullet, bulletEntryIt); + } } } - } - - private void collisionBulletAndPlayers(String instanceId, Instance instance, String bulletOwnerPlayerId, + } + private boolean 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������ - bulletEntryIt.remove(); - instance.getUniverse().displace(bullet.getPlaceable()); +// bulletEntryIt.remove(); +// instance.getUniverse().displace(bullet.getPlaceable()); +// System.out.println(bulletId + "�폜"); + return true; } } + return false; } - - private void collisionBulletAndObjects(Instance instance, String bulletOwnerPlayerId, String bulletId, - Bullet bullet, Iterator> bulletEntryIt) { - System.out.println("c1"); + + private boolean collisionBulletAndObjects(Instance instance, String bulletOwnerPlayerId, String bulletId, + Bullet bullet, Iterator> bulletEntryIt) { for (MovableObject object : instance.getObjects().values()) { - if (isCollision(bullet, object)) { - System.out.println("c2"); - // instance.destroyBullet(bulletOwnerPlayerId, bulletId); - bulletEntryIt.remove(); - instance.getUniverse().displace(bullet.getPlaceable()); - System.out.println("c3"); + if (isCollision(bullet, object)) { +// bulletEntryIt.remove(); +// instance.getUniverse().displace(bullet.getPlaceable()); +// System.out.println(bulletId + "�폜"); + return true; } } + return false; } private boolean isCollision(Bullet bullet, Player player) {