Package framework.collision

Examples of framework.collision.CollisionComponent


  private static ParentComponent generateGridLine(float screenX, float screenY, boolean isHorizontal){
    ParentComponent lineParent = new ParentComponent();

    int lineWidth = 50;

    lineParent.addComponent(new CollisionComponent(new LineCollisionMask(new Line(0, 0, 0,lineWidth))));

    lineParent.addComponent(new SpriteComponent(ColourManager.getUnplacedLine()));
   
    if(isHorizontal){
      lineParent.addComponent(new OrientationComponent(270));
View Full Code Here


    SpriteComponent spriteComp = new SpriteComponent(ColourManager.getCursorForPlayer(0), new Vector2f(-10, -10), 20, 20);
    spriteComp.setAlwaysOnTop();
    cursorParent.addComponent(spriteComp);
   
    CollisionComponent collis = new CollisionComponent(new CircularCollisionMask(10));
    cursorParent.addComponent(collis);

    setUpEventListener(collis);

    cursorParent.addComponent(new PositionComponent(50,50));
View Full Code Here

      }
    };
  }

  private static void onCollisionStarted(CollisionEvent e){
    CollisionComponent inContactWith = e.getCollidedWith();
   
    //Deselect all other lines
    CollisionComponent cursorCollisComp = (CollisionComponent) ComponentSystem.getInstance().getComponentWithTypeAndLabel("Cursor", CollisionComponent.class);
    if(cursorCollisComp != null){
      for(CollisionComponent collis: cursorCollisComp.getAllComponentsInContact()){
        deselectLine(collis);
      }
    }
   
    //Change the image
View Full Code Here

      }
    }
  }

  private static void onMouseReleased(){
    CollisionComponent collis = (CollisionComponent) ComponentSystem.getInstance().getComponentWithTypeAndLabel("Cursor", CollisionComponent.class.getName());
   
    //Make it the last one it was in contact with
    CollisionComponent inContactWith = null;
    for(CollisionComponent c:collis.getAllComponentsInContact()){
      inContactWith = c;
    }

    if(inContactWith != null){
      LineComponent lineComp = (LineComponent) inContactWith.getSiblingByType(LineComponent.class.getName());
      EventSystem.getInstance().pushEvent(new PlayerClickedOnLineEvent(lineComp));
    }
  }
View Full Code Here

    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;
View Full Code Here

    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

    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

        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 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

TOP

Related Classes of framework.collision.CollisionComponent

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.