Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package prgAss1package;
- import objectdraw.*;
- public class NoExit extends WindowController
- {
- private FramedRect box;
- private FramedOval face;
- private Line mouth;
- private FramedOval eye;
- private FramedOval eye2;
- private Location lastPoint;
- private boolean faceGrabbed = false;
- public void begin()
- {
- // x y width height canvas
- box = new FramedRect (100,100,200,300,canvas);
- face = new FramedOval (200,200,50,50,canvas);
- mouth = new Line (217,235,232,235,canvas);
- eye = new FramedOval (210,210,10,10,canvas);
- eye2 = new FramedOval (230,210,10,10,canvas);
- }
- public void onMouseDrag(Location point)
- {
- if ( faceGrabbed && box.contains(point))
- {
- if (!(face.getX()<=100) && !(face.getX()>=250) && !(face.getY()<=100) && !(face.getY() >=350))
- {
- face.move(point.getX()-lastPoint.getX(), point.getY()-lastPoint.getY());
- eye.move( point.getX() - lastPoint.getX(),point.getY() - lastPoint.getY() );
- eye2.move( point.getX() - lastPoint.getX(),point.getY() - lastPoint.getY() );
- mouth.move( point.getX() - lastPoint.getX(),point.getY() - lastPoint.getY() );
- lastPoint=point;
- }
- else if (face.getX()<=100)
- {
- face.moveTo(face.getX() + 1,face.getY());
- eye.moveTo(eye.getX() + 1, eye.getY());
- eye2.moveTo(eye2.getX() + 1, eye2.getY());
- mouth.move(1,0);
- lastPoint = point;
- }
- else if (face.getY()<=100)
- {
- face.moveTo(face.getX(),face.getY() + 1);
- eye.moveTo(eye.getX(), eye.getY() + 1);
- eye2.moveTo(eye2.getX(), eye2.getY() + 1);
- mouth.move(0,1);
- lastPoint = point;
- }
- else if ((face.getX() + 50) >=250)
- {
- face.moveTo(face.getX()-1,face.getY());
- eye.moveTo(eye.getX()-1, eye.getY());
- eye2.moveTo(eye2.getX()-1, eye2.getY());
- mouth.move(-1,0);
- lastPoint = point;
- }
- else if ((face.getY() + 50) >= 350)
- {
- face.moveTo(face.getX(),face.getY()-1);
- eye.moveTo(eye.getX(), eye.getY()-1);
- eye2.moveTo(eye2.getX(), eye2.getY()-1);
- mouth.move(0,-1);
- lastPoint = point;
- }
- }
- }
- public void onMousePress(Location point)
- {
- if (face.contains(point))
- {
- faceGrabbed = true;
- lastPoint = point;
- }
- faceGrabbed = face.contains(point);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement