Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //music is Silk Lingerie by Ghost Data
- //Start screen BG is from pixabay labeled for noncommercial reuse with modification (I recolored it to match the color palette)
- import processing.sound.*;
- SoundFile music;
- SoundFile laser;
- import interfascia.*;
- GUIController c;
- IFButton startButton;
- IFLabel l;
- PImage startBG; //Background image vaiable
- boolean startbg = true; // this makes the BG image disappear after the button is pressed
- //star arrays for the X, Y, and radius
- int [] xLoc = {140, 100, 160, 1000, 1010, 230, 130, 40, 1040, 910, 60, 1030, 10, 930, 30, 940, 1060, 960, 900, 200, 30};
- int [] yLoc = {160, 640, 10, 610, 530, 140, 100, 230, 540, 40, 600, 60, 710, 130, 510, 200, 660, 30, 630, 560, 60};
- int [] radius = {20, 10, 18, 13, 6, 7, 9, 5, 8, 15, 20, 17, 14, 16, 2, 20, 19, 4, 12, 11, 20};
- //using mouse fuctions example from processing so the alien can pick up and move the galaxy
- float GalaxyX; //Where the galaxy X is
- float GalaxyY; //Where the galaxy Y is
- int circleSize = 50; //how large the initial center circle is
- boolean overGalaxy = false; //if the mouse isn't over the galaxy this is false
- boolean locked = false; //this keeps the galaxy still until you move it
- float xOffset = 0.0;
- float yOffset = 0.0;
- Comet [] Comets = new Comet [10]; //how many comets spawn
- void setup() {
- size (1280, 813); //size of canvas
- GalaxyX = int (random (1000)); //the galaxy X and Y will spawn at a random int
- GalaxyY = int (random (700));
- music = new SoundFile(this, "silkLingerie.wav"); //music file
- music.loop(); //the music will loop
- music.amp(.5);
- for (int num = 0; num < 10; num++) { //A loop so it will spawn comets until it reaches 10
- Comets[num] = new Comet (random(1280), random(813), 15, random(-2, 2)); //where the comets will spawn is random
- }
- c = new GUIController (this);
- startButton = new IFButton ("Start", 620, 450, 100, 40); //name on the button,X, Y, width, height
- startButton.addActionListener(this);
- c.add(startButton);
- }
- void draw() {
- Galaxy(); //calling galaxy function
- spaceShip(); //calling spaceship function
- Stars(); //calling star function
- for (int num = 0; num < 10; num++) { //telling the comets to spawn until they reach 10
- Comets[num].update();
- }
- startbg(); //start screen
- }
- void actionPerformed (GUIEvent e) {
- if (e.getSource() == startButton) {
- noCursor(); //cursor disappears once you click start
- startbg = false; //the background turns off
- laser = new SoundFile(this, "Laser_Shoot.wav"); //this sound plays
- laser.play();
- startButton.setPosition(2000, 2000); //makes the button go off screen
- }
- }
- void startbg() {
- if (startbg == true) { //if the boolean is true then
- textSize(60); //size of text
- startBG = loadImage ("space.jpg");//load the bg image
- background(startBG);//present the image
- fill (255, 50, 50);//text color
- text("Galaxy Mover", 500, 300);//what the text says, x position, Y position
- }
- }
- void Galaxy() {
- //everything for is to find out where the edge of the galaxy is so you can click it
- if (mouseX > GalaxyX - circleSize && mouseX < GalaxyX + circleSize && mouseY > GalaxyY - circleSize && mouseY < GalaxyY + circleSize) {
- overGalaxy = true; //if all the requirements above are met then you are over the galaxy
- }
- if (!locked) { //if the galaxy is not locked
- //color variables
- color Yellow2 = color (#FFD699);
- color Brown = color (#FF9999);
- color Orange = color (#F090C8);
- color Red = color (#CB8DEB);
- color Space = color (#E394A7);
- //the fill and size of all the cirlces for the galaxy when mouse is not pressed
- background (Space);
- fill (Red);
- circle (GalaxyX, GalaxyY, circleSize + 400);
- fill (Orange);
- circle (GalaxyX, GalaxyY, circleSize + 250);
- fill (Brown);
- circle (GalaxyX, GalaxyY, circleSize + 100);
- fill (Yellow2);
- circle (GalaxyX, GalaxyY, circleSize);
- } else { //if it is locked
- //color variables
- color Yellow = color (#FFD699);
- color Raspberry = color (#F1C5FB);
- color Pinky = color (#E0D9FB);
- color Purple = color (#C9D6FA);
- color Space = color (#E394A7);
- //the fill and size of all the cirlces for the galaxy once mouse is pressed
- background (Space);
- fill (Raspberry);
- circle (GalaxyX, GalaxyY, circleSize + 400);
- fill (Pinky);
- circle (GalaxyX, GalaxyY, circleSize + 250);
- fill (Purple);
- circle (GalaxyX, GalaxyY, circleSize + 100);
- fill (Yellow);
- circle (GalaxyX, GalaxyY, circleSize);
- overGalaxy = false; //changes over galaxy to false for movement
- }
- }
- //to move the galaxy around
- void mousePressed() {
- if (overGalaxy) { //over the galaxy
- locked = true; //can't move galaxy
- Galaxy(); //plays funtion Galaxy when you press over the galaxy
- laser = new SoundFile(this, "Laser_Shoot.wav"); //load sound
- laser.play(); //sound plays
- } else {
- locked = false; //unlocked if you click it
- }
- xOffset = mouseX - GalaxyX; //of offset is = to the mouse position minus the galaxy center
- yOffset = mouseY - GalaxyY;
- }
- void mouseDragged() {
- if (locked) { //if boolean locked is false
- GalaxyX = mouseX - xOffset; //the galaxy x is the mouse location - the amount you're offset from center
- GalaxyY = mouseY - yOffset; //the galaxy y is the mouse location - the amount you're offset from center
- }
- }
- void mouseReleased() {
- locked = false; //let go of the galaxy
- }
- //other objects
- void spaceShip() {
- fill (190, 255, 190); //fill with lime green
- circle (mouseX, mouseY-15, 30); //mouses x and -15 the y are a circle with diameter 30
- fill (0, 0, 0); // fill with black
- ellipse (mouseX, mouseY, 80, 30); //the mouses x and y become an ellipse of 80 width, 30 height
- }
- void Stars() {
- int n = 0; //int n starts at 0
- while (n < 19) { //while n is less than 19
- //color (stars);
- fill (255, 255, 255); //fill with this color
- noStroke(); //no stroke
- //AT THESE LOCATIONS
- circle (xLoc[n], yLoc[n], radius[n]);
- circle (-yLoc[n], -xLoc[n], radius[n]);
- circle (2 * yLoc[n], 2 * xLoc[n], radius[n]);
- circle (2 / xLoc[n], 2 / yLoc[n], radius[n]);
- circle (2 * -yLoc[n], 2 * -xLoc[n], radius[n]);
- circle (2 * -xLoc[n], 2 * -yLoc[n], radius[n]);
- circle (1.5 * -xLoc[n], 1.5 * -yLoc[n], radius[n]);
- circle (1.5 / yLoc[n], 1.5 / xLoc[n], radius[n]);
- n = n + 1; // and add 1 to n
- }
- }
- //used ball example for this
- class Comet {
- //data
- float cometSize;
- float shakeSpeed;
- float xPos = 0; //xpos and ypos are set to 0
- float yPos = 0;
- //constructor
- Comet (float x, float y, float paramSize, float paramSpeed) {
- cometSize = paramSize; //cometsize is the same as paramsize
- shakeSpeed = paramSpeed; //shakespeed is = paramspeed
- xPos = x; //the variable for xpos is = x
- yPos = y; //the variable for ypos is = y
- }
- //function
- void update() {
- noStroke(); //the cirlces don't get a stroke
- circle (xPos, yPos, cometSize); //what the comets are made from
- xPos = xPos + shakeSpeed;
- if (xPos > width || xPos < 0) { //if the x postion greater than the canvas width or the x position is less than 0
- shakeSpeed *= -1; //the shake speed goes down by -1
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement