Package framework.rendering

Examples of framework.rendering.SpriteComponent


  public static void setUpTurnCounter() {
    ParentComponent counterParent = new ParentComponent();
    counterParent.addComponent(new TurnCounterComponent());
    counterParent.addComponent(new TextRenderComponent("Current Move:"));
   
    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));
   
View Full Code Here


  }

  private static ParentComponent generateCursor(){
    ParentComponent cursorParent = new ParentComponent("Cursor");

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

      }
    }
   
    //Change the image
    if(!isSiblingLinePlaced(inContactWith)){
      SpriteComponent spriteComp = (SpriteComponent) inContactWith.getSiblingByType(SpriteComponent.class.getName());
      if(spriteComp != null){
        spriteComp.setImageFilename(ColourManager.getHighlightedLine(), true);
      }
    }
  }
View Full Code Here

    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);
    root.addComponent(p3);
View Full Code Here

  public static void test2(){
    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

    return hasBeenPlaced;
  }

  public void setHasBeenPlaced(boolean hasBeenPlaced) {
    this.hasBeenPlaced = hasBeenPlaced;
    SpriteComponent s = (SpriteComponent) getSiblingByType(SpriteComponent.class.getName());
    if(s != null){
      s.setImageFilename(hasBeenPlaced ? placedImage : emptyImage);
    }
  }
View Full Code Here

  }

  private void setMouseInside(boolean mouseInside) {
    this.mouseInside = mouseInside;
    if(!hasBeenPlaced){
      SpriteComponent s = (SpriteComponent) getSiblingByType(SpriteComponent.class.getName());
      if(s != null){
        s.setImageFilename(mouseInside ? mousedOverImage : emptyImage);
      }
    }
  }
View Full Code Here

  @Override
  public void onEvent(Event e) {
    if(e != null){
      if(e.getType().equals("Collision")){
        CollisionEvent collis = (CollisionEvent) e;
        SpriteComponent sprite = (SpriteComponent) collis.getCollidedWith().getSiblingByType(SpriteComponent.class.getName());
        if(sprite != null){
          sprite.setImageFilename("res/img/red_dot.png", true);
        }
      }else if(e.getType().equals("CollisionStopped")){
        CollisionEvent collis = (CollisionEvent) e;
        SpriteComponent sprite = (SpriteComponent) collis.getCollidedWith().getSiblingByType(SpriteComponent.class.getName());
        if(sprite != null){
          sprite.setImageFilename("res/img/dot.png", true);
        }
      }else if(e.getType().equals("MousePressed")){
        Collection<Component> comps = ComponentSystem.getInstance().getAllComponents().getComponentsOfType(SpriteComponent.class.getName()).getAllComponents();
        String filename = ((MousePressedEvent) e).getButton() == Input.MOUSE_LEFT_BUTTON ? "res/img/square.png" : "res/img/line.png";
        for(Component c:comps){
          ((SpriteComponent) c).setImageFilename(filename);
        }
      }else if(e.getType().equals("MouseReleased")){
        Collection<Component> dots = ComponentSystem.getInstance().getComponentsOfType(Dot.class.getName());
        for(Component dot:dots){
          SpriteComponent s = (SpriteComponent) dot.getSiblingByType(SpriteComponent.class.getName());
          if(s != null){
            s.setImageFilename("res/img/dot.png");
            s.scaleToMatchTexture();
          }
        }
      }
    }
  }
View Full Code Here

    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

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

TOP

Related Classes of framework.rendering.SpriteComponent

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.