Beth - M

By Elizabeth
//click to make the monsters scatter. Monster m; int num = 15; Monster[] monsters; void setup() { size(600, 400); smooth(); monsters = new Monster[num]; for (int i = 0; i < num; i++) { monsters[i] = new Monster(100, 200, .50, .50, "monster.png"); } } void draw() { background(255); for (int i = 0; i < num; i++) { monsters[i].move(mouseX, mouseY); monsters[i].display(); } } class Monster{ PImage monster; float x; float y; float speedX = 1.0; float speedY = 0.4; Monster(float inx, float iny, float inspeedX, float inspeedY, String imagename) { x = inx; y = iny; speedX = inspeedX; speedY = inspeedY; monster = loadImage(imagename); } void move(float mX, float mY) { x = mX; y = mY; } void display(){ if (mousePressed == true) { x = random(0, 600); y = random(0, 400); image(monster, x, y, 127, 88); } else if(mousePressed == false) { x = random(mouseX, mouseX + 150); y = random(mouseY, mouseY + 150); image(monster, x, y, 127, 88); } } }

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*