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
  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) {}
  }