diff --git a/src/main/java/cactusServer/models/CollisionManager.java b/src/main/java/cactusServer/models/CollisionManager.java index 4044ce6..b6234ed 100644 --- a/src/main/java/cactusServer/models/CollisionManager.java +++ b/src/main/java/cactusServer/models/CollisionManager.java @@ -62,13 +62,21 @@ } } } + for (Player player : Instances.getInstance().getPlayers(instanceId).values()) { + for (Player player2 : Instances.getInstance().getPlayers(instanceId).values()) { + if (!player.equals(player2)) { + collisionMove(player2, player); + } + } + } } public void collisionMove(MovableObject object, Player player) { CollisionResult result; - result = PhysicsUtility.checkCollision((Object3D)player.getPlaceable().getBody(), null, object.getObject(), null); - if (result != null) { - System.out.println("�I�u�W�F�N�g�ƃv���C���[���Փ�"); + result = PhysicsUtility.checkCollision((Object3D) player.getPlaceable().getBody(), null, object.getObject(), + null); + if (result != null) { + System.out.println("�I�u�W�F�N�g�ƃv���C���[���Փ�"); objMove(result, object, false); } } @@ -87,10 +95,11 @@ } } } - + public void collisionMove(Player player1, Player player2) { CollisionResult result; - result = PhysicsUtility.checkCollision((Object3D)player1.getPlaceable(), null, (Object3D)player2.getPlaceable(), null); + result = PhysicsUtility.checkCollision((Object3D) player1.getPlaceable(), null, + (Object3D) player2.getPlaceable(), null); if (result != null) { System.out.println("�v���C���[���m���Փ�"); objMove(result, player1, true); @@ -105,7 +114,7 @@ vec.add(result.normal); object.setPosition(new Position3D(vec)); } - + private void objMove(CollisionResult result, Player player, boolean negate) { result.normal.scale(-1); Vector3d vec = player.getPosition().getVector3d(); @@ -114,7 +123,7 @@ vec.add(result.normal); player.setPosition(new Position3D(vec)); } - + private void collisionBulletsAndOthers(String instanceId, Instance instance) { collisionBulletAndOtherBullets(instance); for (Map.Entry> playersBulletsEntry : instance.getBullets().entrySet()) { @@ -122,10 +131,12 @@ Map bulletMap = playersBulletsEntry.getValue(); for (Map.Entry bulletEntry : bulletMap.entrySet()) { Bullet bullet = bulletEntry.getValue(); - if (!bullet.isAlive()) continue; + if (!bullet.isAlive()) + continue; String bulletId = bulletEntry.getKey(); collisionBulletAndPlayers(instanceId, instance, bulletOwnerPlayerId, bulletId, bullet); - if (!bullet.isAlive()) continue; + if (!bullet.isAlive()) + continue; collisionBulletAndObjects(instance, bulletOwnerPlayerId, bulletId, bullet); } } @@ -147,7 +158,7 @@ } return false; } - + private boolean collisionBulletAndObjects(Instance instance, String bulletOwnerPlayerId, String bulletId, Bullet bullet) { for (MovableObject object : instance.getObjects().values()) { @@ -159,7 +170,7 @@ } return false; } - + private void collisionBulletAndOtherBullets(Instance instance) { List> allBulletsEntryList = new ArrayList<>(); for (HashMap playerBullets : instance.getBullets().values()) { @@ -168,11 +179,13 @@ for (int i = 0; i < allBulletsEntryList.size() - 1; i++) { Map.Entry bulletEntry1 = allBulletsEntryList.get(i); Bullet bullet1 = bulletEntry1.getValue(); - if (!bullet1.isAlive()) continue; + if (!bullet1.isAlive()) + continue; for (int j = i + 1; j < allBulletsEntryList.size(); j++) { Map.Entry bulletEntry2 = allBulletsEntryList.get(j); Bullet bullet2 = bulletEntry2.getValue(); - if (!bullet2.isAlive()) continue; + if (!bullet2.isAlive()) + continue; if (isCollision(bullet1, bullet2)) { bullet1.setAlive(false); bullet2.setAlive(false); @@ -185,7 +198,8 @@ private boolean isCollision(Bullet bullet, Player player) { CollisionResult result; - result = PhysicsUtility.checkCollision((Object3D) (bullet.getPlaceable()), null, (Object3D)player.getPlaceable().getBody(), null); + result = PhysicsUtility.checkCollision((Object3D) (bullet.getPlaceable()), null, + (Object3D) player.getPlaceable().getBody(), null); return (result != null); } @@ -194,10 +208,11 @@ result = PhysicsUtility.checkCollision((Object3D) (bullet.getPlaceable()), null, object.getObject(), null); return (result != null); } - + private boolean isCollision(Bullet bullet1, Bullet bullet2) { CollisionResult result; - result = PhysicsUtility.checkCollision((Object3D) (bullet1.getPlaceable()), null, (Object3D) (bullet2.getPlaceable()), null); + result = PhysicsUtility.checkCollision((Object3D) (bullet1.getPlaceable()), null, + (Object3D) (bullet2.getPlaceable()), null); return (result != null); } }