Advertisement
Guest User

Pyry

a guest
Feb 21st, 2009
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | None | 0 0
  1. PImage teddy;
  2.  
  3. float xpos;
  4. float ypos;
  5. float drag = 30.0;
  6.  
  7. void setup()
  8. {
  9.   size(200,200);
  10.   teddy = loadImage("teddy.gif");
  11.   xpos = width/2;
  12.   ypos = height/2;
  13.   frameRate(60);
  14. }
  15.  
  16. void draw()
  17. {
  18.   background(102);
  19.  
  20.   float difx = mouseX - xpos-teddy.width/2;
  21.   if(abs(difx) > 1.0) {
  22.     xpos = xpos + difx/drag;
  23.     xpos = constrain(xpos, 0, width-teddy.width);
  24.   }  
  25.  
  26.   float dify = mouseY - ypos-teddy.height/2;
  27.   if(abs(dify) > 1.0) {
  28.     ypos = ypos + dify/drag;
  29.     ypos = constrain(ypos, 0, height-teddy.height);
  30.   }  
  31.  
  32.   // Display the sprite at the position xpos, ypos
  33.   image(teddy, xpos, ypos);
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement