Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Game.Pworld.Pmapping;
- import java.awt.Point;
- import java.awt.geom.Point2D;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.Map;
- import java.util.Set;
- import Base.Indexer;
- import Base.MapValueSet;
- import Game.Pworld.Pentities.EntityData;
- import Game.Pworld.Pentitydefinitions.EntityAttribute;
- import Game.Pworld.Pentitydefinitions.GameObjects;
- public class BaseEntityLogicA {
- class Point1{
- Point point;
- final int n1;
- public Point1(int x, int y, int n1){
- point = new Point(x,y);
- this.n1 = n1;
- }
- public Point1(Point p, int n1){
- point = new Point(p);
- this.n1 = n1;
- }
- @Override
- public String toString(){
- return getPosInfo(point,n1);
- }
- public String getPosInfo(Point p, int h){
- return ("[x: "+ p.x + ", y: "+ p.y + ", Num 1: "+ n1+"]");
- }
- }
- class SectionH{
- private Indexer indxSec = new Indexer();
- /**@param Integer used with unique SectionTag
- * @param SectionInfo */
- private Map<Integer,SectionInfo> SectionMap = new HashMap<Integer, SectionInfo>();
- /**@param Integer used with unique SectionTag
- * @param Integer used with unique EntityTag */
- private MapValueSet<Integer,Integer> SectionEntitySet = new MapValueSet<Integer,Integer>();
- public int addEmptySection(SectionInfo si){
- int tag = indxSec.getNextTag();
- SectionMap.put(tag, si);
- return tag;
- }
- public void addEntity(int sTag, int eTag){
- if(SectionEntitySet.mapContains(eTag)){
- SectionEntitySet.removeAtValue(eTag);
- }
- SectionEntitySet.put(sTag, eTag);
- }
- public int getHeight(int tag) {
- return SectionMap.get(tag).getHeight();
- }
- public Set<Integer> getSections(){
- return SectionMap.keySet();
- }
- public Set<Integer> getSectionEntities(int SectionTag){
- return SectionEntitySet.getSet(SectionTag);
- }
- }
- class GridH{
- public final int GRID_SIZE = 192;
- /**@param Point used as Grid Index
- * @param Integer used with unique EntityTag */
- private MapValueSet<String,Integer> GridMap = new MapValueSet<String,Integer>();
- public Point placeEntityIntoGrid(Point2D pos, int height, int entTag){
- Point p = new Point((int) (pos.getX()/GRID_SIZE),(int) (pos.getY()/GRID_SIZE));
- if(GridMap.mapContains(entTag)){
- GridMap.removeAtValue(entTag);
- }
- GridMap.put(new Point1(p,height).toString(), entTag);
- return p;
- }
- }
- class EntityH{
- GameObjects gObjs = new GameObjects();
- private Indexer indxEnt = new Indexer();
- /**@param Integer used with unique EntityTag
- * @param EntityData */
- private Map<Integer,EntityData> EntityMap = new HashMap<Integer,EntityData>();
- /**@param EntityAttribute
- * @param Integer used with unique EntityTag*/
- private MapValueSet<EntityAttribute,Integer> EntityAttributeValues = new MapValueSet<EntityAttribute,Integer>();
- public int setEntity(EntityData ED){
- int entTag = indxEnt.getNextTag();
- ED.setTag(entTag);
- EntityMap.put(entTag, ED);
- for(int i = 0; i < EntityAttribute.values().length; i++){
- if(gObjs.getGameObject(ED.getName()).getAttributes().containsKey(EntityAttribute.values()[i])){
- EntityAttributeValues.put(EntityAttribute.values()[i],entTag);
- }
- }
- return entTag;
- }
- public void SetPosition(Point2D pos, int eTag) {
- EntityMap.get(eTag).setPosition(pos);
- }
- public Point2D getPosition(int eTag) {
- return EntityMap.get(eTag).getPosition();
- }
- public EntityData getEntityData(int eTag) {
- return EntityMap.get(eTag);
- }
- }
- private Point1 pointField = new Point1(new Point(),0);
- SectionH section = new SectionH();
- EntityH entity = new EntityH();
- GridH grid = new GridH();
- public int addEntity(EntityData ED){
- int tag = -1;
- section.addEntity(ED.getSection(), tag = entity.setEntity(ED));
- grid.placeEntityIntoGrid(ED.getPosition(), section.getHeight(ED.getTag()), ED.getTag());
- return tag;
- }
- public void addEmptySection(SectionInfo si){
- section.addEmptySection(si);
- }
- public void moveEntity(Point2D pos, int eTag, int sTag){
- EntityData hold = entity.getEntityData(eTag);
- hold.setPosition(pos);
- hold.setSection(sTag);
- grid.placeEntityIntoGrid(pos,section.getHeight(sTag),sTag);
- }
- public String getEntityPosition(int eTag){
- EntityData ED = entity.getEntityData(eTag);
- Point2D ePos = ED.getPosition();
- Point p = new Point((int) (ePos.getX()/grid.GRID_SIZE),(int) (ePos.getY()/grid.GRID_SIZE));
- return pointField.getPosInfo(p, section.getHeight(ED.getSection()));
- }
- public Set<Integer> getSections(){
- return section.getSections();
- }
- public Set<Integer> getSectionEntities(int SectionTag){
- return section.getSectionEntities(SectionTag);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement