Package testing

Source Code of testing.TestsGen

package testing;

import org.newdawn.slick.geom.Vector2f;

import framework.collision.CircularCollisionMask;
import framework.collision.CollisionComponent;
import framework.collision.LineCollisionMask;
import framework.component.ComponentSystem;
import framework.component.ParentComponent;
import framework.component.util.MouseFollowerComponent;
import framework.event.Event;
import framework.event.EventListener;
import framework.event.EventSystem;
import framework.rendering.SpriteComponent;
import framework.rendering.TextRenderComponent;
import framework.spacial.Line;
import framework.spacial.OrientationComponent;
import framework.spacial.PositionComponent;
import framework.spacial.rotational.OrbitalVelocityComponent;
import framework.spacial.rotational.SpinComponent;
import framework.userinput.MouseListenerSystem.MousePressedEvent;

public abstract class TestsGen {
  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);
    root.addComponent(p3);
    root.addComponent(new ColourChangeComponent());
  }
 
  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))));
  }
}
TOP

Related Classes of testing.TestsGen

TOP
Copyright © 2018 www.massapi.com. 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.