示例#1
0
 public void keyReleased(KeyEvent e) {
   int key = e.getKeyCode();
   if (key == KeyEvent.VK_RIGHT) {
     wrinkle.unGoRight();
   } else if (key == KeyEvent.VK_LEFT) {
     wrinkle.unGoLeft();
   }
 }
示例#2
0
  public void keyPressed(KeyEvent e) {
    int key = e.getKeyCode();
    if (key == KeyEvent.VK_SPACE) {
      wrinkle.jump();

    } else if (key == KeyEvent.VK_RIGHT) {
      wrinkle.goRight();
    } else if (key == KeyEvent.VK_LEFT) {
      wrinkle.goLeft();
    }
  }
示例#3
0
  public Drawpan() {
    setIgnoreRepaint(true);
    addKeyListener(this);
    setFocusable(true);

    terrains = new Vector<Terrain>();

    background1 = new BufferedImage(Global.WinX, Global.WinY, BufferedImage.TYPE_INT_RGB);
    background2 = new BufferedImage(Global.WinX, Global.WinY, BufferedImage.TYPE_INT_RGB);
    background3 = new BufferedImage(Global.WinX, Global.WinY, BufferedImage.TYPE_INT_RGB);
    foreground = new BufferedImage(Global.WinX, Global.WinY, BufferedImage.TYPE_INT_RGB);
    buff = new BufferedImage(Global.WinX, Global.WinY, BufferedImage.TYPE_INT_RGB);

    wrinkle = new Wrinkle(0, Global.WinY - 200);

    terrains.add(new Terrain(0, Global.WinY - 200 + wrinkle.getHeight(), 400, 400, Color.GREEN));
    terrains.add(new Terrain(500, Global.WinY - 200 + wrinkle.getHeight(), 300, 400, Color.RED));
    terrains.add(new Terrain(300, 400, 100, 100));
    terrains.add(new Terrain(200, 200, 50, 50));
  }
示例#4
0
  boolean go() {

    wrinkle.update(terrains);
    drawToBuff();
    drawToPanel();
    try {
      Thread.sleep(Global.timeStep);
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
    return true;
  }
示例#5
0
  void drawToBuff() {

    Graphics2D g = (Graphics2D) buff.createGraphics();
    // g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
    g.setStroke(new BasicStroke(5));
    g.setColor(Color.CYAN);

    g.fillRect(0, 0, Global.WinX, Global.WinY);
    for (int i = 0; i < terrains.size(); ++i) {
      terrains.get(i).draw(g);
    }
    wrinkle.draw(g);
  }