diff --git a/src/main/java/cactusServer/models/CollisionManager.java b/src/main/java/cactusServer/models/CollisionManager.java index c56b316..3ffe8f1 100644 --- a/src/main/java/cactusServer/models/CollisionManager.java +++ b/src/main/java/cactusServer/models/CollisionManager.java @@ -2,11 +2,15 @@ import java.util.ArrayList; import java.util.HashMap; +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 +44,7 @@ Instance instance = Instances.getInstance().getInstance(instanceId); instance.getUniverse().update(interval); collisionPlayersObjects(instanceId, instance); + collisionBulletsAndOthers(instanceId, instance); } } @@ -86,4 +91,49 @@ vec.add(result.normal); object.setPosition(new Position3D(vec)); } + + private void collisionBulletsAndOthers(String instanceId, Instance instance) { + 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(); + collisionBulletAndPlayers(instanceId, instance, bulletOwnerPlayerId, bulletId, bullet); + collisionBulletAndObjects(instance, bulletOwnerPlayerId, bulletId, bullet); + } + } + } + + private void collisionBulletAndPlayers(String instanceId, Instance instance, String bulletOwnerPlayerId, String bulletId, Bullet bullet) { + 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������ + } + } + } + + private void collisionBulletAndObjects(Instance instance, String bulletOwnerPlayerId, String bulletId, Bullet bullet) { + for (Object object : instance.getObjects().values()) { + if (isCollision(bullet, object)) { + instance.destroyBullet(bulletOwnerPlayerId, bulletId); + } + } + } + + 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); + } }