Advertisement
lgfjj

NoExit PG1

Mar 4th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. package prgAss1package;
  2. import objectdraw.*;
  3.  
  4. public class NoExit extends WindowController
  5. {
  6.  
  7. private FramedRect box;
  8. private FramedOval face;
  9. private Line mouth;
  10. private FramedOval eye;
  11. private FramedOval eye2;
  12.  
  13. private Location lastPoint;
  14.  
  15. private boolean faceGrabbed = false;
  16.  
  17.  
  18.  
  19. public void begin()
  20. {
  21. // x y width height canvas
  22. box = new FramedRect (100,100,200,300,canvas);
  23. face = new FramedOval (200,200,50,50,canvas);
  24. mouth = new Line (217,235,232,235,canvas);
  25. eye = new FramedOval (210,210,10,10,canvas);
  26. eye2 = new FramedOval (230,210,10,10,canvas);
  27. }
  28.  
  29. public void onMouseDrag(Location point)
  30. {
  31. if ( faceGrabbed && box.contains(point))
  32. {
  33.  
  34.  
  35. if (!(face.getX()<=100) && !(face.getX()>=250) && !(face.getY()<=100) && !(face.getY() >=350))
  36. {
  37. face.move(point.getX()-lastPoint.getX(), point.getY()-lastPoint.getY());
  38. eye.move( point.getX() - lastPoint.getX(),point.getY() - lastPoint.getY() );
  39. eye2.move( point.getX() - lastPoint.getX(),point.getY() - lastPoint.getY() );
  40. mouth.move( point.getX() - lastPoint.getX(),point.getY() - lastPoint.getY() );
  41. lastPoint=point;
  42. }
  43.  
  44. else if (face.getX()<=100)
  45. {
  46. face.moveTo(face.getX() + 1,face.getY());
  47. eye.moveTo(eye.getX() + 1, eye.getY());
  48. eye2.moveTo(eye2.getX() + 1, eye2.getY());
  49. mouth.move(1,0);
  50. lastPoint = point;
  51. }
  52.  
  53. else if (face.getY()<=100)
  54. {
  55. face.moveTo(face.getX(),face.getY() + 1);
  56. eye.moveTo(eye.getX(), eye.getY() + 1);
  57. eye2.moveTo(eye2.getX(), eye2.getY() + 1);
  58. mouth.move(0,1);
  59.  
  60. lastPoint = point;
  61. }
  62.  
  63. else if ((face.getX() + 50) >=250)
  64. {
  65. face.moveTo(face.getX()-1,face.getY());
  66. eye.moveTo(eye.getX()-1, eye.getY());
  67. eye2.moveTo(eye2.getX()-1, eye2.getY());
  68. mouth.move(-1,0);
  69. lastPoint = point;
  70. }
  71.  
  72. else if ((face.getY() + 50) >= 350)
  73. {
  74. face.moveTo(face.getX(),face.getY()-1);
  75. eye.moveTo(eye.getX(), eye.getY()-1);
  76. eye2.moveTo(eye2.getX(), eye2.getY()-1);
  77. mouth.move(0,-1);
  78. lastPoint = point;
  79. }
  80.  
  81. }
  82. }
  83.  
  84. public void onMousePress(Location point)
  85. {
  86. if (face.contains(point))
  87. {
  88. faceGrabbed = true;
  89. lastPoint = point;
  90. }
  91. faceGrabbed = face.contains(point);
  92.  
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement