/*
* AQP Project
* http://http://code.google.com/p/aqp-project/
* Alexandre Gomez - Clément Troesch - Fabrice Latterner
*/
package com.aqpproject.worldmodel.game.entity;
import com.aqpproject.game.Singleton;
import com.aqpproject.tools.Vector2D;
import java.util.HashMap;
/**
*
* @author Clément
*/
public class WEMiniMap extends WorldEntity {
public WEMiniMap(String mapSpriteName) {
super("MiniMapBackground", "MiniMapBackground", new Vector2D(), 0, 1, true, true);
Vector2D size = Singleton.getVisualisation().getSpriteSize(m_spriteName);
Vector2D screen = Singleton.getVisualisation().getResolution();
int shift = 20;
m_position.x = screen.x - size.x;
m_position.y = screen.y - size.y - shift;
//Singleton.getVisualisation().setActorAlpha(m_name, 0.4f);
//Entities
m_entities = new HashMap<>();
m_mapSpriteName = mapSpriteName;
Vector2D mapSize = Singleton.getVisualisation().getSpriteSize(m_mapSpriteName);
m_mapShift = new Vector2D(size).translate(-mapSize.x, -mapSize.y).scale(0.5f);
Singleton.getVisualisation().createActor("MiniMap", m_mapSpriteName, m_position.x + m_mapShift.x, m_position.y + m_mapShift.y, 0, 1, true, true);
}
@Override
public void update(long time) {
for (String s : m_entities.keySet()) {
Vector2D pos = m_entities.get(s).getCenter();
pos = pos.scale(1.f / 16.f).translate(m_position).translate(m_mapShift);
Singleton.getVisualisation().updateActor(s + "_mini", pos.x, pos.y, 0);
}
}
public void addEntity(WorldEntity entity, boolean player) {
m_entities.put(entity.m_name, entity);
Singleton.getVisualisation().createActor(entity.m_name + "_mini", "MiniPlayer" + (player ? "1" : "2"), m_position.x + m_mapShift.x, m_position.y + m_mapShift.y, 0, 1, true, true);
}
@Override
public void destroy() {
super.destroy();
Singleton.getVisualisation().deleteActor("MiniMap", true);
for (String s : m_entities.keySet()) {
Singleton.getVisualisation().deleteActor(s + "_mini", true);
}
}
private HashMap<String, WorldEntity> m_entities;
private String m_mapSpriteName;
private Vector2D m_mapShift;
}