Ejemplo n.º 1
0
	public void paint(Graphics g){ //Graphics is a crayon box; Graphics2d is like an art kit
		BufferedImage image = new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);
		Graphics2D g2 = (Graphics2D)image.getGraphics();
		//Graphics2D g2 = (Graphics2D)g;
		g2.setColor(Color.white);
		g2.fillRect(0,0,width,height);
		g2.setColor(Color.pink);
		g2.drawOval(50, 50, width-100, height-100);
		g2.drawOval(175, 175, width-490, height-490);
		g2.drawOval(375, 175, width-490, height-490);
		g2.drawLine(0,10,height,0);
		g2.drawArc(175, 250, 250, 130, 200, 90);
		Hero hero2 = new Hero("Dorami", "/images/heroes/Dorami.jpg",100,100);

		if(Math.abs(hero1.getX()-hero2.getX()) + Math.abs(hero1.getY()-hero2.getY()) <20  ){
			itemPickedUp=true;
		}
		if(!itemPickedUp){g2.drawImage(hero2.getImage(), hero2.getX(), hero2.getY(), null);}
		g2.drawImage(hero1.getImage(), hero1.getX(), hero1.getY(), null);
		//g2.fillOval(50,100,200,100);
		//g2.drawArc(50, 300, 200, 100,0,90);
	/*	int c =0;
		int margin =2;
		int squareD =20;
		for(int x=0; x<width; x+= squareD +margin){
			for(int y=0; y<height; y+= squareD+margin){
				if(c<255) c++;
				else c=0;
				Color local = new Color((int) Math.floor(Math.random() * 256),(int) Math.floor(Math.random() * 256),c);
				g2.setColor(local);
				g2.fillRect(x,y,squareD,squareD);
			}
		}*/
		g.drawImage(image, 0, 0, null);
	}
Ejemplo n.º 2
0
  private void setupPlayer2() {
    listener2 = mock(EventListener.class);
    player2 = new Player(listener2, game);
    joystick2 = player2.getJoystick();

    dice(hero2.getX(), hero2.getY());

    game.newGame(player2);
    hero2.init(game);
  }
Ejemplo n.º 3
0
  private void setupPlayer1() {
    listener1 = mock(EventListener.class);
    player1 = new Player(listener1, game);
    joystick1 = player1.getJoystick();

    dice(hero1.getX(), hero1.getY());

    game.newGame(player1);
    hero1.init(game);
  }
Ejemplo n.º 4
0
  public void paint(Graphics g) {
    super.paint(g);

    // 画出我的坦克
    g.fillRect(0, 0, 400, 300); // 确定区域为400 300 背景为黑色值

    // 使用画坦克方法画出坦克
    this.drawTank(hero.getX(), hero.getY(), g, hero.getDirect(), 0);

    // 画出敌人的坦克
    for (int i = 0; i < ets.size(); i++) {
      this.drawTank(ets.get(i).getX(), ets.get(i).getY(), g, ets.get(i).getDirect(), 1);
    }
  }
Ejemplo n.º 5
0
  //	重写paint方法
  public void paint(Graphics g) {
    super.paint(g);
    //		float lineWidth = 3.0f;
    //	    ((Graphics2D)g).setStroke(new BasicStroke(lineWidth));
    //		将坦克的活动区域填充为默认黑色
    g.fillRect(0, 0, 800, 600);
    this.drawTank(hero.getX(), hero.getY(), g, hero.getDirection(), 1);

    for (int i = 0; i < hero.bombs.size(); i++) {
      Bomb myBomb = hero.bombs.get(i);
      // 画出一颗子弹
      if (myBomb != null && myBomb.isLive == true) {
        //			float lineWidth = 2.0f;
        //			((Graphics2D) g).setStroke(new BasicStroke(lineWidth));//设置线条为粗线
        g.draw3DRect(myBomb.x, myBomb.y, 2, 2, true);
      }
      if (myBomb.isLive == false) {
        hero.bombs.remove(myBomb);
      }
    }
    //		画出爆炸
    for (int i = 0; i < baozhas.size(); i++) {
      BaoZha bz = baozhas.get(i);
      System.out.println("baozhas.size()= " + baozhas.size());
      if (bz.life > 5) {
        g.drawImage(image3, bz.x, bz.y, 30, 30, this);
      } else if (bz.life > 3) {
        g.drawImage(image2, bz.x, bz.y, 30, 30, this);
      } else {
        g.drawImage(image1, bz.x, bz.y, 30, 30, this);
      }
      bz.liftDown();
      if (bz.life == 0) {
        baozhas.remove(bz);
      }
    }

    //		画出敌人的坦克
    for (int i = 0; i < ets.size(); i++) {
      EnemyTank et = ets.get(i);
      if (et.isLive) {

        this.drawTank(et.getX(), et.getY(), g, et.getDirection(), 0);
      }
    }
  }
Ejemplo n.º 6
0
  public void paint(Graphics g) {
    // Graphics is a crayon box
    // Graphics2d is like an art kit
    // Random random = new Random();
    BufferedImage image = new BufferedImage(width, length, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = (Graphics2D) g;
    /*g2.setColor(Color.white);
    g2.fillRect(0, 0, width, length);
    g2.setColor(Color.red);
    g2.fillOval(50, 100, 200, 100);
    g2.setColor(Color.blue);
    g2.drawOval(50, 100, 200, 100);
    //x, y, width, length, startDEG, lengthDEG
    g2.drawArc(50, 300, 200, 100, 0, 90);
    //string, x, y
    g2.drawString("String", 300, 300);
    //lines: startX, startY, endX, endY
    g2.drawLine(0, 0, width, length);*/
    g2.setColor(new Color(0, 255, 255));
    g2.fillRect(0, 0, width, length);
    // paintLandscape(g2);
    g2.drawImage(girl.getImage(), girl.getX(), girl.getY(), null);
    itemPickedUp = false;
    /*int ovalD = 50;
    int margin = 30;
    for(int x = 0; x < width; x+=ovalD+margin) {
    	g2.setColor(Color.white);
    	g2.fillOval(x, 50, ovalD, 20);
    }
    g2.setColor(new Color(255, 204, 0));
    g2.fillRect(0, 150, width, length);
    for(int num = 0; num < 7; num++) {
    	int x = random.nextInt(width - 0 + 1) + 0;
    	int y = random.nextInt(length - 150) + 150;
    	g2.setColor(Color.green);
    	g2.fillRect(x,y, 50, 100);
    }
    /*g2.setColor(Color.blue);
    int squareD = 20;
    int margin = 2;
    for (int x = 0; x < width; x += squareD + margin) {
    	for (int y = 0; y < length; y += squareD + margin) {
    		c++;
    		if(c > 255) {
    			c = 0;
    			g2.setColor(new Color(0, 0, c));
    			g2.fillRect(x, y, squareD, squareD);
    		}
    		else {
    			g2.setColor(new Color(0, 0, c));
    			g2.fillRect(x, y, squareD, squareD);
    		}

    	}

    }*/
    // draw the buffered image on the canvas
    /**
     * if (Math.abs(girl.getX()-potion.getX()) + Math.abs(girl.getY()-potion.getY()) <10){
     * itemPickedUp=true; }*
     */
    g.drawImage(image, 0, 0, null);
    if (itemPickedUp) {}
  }