/* Interactive Toy - Spaceship simulator By Matthew Burchat Started Project: 9/25/2018 Last Updated: 9/29/2018 Spaceship simulator Interactions: Enemy spaceships spawn randomly click mouse over the ship to destory it Course: Introduction to Media Computation Professor: Nicolas Hesler */ //Variables //Turret x and y locations float turretx = 150; float turrety = 375; //Random Enemy coordinates float RandomEnemyX = 0; float RandomEnemyY = 0; //Score count int intScore = 0; void setup() { size(400, 400); frameRate(60); noCursor(); // loop to find a random x coordinate for (int i = 0; i < 1; i++) { RandomEnemyX = random(50, 350); println(RandomEnemyX); } // loop to find a random y coordinate for (int i = 0; i < 1; i++) { RandomEnemyY = random(150, 300); println(RandomEnemyY); } } void draw() { background(20); //println(mouseX, mouseY); drawDeathstar(); drawPlanet(); drawEnemy(); drawTurret(); drawReticle(); } void drawReticle() { // Reticle stroke(255, 0, 0); //middle line(mouseX, mouseY - 10, mouseX, mouseY - 30); //bottom line(mouseX, mouseY + 10, mouseX, mouseY + 30); //left line(mouseX - 10, mouseY, mouseX - 30, mouseY); //right line(mouseX + 10, mouseY, mouseX + 30, mouseY); //top left two lines line(mouseX - 40, mouseY - 15, mouseX - 40, mouseY - 35); line(mouseX - 40, mouseY - 35, mouseX - 15, mouseY - 35); //top right two lines line(mouseX + 40, mouseY - 15, mouseX + 40, mouseY - 35); line(mouseX + 40, mouseY - 35, mouseX + 15, mouseY - 35); //bottom left two lines line(mouseX - 40, mouseY + 15, mouseX - 40, mouseY + 35); line(mouseX - 40, mouseY + 35, mouseX - 15, mouseY + 35); //bottom right two lines line(mouseX + 40, mouseY + 15, mouseX + 40, mouseY + 35); line(mouseX + 40, mouseY + 35, mouseX + 15, mouseY + 35); } void drawDeathstar() { //base noStroke(); fill(120); ellipseMode(CENTER); ellipse(50, 50, 125, 125); //grey plate fill(180); ellipseMode(CORNERS); ellipse(43, -4, 88, 42); } void drawPlanet() { //Planet at bottom right fill(86, 113, 81); ellipseMode(CENTER); ellipse(420, 470, 400, 400); } void drawTurret() { fill(180); stroke(0); //left barrel rect(turretx + 30, turrety - 75, 5, 45); rect(turretx + 27, turrety - 80, 10, 10); //right barrel rect(turretx + 65, turrety - 75, 5, 45); rect(turretx + 63, turrety - 80, 10, 10); //base of turret rect(turretx, turrety, 100, 35); //head of turret quad(turretx + 25, turrety - 40, turretx + 75, turrety - 40, turretx + 100, turrety, turretx, turrety); } void drawEnemy() { //Int variables used to transfer the float variables to int so they can be used in the x and y of a shape int i1 = int(RandomEnemyX); int i2 = int(RandomEnemyY); //Used predetermined variables to test things //int i1 = 210; //int i2 = 210; //outer center circle fill(165, 166, 173); ellipse(i1, i2, 30, 30); //inner center circle fill(30, 22, 22); ellipse(i1, i2, 20, 20); //left wing and base connector fill(165, 166, 173); rect(i1 - 25, i2 - 3, 10, 5); //right wing and base connector rect(i1 + 15.2, i2 - 3, 10, 5); //left wing rect(i1 - 28, i2 - 30, 5, 58); //ring wing rect(i1 + 24, i2 - 30, 5, 58); } void mousePressed() { int i1 = int(RandomEnemyX); int i2 = int(RandomEnemyY); intScore = intScore + 1; //Checks if mouse coordinates are over the enemy if (mouseX >= i1 - 28 && mouseY >= i2 - 30) { if (mouseX <= i1 + 29 && mouseY <= i2 +28) { println("hit! Score:"+intScore); // loop to find a random x coordinate for (int i = 0; i < 1; i++) { RandomEnemyX = random(50, 350); //println(RandomEnemyX); } // loop to find a random y coordinate for (int i = 0; i < 1; i++) { RandomEnemyY = random(150, 300); //println(RandomEnemyY); } drawDeathstar(); drawPlanet(); drawTurret(); drawEnemy(); drawReticle(); } } }