Package framework.spacial

Examples of framework.spacial.PositionComponent


   
    SpriteComponent spriteComp = new SpriteComponent(ColourManager.getSquareForPlayer(0),new Vector2f(125, -8), 40, 40);
    //spriteComp.setAlwaysOnTop();
    counterParent.addComponent(spriteComp);
    //300 500
    counterParent.addComponent(new PositionComponent(20, 28));
   
    ComponentSystem.getInstance().getParentComponentByLabel("Background").addComponent(counterParent);
  }
View Full Code Here


  @Override
  public boolean isValidComponent(Component c) {
    if(c != null && this.mask != null && this.origin != null){
      if(c.equals(mask)) return false;
      PositionComponent p = (PositionComponent)  (c instanceof PositionComponent ? c : c.getSiblingByType(PositionComponent.class.getName()));
      if(p != null){
        Vector2f otherOrigin = p.getVector();
        if(otherOrigin != null){
          SingleTypeComponentList comps = p.getSiblingsByType(CollisionComponent.class.getName());
          if(comps != null){
            for(Component collis: comps){
              if(this.mask.isCollision(this.origin, otherOrigin, ((CollisionComponent) collis).getMask())){
                return true;
              }
View Full Code Here

  public static void test1(){
    ComponentSystem cs = ComponentSystem.getInstance();
    ParentComponent root = cs.getRoot();
   
    final ParentComponent p1 = new ParentComponent();
    p1.addComponent(new PositionComponent(100,100));
    SpriteComponent s1 = new SpriteComponent("res/img/square.png", new Vector2f(-25, -25), 50, 50);
    s1.setAlwaysOnTop();
    p1.addComponent(s1);
   
    p1.addComponent(new MouseFollowerComponent());
    p1.addComponent(new CollisionComponent(new CircularCollisionMask(25)));
    p1.addComponent(new OrientationComponent(-100));
    final SpinComponent spin = new SpinComponent(0.1f);
    //p1.addComponent(spin);
    EventSystem.getInstance().registerEventListener(new EventListener() {
      private int button;
      @Override
      public void onEvent(Event e) {
        int b = ((MousePressedEvent) e).getButton();
        if(b != button){
          spin.setValue(-spin.getValue());
          button = b;
        }
        p1.addComponent(spin);
      }
     
      @Override
      public int getUniqueID() {
        return 0;
      }
     
      @Override
      public String getType() {
        return "Custom";
      }
    }, "MousePressed", null);
   
    EventSystem.getInstance().registerEventListener(new EventListener() {
      @Override
      public void onEvent(Event e) {
        p1.removeComponent(spin);
      }
     
      @Override
      public int getUniqueID() {
        return 1;
      }
     
      @Override
      public String getType() {
        return "Custom";
      }
    }, "MouseReleased", null);
   
    ParentComponent gridParent = SquaresGen.generateGrid(90, 50, 10, 10, 50);
    root.addComponent(gridParent);
    gridParent.addComponent(new OrbitalVelocityComponent(0.5f, new Vector2f(95, 55)));
   
   
   
    ParentComponent p2 = new ParentComponent();
   
    p1.addComponent(p2);
   
    p2.addComponent(new PositionComponent(10, 150));
    p2.addComponent(new SpriteComponent("res/img/square.png"));
    p2.addComponent(new OrientationComponent(100));
    p2.addComponent(new TextRenderComponent("Click to rotate!"));
   
    ParentComponent p3 = new ParentComponent();
    p3.addComponent(new PositionComponent (700,100));
    p3.addComponent(new SpriteComponent("res/img/line.png",new Vector2f(0, 0), 50, 50));
    p3.addComponent(new OrientationComponent(100));
   
   
    root.addComponent(p1);
View Full Code Here

    ParentComponent root = ComponentSystem.getInstance().getRoot();
    ParentComponent gridLine = new ParentComponent();
    root.addComponent(gridLine);
    gridLine.addComponent(new GridLine());
    gridLine.addComponent(new SpriteComponent("res/img/square.png", 10, 50));
    gridLine.addComponent(new PositionComponent(500,500));
    gridLine.addComponent(new OrientationComponent(100));
    gridLine.addComponent(new CollisionComponent(new LineCollisionMask(new Line(0, 0, 0, 100))));
    //gridLine.addComponent(new CollisionComponent(new RectangularCollisionMask(new Rectangle(10, 50))));
   
    ParentComponent cursor = new ParentComponent();
    root.addComponent(cursor);
    cursor.addComponent(new MouseFollowerComponent());
    cursor.addComponent(new PositionComponent(0,0));
    cursor.addComponent(new SpriteComponent("res/img/dot.png",new Vector2f(-5,-5),10,10));
    //cursor.addComponent(new CollisionComponent(new PointCollisionMask()));
    cursor.addComponent(new CollisionComponent(new CircularCollisionMask(5)));
    //cursor.addComponent(new CollisionComponent(new RectangularCollisionMask(new Rectangle(10, 10), new Vector2f(-5, -5))));
  }
View Full Code Here

    int spacing = 75;
   
    GridLineGenerator.generateLineGrid(grid, gridParent, spacing);
    SquareGenerator.generateSquares(grid, gridParent, spacing);
   
    PositionComponent pos = new PositionComponent(0, 0);
    gridParent.addComponent(pos);
    pos.addVector(new Vector2f(topLeftX, topLeftY));
   
    DotsGenerator.createDots(topLeftX, topLeftY , grid.getDotsWidth() , grid.getDotsHeight() , spacing, gridParent);
  }
View Full Code Here

public class SquaresGen {

  public static ParentComponent generateGrid(int x, int y, int width, int height, float gridSpacing){
    ParentComponent p = new ParentComponent();
    PositionComponent pos = new PositionComponent(x,y);
    p.addComponent(pos);
    p.addComponent(new Grid(width, height, gridSpacing));
    return p;
  }
View Full Code Here

  }
 
  public static ParentComponent generateDot(ParentComponent grandparent, int gridX, int gridY, float gridSpacing){
    ParentComponent p = new ParentComponent();
    grandparent.addComponent(p);
    PositionComponent pos = new PositionComponent(0,0);
    p.addComponent(pos);
    pos.setRelativeToParent(new Vector2f(gridSpacing*gridX,gridSpacing*gridY));
    p.addComponent(new Dot(gridX, gridY));
    p.addComponent(new SpriteComponent("res/img/dot.png",new Vector2f(-10, -10), 20, 20));
    p.addComponent(new CollisionComponent(new CircularCollisionMask(10)));
    return p;
  }
View Full Code Here

    Collection<Component> collisCompsCollection = ComponentSystem.getInstance().getComponentsOfType(CollisionComponent.class.getName());
    if(collisCompsCollection != null){
      ArrayList<Component> collisComps = new ArrayList<Component>(collisCompsCollection);
      for(int i = 0; i < collisComps.size(); i++){
        Component c = collisComps.get(i);
        PositionComponent posComp = (PositionComponent) c.getSiblingByType(PositionComponent.class.getName());
        if(posComp != null){
          Vector2f pos = posComp.getVector();
          if(pos != null){
            CollisionComponent collis = (CollisionComponent) c;
            if(collis.getMask() != null){
              g.setColor(Color.white);
              collis.getMask().renderForDebug(g, pos);
View Full Code Here

public class Square extends ParentComponent{

  public Square(int x, int y) {
    super();
    addComponent(new PositionComponent(x,y));
    addComponent(new SpriteComponent("img/square.png"));
    addComponent(new VelocityComponent(new Vector2f(0.01f, 0.1f)));
    addComponent(new CollisionComponent(new PointCollisionMask()));
  }
View Full Code Here

  }

  @Override
  public void onEvent(Event e) {
    if(e != null && e.getType() == "TimePassed"){
      PositionComponent pos = (PositionComponent) getSiblingByType(PositionComponent.class.getName());
      if(pos != null){
        TimePassedEvent time = (TimePassedEvent) e;
        pos.addVector(this.getVector().scale(time.getDelta()));
      }
    }
  }
View Full Code Here

TOP

Related Classes of framework.spacial.PositionComponent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.