• fullscreen
  • Monster_Moveit.pde
  • monster.pde
  • Monster mr; // Variable mr definieren, vom Datentyp monster
    
    void setup ()
    {
      smooth();
      size (600,600);
      background (255);
      frameRate(30);
    
      mr = new Monster();
    
    }
    
    
    
    void draw ()
    
    {
      background(255);
    
      mr.zeichnen();
    }
    
    void mouseMoved ()
    {
        mr.testMouseOver( mouseX, mouseY );
    }
    
    void mousePressed ()
    {
        mr.testMousePressed( mouseX, mouseY );   
    }
    
    void mouseDragged ()
    {
        mr.moveIfPressed( mouseX-pmouseX, mouseY-pmouseY );
    }
    
    void mouseReleased ()
    {
        mr.released();
    }
    
    
    class Monster
    {
    
      float xp, yp;
    
      boolean isOver;
      boolean isPressed;
    
    
      Monster ()
      {
        xp = random(width);
        yp = 20;
      }
    
      void zeichnen ()
      {
    
        translate (xp,yp);
        pushMatrix();
        translate (-50,120);
        beginShape();
        fill (0);
        vertex( 286.0 , 101.0 );
        bezierVertex( 286.0 , 101.0 , 234.0 , 97.0 , 195.0 , 131.0 );
        bezierVertex( 195.0 , 131.0 , 117.0 , 182.0 , 74.0 , 140.0 );
        vertex( 71.0 , 138.0 );
        bezierVertex( 71.0 , 138.0 , 92.0 , 178.0 , 135.0 , 178.0 );
        bezierVertex( 135.0 , 178.0 , 203.0 , 166.0 , 229.0 , 144.0 );
        bezierVertex( 229.0 , 144.0 , 265.0 , 123.0 , 291.0 , 121.0 );
        vertex( 289.0 , 119.0 );
        vertex( 288.0 , 102.0 );
        endShape();
        popMatrix();
    
        fill(0);
        rect (100,150,200,150);
    
    
        float y1 = map( mouseY,    0, height,    90, 10 );
    
    
        fill(255);
        ellipse (200,250,120,y1); // Mund
    
    
        fill(0);
        triangle (100,300,150,300,100,350);
    
        fill(0);
        triangle (250,300,300,300,300,350);
    
    
        fill(0);
        ellipse (120,150,80,80);
    
        fill(0);
        ellipse (280,150,80,80);
    
    
        float x1 = map( mouseX,    0, width,    100, 140 );
        float x2 = map( mouseX,    0, width,    270, 300 );
    
    
        fill(255);
        noStroke();
        ellipse (x2,150,40,40); //Pupille links
    
        fill(255);
        noStroke();
        ellipse (x1,150,40,40); // Pupille rechts
    
    
      }
    
      /////////////// Ende zeichnen
    
      void testMouseOver ( float mx , float my )
      {
        isOver = (mx > xp) && (mx < xp+300) && (my > yp) && (my < yp+300);
      }
    
    
      void testMousePressed ( float mx, float my )
      {
        testMouseOver( mx, my );
    
        isPressed = isOver;
      }
    
      void moveIfPressed ( float xd, float yd )
      {
        if ( isPressed )
        {
          xp += xd;
          yp += yd;
        }
      }
    
      void released ()
      {
        isPressed = false;
      }
    }
    
    
    
    
    

    code

    tweaks (0)

    about this sketch

    This sketch is running as Java applet, exported from Processing.

    license

    advertisement

    Carina Schweitzer

    monster moveit

    Add to Faves Me Likey@! 1
    You must login/register to add this sketch to your favorites.

    drag monster

    You need to login/register to comment.