Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.22 KB | None | 0 0
  1. //music is Silk Lingerie by Ghost Data
  2. //Start screen BG is from pixabay labeled for noncommercial reuse with modification (I recolored it to match the color palette)
  3.  
  4. import processing.sound.*;
  5. SoundFile music;
  6. SoundFile laser;
  7. import interfascia.*;
  8. GUIController c;
  9. IFButton startButton;
  10. IFLabel l;
  11.  
  12. PImage startBG; //Background image vaiable
  13. boolean startbg = true; // this makes the BG image disappear after the button is pressed
  14.  
  15.  
  16. //star arrays for the X, Y, and radius
  17. int [] xLoc = {140, 100, 160, 1000, 1010, 230, 130, 40, 1040, 910, 60, 1030, 10, 930, 30, 940, 1060, 960, 900, 200, 30};
  18. int [] yLoc = {160, 640, 10, 610, 530, 140, 100, 230, 540, 40, 600, 60, 710, 130, 510, 200, 660, 30, 630, 560, 60};
  19. int [] radius = {20, 10, 18, 13, 6, 7, 9, 5, 8, 15, 20, 17, 14, 16, 2, 20, 19, 4, 12, 11, 20};
  20.  
  21. //using mouse fuctions example from processing so the alien can pick up and move the galaxy
  22. float GalaxyX; //Where the galaxy X is
  23. float GalaxyY; //Where the galaxy Y is
  24. int circleSize = 50; //how large the initial center circle is
  25. boolean overGalaxy = false; //if the mouse isn't over the galaxy this is false
  26. boolean locked = false; //this keeps the galaxy still until you move it
  27. float xOffset = 0.0;
  28. float yOffset = 0.0;
  29.  
  30. Comet [] Comets = new Comet [10]; //how many comets spawn
  31.  
  32. void setup() {
  33. size (1280, 813); //size of canvas
  34. GalaxyX = int (random (1000)); //the galaxy X and Y will spawn at a random int
  35. GalaxyY = int (random (700));
  36.  
  37. music = new SoundFile(this, "silkLingerie.wav"); //music file
  38. music.loop(); //the music will loop
  39. music.amp(.5);
  40.  
  41. for (int num = 0; num < 10; num++) { //A loop so it will spawn comets until it reaches 10
  42. Comets[num] = new Comet (random(1280), random(813), 15, random(-2, 2)); //where the comets will spawn is random
  43. }
  44.  
  45. c = new GUIController (this);
  46. startButton = new IFButton ("Start", 620, 450, 100, 40); //name on the button,X, Y, width, height
  47. startButton.addActionListener(this);
  48. c.add(startButton);
  49. }
  50.  
  51. void draw() {
  52. Galaxy(); //calling galaxy function
  53. spaceShip(); //calling spaceship function
  54. Stars(); //calling star function
  55. for (int num = 0; num < 10; num++) { //telling the comets to spawn until they reach 10
  56. Comets[num].update();
  57. }
  58. startbg(); //start screen
  59. }
  60.  
  61. void actionPerformed (GUIEvent e) {
  62. if (e.getSource() == startButton) {
  63. noCursor(); //cursor disappears once you click start
  64. startbg = false; //the background turns off
  65. laser = new SoundFile(this, "Laser_Shoot.wav"); //this sound plays
  66. laser.play();
  67. startButton.setPosition(2000, 2000); //makes the button go off screen
  68. }
  69. }
  70.  
  71. void startbg() {
  72. if (startbg == true) { //if the boolean is true then
  73. textSize(60); //size of text
  74. startBG = loadImage ("space.jpg");//load the bg image
  75. background(startBG);//present the image
  76. fill (255, 50, 50);//text color
  77. text("Galaxy Mover", 500, 300);//what the text says, x position, Y position
  78. }
  79. }
  80.  
  81. void Galaxy() {
  82. //everything for is to find out where the edge of the galaxy is so you can click it
  83. if (mouseX > GalaxyX - circleSize && mouseX < GalaxyX + circleSize && mouseY > GalaxyY - circleSize && mouseY < GalaxyY + circleSize) {
  84. overGalaxy = true; //if all the requirements above are met then you are over the galaxy
  85. }
  86. if (!locked) { //if the galaxy is not locked
  87. //color variables
  88. color Yellow2 = color (#FFD699);
  89. color Brown = color (#FF9999);
  90. color Orange = color (#F090C8);
  91. color Red = color (#CB8DEB);
  92. color Space = color (#E394A7);
  93. //the fill and size of all the cirlces for the galaxy when mouse is not pressed
  94. background (Space);
  95. fill (Red);
  96. circle (GalaxyX, GalaxyY, circleSize + 400);
  97. fill (Orange);
  98. circle (GalaxyX, GalaxyY, circleSize + 250);
  99. fill (Brown);
  100. circle (GalaxyX, GalaxyY, circleSize + 100);
  101. fill (Yellow2);
  102. circle (GalaxyX, GalaxyY, circleSize);
  103. } else { //if it is locked
  104. //color variables
  105. color Yellow = color (#FFD699);
  106. color Raspberry = color (#F1C5FB);
  107. color Pinky = color (#E0D9FB);
  108. color Purple = color (#C9D6FA);
  109. color Space = color (#E394A7);
  110. //the fill and size of all the cirlces for the galaxy once mouse is pressed
  111. background (Space);
  112. fill (Raspberry);
  113. circle (GalaxyX, GalaxyY, circleSize + 400);
  114. fill (Pinky);
  115. circle (GalaxyX, GalaxyY, circleSize + 250);
  116. fill (Purple);
  117. circle (GalaxyX, GalaxyY, circleSize + 100);
  118. fill (Yellow);
  119. circle (GalaxyX, GalaxyY, circleSize);
  120. overGalaxy = false; //changes over galaxy to false for movement
  121. }
  122. }
  123. //to move the galaxy around
  124. void mousePressed() {
  125. if (overGalaxy) { //over the galaxy
  126. locked = true; //can't move galaxy
  127. Galaxy(); //plays funtion Galaxy when you press over the galaxy
  128. laser = new SoundFile(this, "Laser_Shoot.wav"); //load sound
  129. laser.play(); //sound plays
  130. } else {
  131. locked = false; //unlocked if you click it
  132. }
  133. xOffset = mouseX - GalaxyX; //of offset is = to the mouse position minus the galaxy center
  134. yOffset = mouseY - GalaxyY;
  135. }
  136.  
  137. void mouseDragged() {
  138. if (locked) { //if boolean locked is false
  139. GalaxyX = mouseX - xOffset; //the galaxy x is the mouse location - the amount you're offset from center
  140. GalaxyY = mouseY - yOffset; //the galaxy y is the mouse location - the amount you're offset from center
  141. }
  142. }
  143. void mouseReleased() {
  144. locked = false; //let go of the galaxy
  145. }
  146.  
  147. //other objects
  148. void spaceShip() {
  149. fill (190, 255, 190); //fill with lime green
  150. circle (mouseX, mouseY-15, 30); //mouses x and -15 the y are a circle with diameter 30
  151. fill (0, 0, 0); // fill with black
  152. ellipse (mouseX, mouseY, 80, 30); //the mouses x and y become an ellipse of 80 width, 30 height
  153. }
  154.  
  155. void Stars() {
  156. int n = 0; //int n starts at 0
  157. while (n < 19) { //while n is less than 19
  158. //color (stars);
  159. fill (255, 255, 255); //fill with this color
  160. noStroke(); //no stroke
  161. //AT THESE LOCATIONS
  162. circle (xLoc[n], yLoc[n], radius[n]);
  163. circle (-yLoc[n], -xLoc[n], radius[n]);
  164. circle (2 * yLoc[n], 2 * xLoc[n], radius[n]);
  165. circle (2 / xLoc[n], 2 / yLoc[n], radius[n]);
  166. circle (2 * -yLoc[n], 2 * -xLoc[n], radius[n]);
  167. circle (2 * -xLoc[n], 2 * -yLoc[n], radius[n]);
  168. circle (1.5 * -xLoc[n], 1.5 * -yLoc[n], radius[n]);
  169. circle (1.5 / yLoc[n], 1.5 / xLoc[n], radius[n]);
  170. n = n + 1; // and add 1 to n
  171. }
  172. }
  173. //used ball example for this
  174. class Comet {
  175. //data
  176. float cometSize;
  177. float shakeSpeed;
  178. float xPos = 0; //xpos and ypos are set to 0
  179. float yPos = 0;
  180. //constructor
  181. Comet (float x, float y, float paramSize, float paramSpeed) {
  182. cometSize = paramSize; //cometsize is the same as paramsize
  183. shakeSpeed = paramSpeed; //shakespeed is = paramspeed
  184. xPos = x; //the variable for xpos is = x
  185. yPos = y; //the variable for ypos is = y
  186. }
  187. //function
  188. void update() {
  189. noStroke(); //the cirlces don't get a stroke
  190. circle (xPos, yPos, cometSize); //what the comets are made from
  191. xPos = xPos + shakeSpeed;
  192. if (xPos > width || xPos < 0) { //if the x postion greater than the canvas width or the x position is less than 0
  193. shakeSpeed *= -1; //the shake speed goes down by -1
  194. }
  195. }
  196. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement