Package edu.mit.d54.plugins.test

Examples of edu.mit.d54.plugins.test.TestRunner


  }

  @Override
  protected void loop() {
    synchronized(this) {
      Display2D display = getDisplay();
      BufferedImage frame = this.frames.get(this.currentFrame);

      int width = frame.getWidth() > this.widthMax ? this.widthMax : frame.getWidth();
      int height = frame.getHeight() > this.heightMax ? this.heightMax : frame.getHeight();
     
      for (int ix = 0; ix < width; ++ix) {
        for (int iy = 0; iy < height; ++iy) {         
          int pixel = frame.getRGB(ix, iy);

          int red = (pixel >> 16) & 0xFF;
          int green = (pixel >> 8) & 0xFF;
          int blue = pixel & 0xFF;

          display.setPixelRGB(ix, iy, red, green, blue);
        }
      }
     
      if (this.lastUpdateTime + (this.secondDelay * 1000) < System.currentTimeMillis()) {
                if (this.currentFrame == (this.frameCount - 1)) {
View Full Code Here


    time=0;
  }

  @Override
  protected void loop() {
    Display2D display=getDisplay();
    time+=dt;
    Graphics2D g=display.getGraphics();

    float timeInLoop;
    float timeInSegment;
    int segment1Length = 5;
    int segment2Length = 10;
    int segment3Length = (int) Math.ceil((255 + 2*17)*dt);
    int transitionLength = 1;
    int totalLength = segment1Length + segment2Length + segment3Length;
    float maxBrightness;



      int[][] ErlCoords = {
            {0,0}, {0,1}, {0,2},
            {1,0},
            {2,0}, {2,1},
            {3,0},
            {4,0}, {4,1}, {4,2},
     
            {6,0}, {6,1}, {6,2},
            {7,0},        {7,2},
            {8,0}, {8,1},
            {9,0},        {9,2},
            {10,0},       {10,2},
     
            {12,0},
            {13,0},
            {14,0},
            {15,0},
            {16,0}, {16,1}, {16,2}
          };
     
      int[][] ThirtyCoords = {
                     {1,5}, {1,6}, {1,7},
            {2,4},                      {2,8},
                                        {3,8},
                                 {4,7},
                                        {5,8},
            {6,4},                      {6,8},
                   {7,5}, {7,6}, {7,7},
     
                   {9,5}, {9,6}, {9,7},
            {10,4},                     {10,8},
            {11,4},                     {11,8},
            {12,4},                     {12,8},
            {13,4},                     {13,8},
            {14,4},                     {14,8},
                   {15,5},{15,6},{15,7}
          };
      float brightness = 0f;

      timeInLoop = (float) time % totalLength;

      if (timeInLoop < 0.5*dt)
      {
        loopNum = (loopNum + 1) % 3;
      }

      // Segment 1
      if (timeInLoop >=0 && timeInLoop < segment1Length)
      {
        timeInSegment = timeInLoop;
        int framesInSegment = (int) Math.round(timeInSegment / dt);
        maxBrightness = 1f;

        g.drawImage(waveimg[loopNum][framesInSegment], 0, 0, null);
      }


      // Segment 2
      else if (timeInLoop >= segment1Length && timeInLoop < segment1Length + segment2Length)
      {
        timeInSegment = timeInLoop - segment1Length;
        if (timeInSegment <= transitionLength)
        {
          maxBrightness = timeInSegment / transitionLength;
        }
        else if (segment2Length - timeInSegment  <= transitionLength)
        {
          maxBrightness = (segment2Length - timeInSegment) / transitionLength;
        }
        else
        {
          maxBrightness = 1f;
        }
        for (int idx=0; idx<ErlCoords.length; idx++)
        {
          int y=ErlCoords[idx][0];
          int x=ErlCoords[idx][1];
          if (y<=5)
            display.setPixelHSB(x, y, 0f, 0.5f, 1f * maxBrightness);
          else if (y<=10)
            display.setPixelHSB(x, y, 0f, 0.67f, 0.7f * maxBrightness);
          else
            display.setPixelHSB(x, y, 0f, 0.85f, 0.3f * maxBrightness);
        }
        for (int idx=0; idx<ThirtyCoords.length; idx++)
        {
          int y=ThirtyCoords[idx][0];
          int x=ThirtyCoords[idx][1];
          if ((int)(Math.random() * (5)) == 0)
          {
            brightness = 1f;
          }
          else
          {
            brightness = 0.5f;
          }
          display.setPixelHSB(x, y, 1f, 0f, brightness * maxBrightness);
        }

      }

      // Segment 3
View Full Code Here

    float wavePeriodT=Float.parseFloat(getKnobValue("wavePeriodT"));
    float wavePeriodX=Float.parseFloat(getKnobValue("wavePeriodX"));
    float wavePeriodY=Float.parseFloat(getKnobValue("wavePeriodY"));
    float waveDepth=Float.parseFloat(getKnobValue("waveDepth"));
   
    Display2D d=getDisplay();
    for (int x=0; x<d.getWidth(); x++)
    {
      for (int y=0; y<d.getHeight(); y++)
      {
        float intensity=(float)((1-(waveDepth/2))+(waveDepth/2)*Math.cos((getTime()/wavePeriodT+x/wavePeriodX+y/wavePeriodY)*2*Math.PI));
        if (x<5 && y<7)
        {
          if ((x+y)%2==0)
            d.setPixelHSB(x,y,0.666f,1,intensity);
          else
            d.setPixelHSB(x,y,0,0,intensity);
        }
        else
        {
          if (x%2==0)
            d.setPixelHSB(x,y,0,1,intensity);
          else
            d.setPixelHSB(x,y,0,0,intensity);
        }
      }
    }
  }
View Full Code Here

    if(gameState != State.IDLE) {
      if (!controller.isConnected())
        return;
    }

    Display2D display=getDisplay();
    Graphics2D g=display.getGraphics();

    switch(gameState) {
    case IDLE:
      int startScreenDisplayPosition = -1 * ( startScreenScrollPosition / startScreenStepsPerFrame );
      if(startScreenDisplayPosition == (-1 * startScreenResetWidth)) {
View Full Code Here

    userInputList.add(b);
  }

  @Override
  protected void loop() {
    Display2D display=getDisplay();
   
    byte userInput = 0;
    if (!userInputList.isEmpty())
      userInput = userInputList.remove(0);

    switch (gameState)
    {
    case IDLE:
      animTime=0;           // initialize
      animTimeLastStep=0;
      vert = 0;
      gameState=State.IDLE_ANIM;
      break;
    case IDLE_ANIM:

      showTitle();      // show title until user presses button

      switch (userInput)
      {
      case 'L':
      case 'R':
      case 'U':
      case 'D':
        gameState=State.LEVEL_START;
        animTime=0;
      }
      break;
    case LEVEL_START:
      animTime+=timestep;
      showL();      // show which level
      showLevelNumber(levelNumber);

      loadLevel(levelNumber);    // load the level data

      frogPosX = 0;      // put frog on the left
      frogPosY = 8;

      if (animTime > 3.0){    // wait 3 seconds and start level
        gameState=State.GAME;
      }
      break;
    case GAME:
      animTime+=timestep;
      drawScreen();    // draws the frog and all enabled cars in their corresponding colour
      moveCars();      // checks whether it's time to move each lane and does so if necessary

      // move frog
      switch (userInput)
      {
      case 'L':
        if (frogPosX > 0){
          frogPosX = frogPosX - 1;
        }

        break;
      case 'R':
        if (frogPosX < 8){
          frogPosX = frogPosX + 1;
        }

        if (frogPosX == 8){ // if the frog has reached the right hand side

          levelNumber = levelNumber + 1;    // go up a level

          if (levelNumber == 10){  // if you've finished all 9 levels

            clearScreen();
            gameState=State.GAME_END_2;
            animTime=0;

          }else// or if it's just the next stage

            clearScreen();
            gameState=State.LEVEL_START;
            animTime=0;
          }
        }

        break;
      case 'U':

        if (frogPosY > 0){
          frogPosY = frogPosY - 1;
        }
        break;
      case 'D':

        if (frogPosY < 16){
          frogPosY = frogPosY + 1;
        }
        break;
      case -1: //there was an error in the network socket or no client connected -- "pause" the game
        return;
      }

      hitCheck()// check whether frog and any of the enabled cars occupy the same area and if so, die


      break;
    case GAME_END_1:   // lose
      animTime+=timestep;

      for (int i = 0;i < vert; i++){      // death animation
        for (int horiz = 0; horiz < 9; horiz++){
          display.setPixelRGB(horiz, i, 255-(i*15), 0, 0); // (red)
        }
      }


      if (animTime - animTimeLastStep > 0.1){  // time to write a new line
        if (vert < 17){
          vert = vert + 1;
        }     
        animTimeLastStep = animTime;
      }

      if (animTime > 2.5){   // after 2.5 secs go back to the title screen

        gameState=State.IDLE;

      }


      break;
    case GAME_END_2:  // win
      animTime+=timestep;
      showWin();     // write WIN on the screen

      for (int i = 0;i < vert; i++){    // animated wipe away of "WIN"
        for (int horiz = 0; horiz < 9; horiz++){
          display.setPixelRGB(horiz, i, 0, 0, 0); // (BLACK)
        }
      }

      if (animTime > 5.0){
        if (animTime - animTimeLastStep > 0.1){  // time to write a new line
View Full Code Here

  }

  private double time=0;
  @Override
  protected void loop() {
    Display2D display=getDisplay();
    time+=dt;
    for (int x=0; x<display.getWidth(); x++)
    {
      for (int y=0; y<display.getHeight(); y++)
      {
        display.setPixelHSB(x,y,(float)(x+y+time*3)/36.f, 1f, 1f);
      }
    }
  }
View Full Code Here

    userInputList.add(b);
  }

  @Override
  protected void loop() {
    Display2D display=getDisplay();
   
    byte userInput = 0;
    if (!userInputList.isEmpty())
      userInput = userInputList.remove(0);
View Full Code Here

* to use {@link PluginRunner} instead.
*/
public class TestRunner {
  public static void main(String[] args)
  {
    Display2D display=new GBDisplay();
    JFrame frame=new JFrame("test");
    DisplayPanel dPanel=new DisplayPanel(display);
    frame.add(dPanel);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
    frame.pack();
View Full Code Here

    }
  }

  @Override
  protected void loop() {
    Display2D display=getDisplay();
    Graphics2D g=display.getGraphics();
   
    switch (gameState)
    {
    case IDLE:
      animTime=0;
      animTimeLastStep=0;
      logoPos=0;
      gameState=State.IDLE_ANIM;
      break;
    case IDLE_ANIM:
      animTime+=timestep;
      if (animTime-animTimeLastStep>=LOGO_ANIM_STEP)
      {
        animTimeLastStep=animTime;
        logoPos++;
        if (logoPos>100)
          gameState=State.IDLE;
      }
      g.drawImage(mitrisLogo, 10-logoPos, 6, null);
      break;
    case GAME_START:
      mitrisGame=new MITrisGame(width,height,timestep);
      gameState=State.GAME;
      break;
    case GAME:
      if (!controller.isConnected())
        return;
      //move piece down if it's time
      mitrisGame.clockTick();
      gameDisplayTime=mitrisGame.getTime();
      sendBoardToDisplay(mitrisGame.getDisplayBoard(),display);
      if (mitrisGame.isGameOver())
      {
        System.out.println(String.format("Game over! Lines cleared: %d  Time: %3.1f",mitrisGame.getDisplayBoard().getNumCleared(),mitrisGame.getTime()));
        gameState=State.GAME_END_1;
        gameOverBoard=mitrisGame.getDisplayBoard();
        animTime=0;
                String extra="";
                if (gameOverBoard.getLevel()>=5)
                        extra=" Great job!";
                if (gameOverBoard.getLevel()>=8)
                        extra=" Amazing!!";
                TwitterClient.tweet(String.format("Someone just played Tetris on the MIT Green Building! "+
                          "They cleared %d lines and lasted %1.1f seconds!%s #mittetris",
                          gameOverBoard.getNumCleared(),mitrisGame.getTime(),extra));

      }
      break;
    case GAME_END_1:
      animTime+=timestep;
      if (animTime>GAME_END_WAIT)
      {
        gameState=State.GAME_END_2;
        animTime=0;
        animTimeLastStep=0;
        if (gameOverBoard.getLevel()>=8)
        {
          gameState=State.GAME_END_ALT_2;
          circTime=new double[] {-100,-100,-100,-100,-100};
          circX=new double[5];
          circY=new double[5];
          circHue=new double[5];
          circPos=0;
        }
      }
      sendBoardToDisplay(gameOverBoard,display);
      break;
    case GAME_END_2:
      animTime+=timestep;
      if (animTime-animTimeLastStep>=ANIM_TIME_STEP)
      {
        animTimeLastStep=animTime;
        if (gameOverBoard.isBoardEmpty())
        {
          gameState=State.IDLE;
        }
        gameOverBoard=gameOverBoard.shiftBoardDown();
      }
      sendBoardToDisplay(gameOverBoard,display);
      break;
    case GAME_END_ALT_2:
      animTime+=timestep;
      if (animTime>=CIRC_ANIM_FADE_WAIT_TIME)
      {
        if (animTime<=CIRC_ANIM_FADE_WAIT_TIME+CIRC_ANIM_FADE_TIME)
        {
          double brightness=1-(animTime-CIRC_ANIM_FADE_WAIT_TIME)/CIRC_ANIM_FADE_TIME;
          sendBoardToDisplay(gameOverBoard,display,brightness);
        }
      }
      else
        sendBoardToDisplay(gameOverBoard,display);
      if (animTime-animTimeLastStep>=CIRC_ADD_TIME && animTime<=CIRC_ANIM_STOPADD_TIME)
      {
        animTimeLastStep=animTime;
        circX[circPos]=Math.random()*width;
        circY[circPos]=Math.random()*height;
        circTime[circPos]=animTime-0.3;
        circHue[circPos]=Math.random();
        circPos=(circPos+1)%circX.length;
      }
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
      for (int k=0; k<circX.length; k++)
      {
        g.setColor(new Color(Color.HSBtoRGB((float)circHue[k], 1, 1)));
        g.setStroke(new BasicStroke(1.5f));
        double circH=(animTime-circTime[k])*5;
        double circW=circH/display.getPixelAspect();
        g.draw(new Ellipse2D.Double(circX[k]-circW/2, circY[k]-circH/2, circW, circH));
      }
      if (animTime>=CIRC_ANIM_TOTAL_TIME)
        gameState=State.IDLE;
    }
View Full Code Here

public class TestRunner {
  public static void main(String[] args)
  {
    Display2D display=new GBDisplay();
    JFrame frame=new JFrame("test");
    DisplayPanel dPanel=new DisplayPanel(display);
    frame.add(dPanel);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
    frame.pack();
    frame.setVisible(true);
    TestPlugin plugin=new TestPlugin(display,15);
View Full Code Here

TOP

Related Classes of edu.mit.d54.plugins.test.TestRunner

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.