Last active
October 27, 2015 16:01
-
-
Save slambert/081c3cd885788cd20664 to your computer and use it in GitHub Desktop.
Sample from class of getting sounds to not echo with flags
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int x = 0; | |
int speed = 5; | |
PImage img; //this is the name of the pictures in this file | |
PImage img1; | |
PImage img2; | |
PImage img3; | |
PImage img4; | |
PImage img5; | |
PImage bg; | |
PImage bg1; | |
float j; //PART OF MAGIC THAT HAPPENS | |
float R; | |
float G; | |
float B; | |
float beamA; | |
float beamB; | |
float smoke; | |
//SOUND IMPLEMENT | |
import processing.sound.*; | |
SoundFile file; | |
SoundFile file1; | |
SoundFile file2; | |
boolean vSoundFlag = false; | |
void setup(){ | |
size(1000,700); | |
img = loadImage("ron.png"); // Load the image into the program | |
img1 = loadImage("harry.png"); | |
img2 = loadImage("hermione.png"); | |
img3 = loadImage("cape.png"); | |
img4 = loadImage("ronfly.png"); | |
img5 = loadImage("dobby.png"); | |
bg = loadImage("baggrund.png"); | |
bg1 = loadImage("voldemort.jpg"); | |
file = new SoundFile(this, "syvdage.mp3"); | |
file1 = new SoundFile(this, "magic.mp3"); | |
file2 = new SoundFile(this, "themesong.mp3"); | |
file2.play(); //continuing background music | |
smooth(); | |
} | |
void draw(){ | |
background(bg); | |
Hermione(); //this is much easier to keep track of what is what | |
Harry(); | |
Ron(); | |
Button(); | |
Harrymagic(); | |
} | |
void Hermione(){ | |
stroke(0); | |
pushMatrix(); //rotating star behind her character | |
translate(200, height*0.7); | |
rotate(frameCount / 400.0); | |
fill(255,0,0); | |
star(0, 0, 70, 120, 30); | |
popMatrix(); | |
if(mouseX > 0 && mouseX <300 && mouseY > 0 && mouseY < 600) { //if the mouse is on Hermione | |
image(img3,mouseX-130, mouseY-100, 270, 270);//this is the invisible cape! | |
} | |
image(img2, 100, 300, 170, 350); //image of Hermione | |
} | |
void Harry(){ | |
//ROTATING STAR BEHIND CHARACTER | |
pushMatrix(); | |
translate(width*0.5, height*0.7); | |
rotate(frameCount / 400.0); | |
fill(0,255,0); | |
star(0, 0, 70, 120, 30); | |
popMatrix(); | |
if(mouseX > 350 && mouseX <600 && mouseY > 200 && mouseY < 600) { //IF THE MOUSE IS ON HARRY | |
pushMatrix(); //rotating star behind character | |
translate(width*0.5, height*0.7); | |
rotate(frameCount / 100.0); | |
fill(73,118,49); | |
star(0, 0, 70, 120, 50); | |
popMatrix(); | |
} | |
image(img1, 390, 300, 180, 350); //HI HARRY! | |
} | |
void Ron(){ | |
//ROTATING STAR | |
pushMatrix(); | |
translate(800, height*0.7); | |
rotate(frameCount / 400.0); | |
fill(0,0,255); | |
star(0, 0, 70, 120, 30); | |
popMatrix(); | |
if(mouseX > 690 && mouseX <950 && mouseY > 200 && mouseY < 600) { //IF THE MOUSE IS ON RON | |
cursor(HAND); | |
pushMatrix(); //rotating star behind character | |
translate(800, height*0.7); | |
rotate(frameCount / 100.0); | |
fill(73,227,242); | |
star(0, 0, 70, 120, 50); | |
popMatrix(); | |
} | |
image(img, 700, 300, 180, 350); //HI RONNYBOY! | |
// IF YOU CLICK ON RON THEY WILL ALL DISSAPEAR | |
if (mousePressed == true){ | |
if(mouseX >660 && mouseX<950 && mouseY>200 && mouseY<600) | |
{ | |
x = x + speed; //FLYING RON | |
if ((x > width) || (x < 0)){ | |
speed = speed * -1; //COMES BACK | |
} | |
background(bg); | |
image(img4, x, 100, 300, 200); | |
image(img5, 745, 442, 98, 208); | |
pushMatrix(); | |
translate(width*0.5, height*0.7); | |
rotate(frameCount / 400.0); | |
fill(0,255,0); | |
star(0, 0, 70, 120, 30); | |
popMatrix(); | |
image(img1, 390, 300, 180, 350); | |
pushMatrix(); //rotating star behind her character | |
translate(200, height*0.7); | |
rotate(frameCount / 400.0); | |
fill(255,0,0); | |
star(0, 0, 70, 120, 30); | |
popMatrix(); | |
image(img2, 100, 300, 170, 350); | |
} | |
}} | |
//CODE FOR ROTATING STARS BEHIND CHARACTERS | |
void star(float x, float y, float radius1, float radius2, int npoints) { | |
float angle = TWO_PI / npoints; | |
float halfAngle = angle/2.0; | |
beginShape(); | |
for (float a = 0; a < TWO_PI; a += angle) { | |
float sx = x + cos(a) * radius2; | |
float sy = y + sin(a) * radius2; | |
vertex(sx, sy); | |
sx = x + cos(a+halfAngle) * radius1; | |
sy = y + sin(a+halfAngle) * radius1; | |
vertex(sx, sy); | |
} | |
endShape(CLOSE); | |
} | |
//WHEN HARRY IS PRESSED SOUND AND MAGIC IS BEING ACTIVATED | |
void Harrymagic(){ | |
if (mousePressed == true){ | |
if(mouseX >301 && mouseX<600 && mouseY>100 && mouseY<600){ | |
file1.play(); | |
cursor(HAND); //NOW THE USER KNOW HARRY IS INTERACTIVE | |
//magic balls appear all over when you press the mouse | |
float x; | |
float y; | |
float r; | |
float g; | |
float b; | |
x = random(width); | |
y = random(height); | |
r = random(255); | |
g = random(255); | |
b = random(255); | |
fill(r,g,b); | |
ellipse(x,y,20,20); | |
float R; | |
float G; | |
float B; | |
float A; | |
R = random(255); | |
G = random(255); | |
B = random(255); | |
A = random(255); | |
beamA = random(-10,50); | |
beamB = random(-10,30); | |
smoke = random(2,30); | |
stroke (255); | |
fill (r,g,b); | |
line (490,390,mouseX,mouseY+beamA); | |
line (490,390,mouseX,mouseY+beamB); | |
fill(R,G,B,A); | |
ellipse(mouseX+random(10),mouseY+beamA,smoke,smoke); | |
}} | |
//CURSOR BECOMES A HAND WHEN HOVERING THE KILL VOLDEMORT BUTTON | |
if(mouseX >396 && mouseX<576 && mouseY>0 && mouseY<50){ | |
cursor(HAND); | |
} else { | |
cursor(ARROW); | |
} | |
//CURSOR BECOMES A HAND WHEN HARRY CAN INTERACT | |
if(mouseX >350 && mouseX<600 && mouseY>300 && mouseY<600){ | |
cursor(HAND); | |
} | |
//WHEN HERMIONE DISSAPEARS | |
if(mouseX >100 && mouseX<300 && mouseY>300 && mouseY<600){ | |
stroke(0); | |
background(bg); | |
//HARRY STAYS | |
pushMatrix(); | |
translate(width*0.5, height*0.7); | |
rotate(frameCount / 400.0); | |
fill(0,255,0); | |
star(0, 0, 70, 120, 30); | |
popMatrix(); | |
image(img1, 390, 300, 180, 350); | |
//RON STAYS | |
pushMatrix(); | |
translate(800, height*0.7); | |
rotate(frameCount / 400.0); | |
fill(0,0,255); | |
star(0, 0, 70, 120, 30); | |
popMatrix(); | |
image(img, 700, 300, 180, 350); | |
//BUTTON STAYS | |
stroke(255); | |
fill(0); | |
rect(402,10,170,35,8); //last number makes the corners round | |
textSize(18); | |
fill(193,22,27); | |
text("KILL VOLDEMORT!", 408, 35); | |
}} | |
//KILL VOLDEMORT USER EXPECTATION | |
void Button(){ | |
stroke(255); | |
fill(0); | |
rect(402,10,170,35,8); //last number makes the corners round | |
textSize(18); | |
fill(193,22,27); | |
text("KILL VOLDEMORT!", 408, 35); | |
//WHEN PRESSED THE BUTTON VOLDEMORT IS BEING MEAN AS A BACKGROUND IMAGE | |
if (mousePressed == true){ | |
if(mouseX >396 && mouseX<576 && mouseY>0 && mouseY<65) | |
{ | |
background(bg1); | |
if (vSoundFlag == false) { | |
file.play(); | |
vSoundFlag = !vSoundFlag // make it true | |
} else { | |
} | |
}}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment