OO_Monster

class Monster { int x; int y; int xspeed; int yspeed; Monster { x = 200; y = 200; xspeed = 5; yspeed = 5; stroke(200, 200, 20); } void display { line(x, y, x, y+100); line(x, y+100, x-50, y+150); line(x, y+100, x+50, y+150); line(x-50, y+50, x+50, y+50); ellipse(x, y-30, 60, 60); line(x-15, y-40, x-10, y-30); line(x+15, y-30, x+20, y-40); } void moveX { x = x + xspeed; if (x > width) { xspeed = xspeed*-1; } else if (x < 0) { xspeed = xspeed*-1; } } void moveY { y = y + yspeed; if (y > height) { yspeed = yspeed*-1; } else if (y < 0) { yspeed = yspeed*-1; } } void chase { x = mouseX; y = mouseY; } void follow(int followSpeed) { if (x < mouseX) { if ((x + followSpeed) < mouseX){ x = x + followSpeed; } else { x = mouseX; } } else if (x > mouseX) { if ((x - followSpeed) > mouseX) { x = x - followSpeed; } else { x = mouseX; } } if (y < mouseY) { if ((y + followSpeed) < mouseY) { y = y + followSpeed; } else { y = mouseY; } } else if (y > mouseY) { if ((y - followSpeed) > mouseY) { y = y - followSpeed; } else { y = mouseY; } } } }

Monster myMonster; void setup { size(400,400); myMonster = new Monster; } void draw { background(5, 60, 90); myMonster.follow(5); myMonster.display; }