Package framework.component

Examples of framework.component.ParentComponent


   * Draw a dot on the screen at the given coordinates.
   * @param x The x coordinate (in pixels) of the dot on the screen.
   * @param y The y coordinate (in pixels) of the dot on the screen.
   */
  private static void createDot(float x, float y, ParentComponent gridParent){
    ParentComponent ballParent = new ParentComponent();
    gridParent.addComponent(ballParent);

    PositionComponent ballPos = new PositionComponent(x,y);
    ballParent.addComponent(ballPos);
    SpriteComponent ballSprite = new SpriteComponent(ColourManager.getDot(), 17, 17);
    ballParent.addComponent(ballSprite);
  }
View Full Code Here


public class BackgroundGenerator {
 
  private static final String BACKGROUND_FILENAME = "res/img/Background.png";
 
  public static void generateBackground(){
    ParentComponent backgroundParent = new ParentComponent("Background");
    ComponentSystem.getInstance().getRoot().addComponent(backgroundParent);
   
    backgroundParent.addComponent(new PositionComponent(0,0));
   
    SpriteComponent spriteComp = new SpriteComponent(BACKGROUND_FILENAME);
    spriteComp.setAlwaysOnBottom();
    backgroundParent.addComponent(spriteComp);
  }
View Full Code Here

      }
    }
  }

  public void setRelativeToParent(float newTheta){
    ParentComponent p = this.getParent();
    if(p != null){
      p = p.getParent();
      while(p != null && p.getChildByType(getType()) == null){
        p = p.getParent();
      }
    }
    OrientationComponent orientationComp = null;
    if(p != null){
      orientationComp = (OrientationComponent) p.getChildByType(getType());
    }
    float parentTheta = 0;
    if(orientationComp != null){
      parentTheta = orientationComp.getValue();
    }
View Full Code Here

  }

  private void alterDescendents(float deltaTheta, SingleTypeComponentList descendents){
    if(descendents != null && shouldUpdateDescendents()){
      for(Component d:descendents){
        ParentComponent p = (ParentComponent) d;
        Component oc = p.getChildByType(getType());

        PositionComponent pos = (PositionComponent) p.getChildByType(PositionComponent.class.getName());
        if(pos != null){
          PositionComponent centrePos = (PositionComponent) getSiblingByType(PositionComponent.class.getName());
          if(centrePos != null){
            pos.setVector(VectorUtil.rotateAround(pos.getVector(), centrePos.getVector(), deltaTheta));
          }
        }
        if(oc != null){
          OrientationComponent o = (OrientationComponent) oc;
          if(o.shouldUpdateWithAncestor()){
            o.setValue(o.getValue()+deltaTheta);
          }
        }else{
          alterDescendents(deltaTheta, p.getChildrenByType(ParentComponent.class.getName()));
        }
      }
    }
  }
View Full Code Here

    return gridParent;
  }

  private static ParentComponent generateGridLine(int gridX, int gridY, boolean isHorizontal, float spacing, Grid grid){
    ParentComponent lineParent = generateGridLine(spacing*gridX, spacing*gridY, isHorizontal);

    LineComponent lineComp = new LineComponent(isHorizontal ? grid.getHorizontalLine(gridX,gridY) : grid.getVerticalLine(gridX,gridY));
    lineParent.addComponent(lineComp);
   
    lineParent.setLabel(getLineLabel(gridX, gridY, isHorizontal));
    return lineParent;
  }
View Full Code Here

    return lineParent;
  }


  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));
    }
   
    PositionComponent pos;

    //TODO remove this weird pixel adjustment to make it cleaner, and independant of image size.
    if(isHorizontal){
      pos = new PositionComponent(screenX + 12, screenY+ 10);
    }else{
      pos = new PositionComponent(screenX + 5, screenY + 15);
    }

    lineParent.addComponent(pos);

    return lineParent;
  }
View Full Code Here

  private void alterDescendents(Vector2f deltaVector,
      SingleTypeComponentList descendents) {
    if (shouldUpdateDescendents() && descendents != null) {
      for (Component d : descendents) {
        ParentComponent p = (ParentComponent) d;
        VectorValueComponent v = (VectorValueComponent) p
            .getChildByType(getType());
        if (v != null && v.shouldUpdateWithAncestor()) {
          v.addVector(deltaVector);
        } else {
          alterDescendents(
              deltaVector,
              p.getChildrenByType(ParentComponent.class.getName()));
        }
      }
    }
  }
View Full Code Here

    }
  }

  public void setRelativeToParent(Vector2f newVector) {
    if (newVector != null) {
      ParentComponent p = this.getParent();
      if (p != null) {
        p = p.getParent();
        while (p != null && p.getChildByType(getType()) == null) {
          p = p.getParent();
        }
      }
      VectorValueComponent vecComp = null;
      if (p != null) {
        vecComp = (VectorValueComponent) p.getChildByType(getType());
      }
      Vector2f parentVector = null;
      if (vecComp != null) {
        parentVector = vecComp.getVector();
      }
View Full Code Here

      }
    }
  }

  private static ParentComponent generateSquare(Grid grid, int gridX, int gridY, int spacing){
    ParentComponent squareParent = new ParentComponent(getSquareLabel(gridX, gridY));

    squareParent.addComponent(new SpriteComponent("res/img/Blank.png", spacing - 5, spacing - 5));

    float x = gridX*spacing+10;
    float y = gridY*spacing+10;

    //TODO remove these weird coordinate adjustions.
    squareParent.addComponent(new PositionComponent(x,y));
    squareParent.addComponent(new SquareComponent(grid.getSquare(gridX, gridY)));

    return squareParent;
  }
View Full Code Here

      setUpScoreCounter(player);
    }
  }

  private static void setUpScoreCounter(Player player) {
    ParentComponent counterParent = new ParentComponent();
    counterParent.addComponent(new ScoreCounterComponent(player));
   
    SpriteComponent spriteComp = new SpriteComponent(ColourManager.getSquareForPlayer(player.getId()), new Vector2f(-20, -12), 50, 50);
    counterParent.addComponent(spriteComp);
   
    counterParent.addComponent(new TextRenderComponent(""));
    counterParent.addComponent(new PositionComponent(690+(60*player.getId()), 25));
   
    ComponentSystem.getInstance().getParentComponentByLabel("Background").addComponent(counterParent);
  }
View Full Code Here

TOP

Related Classes of framework.component.ParentComponent

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.