Exemple #1
0
  public void run() {
    MOVE_PREV = MOVE_DOWN;

    System.out.println("INIT!");
    map = new int[mapX][mapY];

    for (int i = 0; i < map.length; i++) {
      for (int j = 0; j < map[i].length; j++) {
        map[i][j] = 0;
      }
    }
    map[blockP.x][blockP.y] = 1;
    //    	map[0][20] = 1;

    StdDraw.setXscale(-1.0, 1.0);
    StdDraw.setYscale(-1.0, 1.0);

    // initial values

    // double vx = 0.015, vy = 0.023;     // velocity

    // main animation loop
    while (true) {

      drawGame();
      try {
        Thread.sleep(100);
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      movePrev();
    }
  }
Exemple #2
0
  public void drawGame() {
    StdDraw.clear(StdDraw.GRAY);

    // Set Color
    StdDraw.setPenColor(StdDraw.YELLOW);
    // Set Font
    setFont(new Font("SansSerif", Font.PLAIN, 32));
    // X, Y, String, rotation degree
    // Write String
    this.text(1 - 0.3, 1 - 0.1, blockP.x + ", " + blockP.y, 0);
    // Set Color
    StdDraw.setPenColor(StdDraw.ORANGE);
    // Set Font
    setFont(new Font("SansSerif", Font.PLAIN, 50));
    // Write String
    this.text(1 - 0.3, 1 - 0.3, "START!", 20);

    StdDraw.setPenColor(StdDraw.BLACK);

    for (int i = 0; i < map.length; i++) {
      for (int j = 0; j < map[i].length; j++) {
        if (map[i][j] > 0) {
          Point2D vLoc = map2Visual(i, j);
          System.out.println(i + ", " + j + ", " + vLoc);
          StdDraw.filledCircle(vLoc.getX(), vLoc.getY(), radius);
        }
      }
    }
  }
Exemple #3
0
 /** This method cannot be called directly. */
 public void mousePressed(MouseEvent e) {
   synchronized (mouseLock) {
     mouseX = StdDraw.userX(e.getX());
     mouseY = StdDraw.userY(e.getY());
     mousePressed = true;
     // System.out.println(mouseX+" ,"+mouseY);
   }
 }
Exemple #4
0
  public static void main(String[] args) {

    // set the scale of the coordinate system
    StdDraw game = new StdDraw();
    game.start();

    // System.out.println(game.map2Visual(99, 99));

  }
Exemple #5
0
 /** This method cannot be called directly. */
 public void actionPerformed(ActionEvent e) {
   FileDialog chooser =
       new FileDialog(StdDraw.frame, "Use a .png or .jpg extension", FileDialog.SAVE);
   chooser.setVisible(true);
   String filename = chooser.getFile();
   if (filename != null) {
     StdDraw.save(chooser.getDirectory() + File.separator + chooser.getFile());
   }
 }
Exemple #6
0
 /** This method cannot be called directly. */
 public void mouseMoved(MouseEvent e) {
   synchronized (mouseLock) {
     mouseX = StdDraw.userX(e.getX());
     mouseY = StdDraw.userY(e.getY());
   }
 }