Newer
Older
CactusServer / src / main / java / cactusServer / models / CollisionManager.java
package cactusServer.models;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.ntlab.radishforandroidstudio.framework.model3D.CollisionResult;
import org.ntlab.radishforandroidstudio.framework.physics.PhysicsUtility;

import cactusServer.entities.Character;
import cactusServer.entities.Instance;
import cactusServer.entities.Object;

public class CollisionManager {
	private static CollisionManager theInstance;
	private List<CollisionResult> result;
	private HashMap<String, Instance> instances;

	private CollisionManager() {
		result = new ArrayList<CollisionResult>();
		instances = Instances.getInstance().getInstances();
	}

	public static CollisionManager getCollision() {
		if (theInstance == null) {
			theInstance = new CollisionManager();
		}
		return theInstance;
	}

	public List<CollisionResult> getResult() {
		return result;
	}

	public void collisionRun() {
		for (Map.Entry<String, Instance> instance : instances.entrySet()) {
			result.clear();
			HashMap<String, Object> objects = instance.getValue().getObjects();
			HashMap<String, Character> characters = instance.getValue().getCharacters();
			for (Map.Entry<String, Object> object : objects.entrySet()) {
				for (Map.Entry<String, Character> character : characters.entrySet()) {
					result.add(PhysicsUtility.checkCollision(character.getValue().getObject(), "",
							object.getValue().getObject(), ""));
				}
			}
		}
	}

}