├── Monster.pde ├── README.md ├── Star.pde └── monsters_in_space.pde /Monster.pde: -------------------------------------------------------------------------------- 1 | class Monster { 2 | int x; 3 | int y; 4 | int w; 5 | int h; 6 | int speedX; 7 | int speedY; 8 | color c; 9 | 10 | Monster(int tempX, int tempY, int tempW, int tempH, int tempSpeedX, int tempSpeedY, color tempC) { 11 | x = tempX; 12 | y = tempY; 13 | w = tempW; 14 | h = tempH; 15 | speedX = tempSpeedX; 16 | speedY = tempSpeedY; 17 | c = color(tempC); 18 | } 19 | 20 | void display() { //Display monster 21 | noStroke(); 22 | fill(c); 23 | rect(x, y, w, h); 24 | rect(x+w/5, y+h, w/5, h/6.66); 25 | rect(x+w/1.66, y+h, w/5, h/6.66); 26 | fill(255); 27 | ellipse(x+w/3, y+h/6.06, w/5, h/10); 28 | ellipse(x+w/1.515, y+h/6.06, w/5, h/10); 29 | fill(0); 30 | ellipse(x+w/3, y+h/6.06, w/10, h/20); 31 | ellipse(x+w/1.515, y+h/6.06, w/10, h/20); 32 | ellipse(x+w/2, y+h/1.33, w/1.66, h/6.66); 33 | } 34 | 35 | void speed() { 36 | x = x + speedX; //Location changes according to speed in x axis 37 | y = y + speedY; //Location changes according to speed in y axis 38 | } 39 | 40 | void bouncePosition() { 41 | if (x > width-100 || x == 0) { //Monster hits left and right borders 42 | speedX *= -1; //Speeds becomes opposite, monsters goes towards opposite direction 43 | } 44 | if (y > height-230 || y == 0) { //Monster hits top and bottom borders 45 | speedY *= -1; //Speeds becomes opposite, monsters goes towards opposite direction 46 | } 47 | } 48 | 49 | void bounceColor() { 50 | if (x == width-100 || x == 0) { //Monster hits left and right borders 51 | c = color(random(0, 255), random(0, 255), random(0, 255)); //Color is randomized 52 | } 53 | if (y == height-230 || y == 0) { //Monster hits top and bottom borders 54 | c = color(random(0, 255), random(0, 255), random(0, 255)); //Color is randomized 55 | } 56 | } 57 | 58 | void monsterLaunch() { 59 | if (mouseClick) { //Monster lanched to space when mouse clicked 60 | x = x + speedX; 61 | y = y + speedY; 62 | } 63 | } 64 | 65 | void move() { 66 | if (x == width + w) { 67 | x = 0 ; 68 | } 69 | if (x == 0 - w) { 70 | x = width; 71 | } 72 | if (y == height + h) { 73 | y = 0; 74 | } 75 | if (y == 0 - h) { 76 | y = height; 77 | } 78 | 79 | if (key == CODED) { //If arrow keys pressed, ball moves accordingly 80 | if (keyCode == UP) { 81 | y += - speedY ; 82 | } else if (keyCode == DOWN) { 83 | y += speedY; 84 | } else if (keyCode == LEFT) { 85 | x += -speedX; 86 | } else if (keyCode == RIGHT) { 87 | x += speedX; 88 | } 89 | } 90 | } 91 | 92 | void arms() { 93 | for (int i = y + 40; i < y + 200; i +=40) { //Draw monster arms 94 | fill(100, 200, 100); 95 | rect(x - 20, i, 140, 20); 96 | } 97 | } 98 | 99 | // VOID TRANSPARENT DOESN'T WORK (no matter which monster I choose, monster 1 becomes transparent when mouseClick = false) 100 | void transparent() { 101 | if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h) { //If mouse over monster , it becomes transparent 102 | fill(0, 0, 25); 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # monsters_in_space 2 | Monsters moving through space. Click for stars. 3 | -------------------------------------------------------------------------------- /Star.pde: -------------------------------------------------------------------------------- 1 | class Star { 2 | int starX; 3 | int starY; 4 | int starNumber; 5 | int starSize; 6 | Star(int tempStarSize, int tempStarNumber) { 7 | starNumber = tempStarNumber; 8 | starSize = tempStarSize; 9 | } 10 | 11 | void display() { 12 | if (mouseClick) { 13 | for (int i=0; i < starNumber; i +=1) { //Number of stars drawn at any time 14 | fill(150, 150, 0); 15 | starX = (int) random(0, width); //Draw stars in random coordinates 16 | starY = (int) random(0, height); 17 | circle(starX, starY, starSize); 18 | } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /monsters_in_space.pde: -------------------------------------------------------------------------------- 1 | // Monsters moving through space. Click mouse for stars. 2 | 3 | Monster monster1; 4 | Monster monster2; 5 | Monster monster3; 6 | Star spaceStars; 7 | boolean mouseClick = false; 8 | 9 | void setup() { 10 | size(600, 400); 11 | monster1 = new Monster(100, 100, 100, 200, 1, 1, color(100, 200, 100)); 12 | monster2 = new Monster(450, 430, 100, 200, 0, -1, color(100, 200, 100)); 13 | monster3 = new Monster(200, 100, 100, 200, 5, 5, color(100, 50, 255)); 14 | spaceStars = new Star(5, 40); 15 | } 16 | 17 | void draw() { 18 | background(0, 0, 25); 19 | spaceStars.display(); 20 | monster1.speed(); 21 | monster1.bouncePosition(); 22 | monster1.bounceColor(); 23 | monster1.display(); 24 | monster2.arms(); 25 | monster2.monsterLaunch(); 26 | monster2.display(); 27 | monster3.display(); 28 | monster3.bounceColor(); 29 | monster3.move(); //Arrows must be pressed once to move monster 30 | } 31 | 32 | void mousePressed() { //Star switch on when mouse clicks and monsterLaunch is enabled 33 | mouseClick = !mouseClick; 34 | } 35 | 36 | void keyPressed() { 37 | //monster3.move(); //Arrows must be pressed constantly to move monster 38 | } 39 | --------------------------------------------------------------------------------