diff --git a/src/main/java/cactusServer/models/CollisionManager.java b/src/main/java/cactusServer/models/CollisionManager.java index c56b316..8f089d1 100644 --- a/src/main/java/cactusServer/models/CollisionManager.java +++ b/src/main/java/cactusServer/models/CollisionManager.java @@ -2,11 +2,16 @@ import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + import org.ntlab.radishforandroidstudio.framework.model3D.CollisionResult; +import org.ntlab.radishforandroidstudio.framework.model3D.Object3D; import org.ntlab.radishforandroidstudio.framework.model3D.Position3D; import org.ntlab.radishforandroidstudio.framework.physics.PhysicsUtility; import org.ntlab.radishforandroidstudio.java3d.Vector3d; +import cactusServer.entities.Bullet; import cactusServer.entities.Instance; import cactusServer.entities.Object; import cactusServer.entities.Player; @@ -40,6 +45,7 @@ Instance instance = Instances.getInstance().getInstance(instanceId); instance.getUniverse().update(interval); collisionPlayersObjects(instanceId, instance); +// collisionBulletsAndOthers(instanceId, instance); } } @@ -86,4 +92,83 @@ 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(); + while (playersBulletsEntryIt.hasNext()) { + Map.Entry> playersBulletsEntry = playersBulletsEntryIt.next(); + String bulletOwnerPlayerId = playersBulletsEntry.getKey(); + Map bulletMap = playersBulletsEntry.getValue(); +// 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(); + 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, 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()); + } + } + } + + 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)) { + System.out.println("c2"); +// instance.destroyBullet(bulletOwnerPlayerId, bulletId); + bulletEntryIt.remove(); + instance.getUniverse().displace(bullet.getPlaceable()); + System.out.println("c3"); + } + } + } + + private boolean isCollision(Bullet bullet, Player player) { + CollisionResult result; + result = PhysicsUtility.checkCollision((Object3D) (bullet.getPlaceable()), null, player.getObject(), null); + return (result != null); + } + + private boolean isCollision(Bullet bullet, Object object) { + CollisionResult result; + result = PhysicsUtility.checkCollision((Object3D) (bullet.getPlaceable()), null, object.getObject(), null); + return (result != null); + } }