/*
It's a pirate puppet show!
Use the mouse to create exciting swashbuckling action!
Press and hold the mouse for appropriately piratey utterances!
...Yes, I took the very literal interpretation of the
puppet theme...
***update***
Now there 3 theme options! (although still
other possibilities exist)
And, to compromise on the visibility of the cursor
it disappears when the mouse is pressed.
...I chose pirates out of the other choices of swordfighting
themes (knights, ninjas, Hamlet, etc.) because of the
versality and recognizeability available for character
design.
*/
PImage hook,Rcurtain,Lcurtain,stage,bg,bg2,bg3,
captain,captain_arm,admiral,admiral_arm,
quote,quote2,quote3,
octopus,T1,T2,T3,T4,T5,T6,T7,T8,
DV,DV2,DVarm,DVcape,captain_arm2;
int time,timer;
int mode=1;
int a,b;
float curtainmove,curtainmove2;
float x=100;
float x2=430;
float angle=0.0;
float angle1=0.0;
float seglength=80;
float targetangle,targetx,targetx2,bobble;
float easing=.1;
float stiffness=.15;
float damping=.9;
float velocity=.0;
float Rarmrotate,Larmrotate,octobody,octo;
float velocity2=.0;
float stiffness2=.2;
float velocity3=.0;
float velocity4=.0;
Button button1,button2,button3;
PImage[] quotes1=new PImage[6];
PImage[] quotes2=new PImage[6];
PImage[] quotes3=new PImage[6];
void setup () {
size(600,600);
frameRate(50);
stroke(0,200);
hook=loadImage("hook.png");
Rcurtain=loadImage("Rcurtain.png");
Lcurtain=loadImage("Lcurtain.png");
stage=loadImage("stage1.jpg");
bg=loadImage("background.jpg");
bg2=loadImage("background2.jpg");
bg3=loadImage("background_3.jpg");
captain=loadImage("captain.png");
captain_arm=loadImage("captain_arm.png");
admiral=loadImage("admiral.png");
admiral_arm=loadImage("admiral_arm.png");
quote=loadImage("bubble.png");
quote2=loadImage("bubble2.png");
quote3=loadImage("bubble3.png");
octopus=loadImage("octopus.png");
T1=loadImage("tentacle1.png");
T2=loadImage("tentacle2.png");
T3=loadImage("tentacle3.png");
T4=loadImage("tentacle4.png");
T5=loadImage("tentacle5.png");
T6=loadImage("tentacle6.png");
T7=loadImage("tentacle7.png");
T8=loadImage("tentacle8.png");
DV=loadImage("vader1.png");
DV2=loadImage("vader2.1.png");
DVarm=loadImage("vader_arm1.png");
DVcape=loadImage("cape1.png");
captain_arm2=loadImage("captain_arm2.1.png");
PImage b1= loadImage("wheel.png");
PImage r1=loadImage("wheel_over.png");
PImage d1=loadImage("wheel_pressed.png");
button1= new Button(350,525,70,b1,r1,d1);
PImage b2= loadImage("anchor.png");
PImage r2=loadImage("anchor_over.png");
PImage d2=loadImage("anchor_pressed.png");
button2= new Button(425,525,70,b2,r2,d2);
PImage b3= loadImage("coin.png");
PImage r3=loadImage("coin_over.png");
PImage d3=loadImage("coin_pressed.png");
button3= new Button(500,525,70,b3,r3,d3);
/////fun pirate sayings!
for (int i=0; i<6; i++) {
String imageName1 = "phrase"+i+".gif";
quotes1[i]=loadImage(imageName1);
String imageName2 = "adj"+i+".gif";
quotes2[i]=loadImage(imageName2);
String imageName3 = "noun"+i+".gif";
quotes3[i]=loadImage(imageName3);
}
}
void draw() {
smooth();
background(240);
noCursor();
if (mode==1) {
image(bg,0,0);
}
if (mode==2) {
image(bg2,0,0);
}
if (mode==3) {
image(bg3,0,0);
}
float sec=millis()/1000.0;
float speed=mouseX-pmouseX;
float yspeed=mouseY-pmouseY;
targetangle=(speed*18/float(width))*PI;
float t1=constrain(targetangle,-PI/2,PI/2);
angle1+=(t1-angle1)*easing;
angle=(mouseY/500.0-.6)*PI;
//Left arm springs
float force=stiffness*(angle-Larmrotate);
velocity=damping*(velocity+force);
Larmrotate+=velocity;
//Right arm springs
float force2=stiffness2*(-1*angle-Rarmrotate);
velocity2=damping*(velocity2+force2);
Rarmrotate+=velocity2;
float mx=constrain(mouseX,50,550);
/////////right puppet
if ((mousePressed==true)&&(mouseY>75)) {
targetx2=mx+130;
x2+=(targetx2-x2)*easing;
} else {
targetx2=300+abs(mx-340)+100;
x2+=(targetx2-x2)*easing*2;
}
if (mode==1) {
pushMatrix();
Admiral(x2,300,angle1);
popMatrix();
pushMatrix(); //right puppet arm
admiralA(x2+angle1*15,280,Rarmrotate);
popMatrix();
}
if (mode==2) { ///giant octopus!
float ybobble=331+5*yspeed;
bobble+=(ybobble-bobble)*.02;
////springs
float force4=stiffness*(bobble-octobody);
velocity4=damping*(velocity4+force4);
octobody+=velocity4;
float force3=stiffness2*(bobble-octo);
velocity3=damping*(velocity3+force3);
octo+=velocity3;
pushMatrix();
tentacle1(x2+50,octo+50,Rarmrotate/4.1);
popMatrix();
pushMatrix();
tentacle2(x2-30,octo+45,Rarmrotate/4.3);
popMatrix();
pushMatrix();
tentacle3(x2+55,octo+55,-1*Rarmrotate/4);
popMatrix();
pushMatrix();
tentacle4(x2-75,octo+60,-1*Rarmrotate/3.8);
popMatrix();
pushMatrix(); /////head and body
octopus(x2,octobody,angle1/PI);
popMatrix();
pushMatrix();
tentacle5(x2+105,octo+65,Rarmrotate/PI);
popMatrix();
pushMatrix();
tentacle6(x2-135,octo+45,Rarmrotate/3);
popMatrix();
pushMatrix();
tentacle7(x2+75,octo+50,-1*Rarmrotate/2.7);
popMatrix();
pushMatrix();
tentacle8(x2-35,octo+55,Rarmrotate/2);
popMatrix();
}
if (mode==3) { ////darth vader
pushMatrix();
Darth(x2,300,angle1);
popMatrix();
pushMatrix(); //arm
DarthA(x2+angle1*15-10,278,Rarmrotate/1.1);
popMatrix();
pushMatrix();
Darth2(x2+angle1*15,272,(Rarmrotate+PI/3)/2);
popMatrix();
pushMatrix();
Cape(x2+angle1*15+7,271,angle1);
popMatrix();
}
///////////////left puppet--Captain
if ((mousePressed==true)&&(mouseY>75)) {
targetx=mx-130;
x+=(targetx-x)*easing;
} else {
targetx=300-abs(mx-260)-100;
x+=(targetx-x)*easing*2;
}
pushMatrix();
Captain(x,300,angle1);
popMatrix();
if(mode==3){
pushMatrix(); //left puppet arm-Captain
captainA2(x+angle1*15,280,Larmrotate);
popMatrix();
}else{
pushMatrix(); //left puppet arm-Captain
captainA(x+angle1*15,280,Larmrotate);
popMatrix();
}
///////quote bubble//////////////////
timer=frameCount%133;
if ((mousePressed==true)&&(timer==0)) {
time=frameCount;
}
if ((frameCount>=time)&&(frameCount<=time+80)) {
if (mode==1) {image(quote,mx-80,50);}
if (mode==2) {image(quote2,mx-80,50);}
if (mode==3) {image(quote3,mx-80,50);}
int q=time%6;
int r=(floor(time*1.4))%6;
int s=(ceil(time*2.2))%6;
image(quotes1[q],mx-80,50);
image(quotes2[r],mx-80,50);
image(quotes3[s],mx-80,50);
}
////stage/////////
image(stage,0,395);
/////buttons//////
button1.update();
button2.update();
button3.update();
button1.display();
button2.display();
button3.display();
////custom piratey cursor///////
if (mousePressed==false) {
image(hook,mouseX-17,mouseY-19);
}
if (sec <=7) { ////intro
curtainmove2+=2 ; //inner curtain layer
image(Lcurtain,0-curtainmove2,0);
image(Rcurtain,300+curtainmove2,0);
curtainmove+=3.7 ; //outer curtain layer
image(Lcurtain,0-curtainmove,0);
image(Rcurtain,300+curtainmove,0);
}
}
void mousePressed() {
if (button1.press()==true) {mode=1;}
if (button2.press()==true) {mode=2;}
if (button3.press()==true) {mode=3;}
}
void mouseReleased() {
button1.release();
button2.release();
button3.release();
}
void Captain(float x, float y, float a) {
strokeWeight(2);
translate(x,y);
rotate(a);
image(captain,-60,-144);
}
void captainA(float x, float y, float a) {
translate(x,y);
rotate(a);
image(captain_arm,-19,-70);
}
void captainA2(float x, float y, float a) {
translate(x,y);
rotate(a);
image(captain_arm2,-20,-85);
}
void Admiral(float x, float y, float a) {
translate(x,y);
rotate(a);
image(admiral,-50,-125);
}
void admiralA(float x, float y, float a) {
translate(x,y);
rotate(a);
image(admiral_arm,-240,-75);
}
void Darth(float x, float y, float a) {
translate(x,y);
rotate(a);
image(DV,-70,-135);
}
void Darth2(float x, float y, float a) {
translate(x,y);
rotate(a);
image(DV2,-60,-115);
}
void Cape(float x, float y, float a) {
translate(x,y);
rotate(a);
image(DVcape,-26,-27);
}
void DarthA(float x, float y, float a) {
translate(x,y);
rotate(a);
image(DVarm,-244,-80);
}
void octopus(float x, float y, float a) {
translate(x,y);
rotate(a);
image(octopus,-112,-144);
}
void tentacle1(float x,float y, float a){
translate (x,y);
rotate(a);
image(T1,-26,-135);
}
void tentacle2(float x,float y, float a){
translate (x,y);
rotate(a);
image(T2,-51,-171);
}
void tentacle3(float x,float y, float a){
translate (x,y);
rotate(a);
image(T3,-27,-108);
}
void tentacle4(float x,float y, float a){
translate (x,y);
rotate(a);
image(T4,-91,-135);
}
void tentacle5(float x,float y, float a){
translate (x,y);
rotate(a);
image(T5,-27,-166);
}
void tentacle6(float x,float y, float a){
translate (x,y);
rotate(a);
image(T6,-66,-167);
}
void tentacle7(float x,float y, float a){
translate (x,y);
rotate(a);
image(T7,-47,-170);
}
void tentacle8(float x,float y, float a){
translate (x,y);
rotate(a);
image(T8,-55,-137);
}
class Button {
int buttonx, buttony;
int Size;
PImage baseimage,overimage,pressimage,currentimage;
boolean over = false;
boolean press = false;
Button(int xpos, int ypos, int s, PImage b, PImage o, PImage p) {
buttonx = xpos;
buttony = ypos;
Size = s;
baseimage = b;
overimage = o;
pressimage = p;
currentimage=baseimage;
}
//updates "over"
void update() {
if ((mouseX >= buttonx) && (mouseX<= buttonx+Size) &&
(mouseY >= buttony) && (mouseY<= buttony+Size)) {
over = true;
} else {
over = false;
}
}
//updates "press" when mouse pressed
boolean press() {
if (over == true) {
press = true;
return true;
} else {
return false;
}
}
//set "press" to false when mouse released
void release() {
press = false;
}
//draws the button
void display() {
if (press == true) {
currentimage=pressimage;
} else if (over == true) {
currentimage=overimage;
} else {
currentimage=baseimage;
}
image(currentimage,buttonx,buttony);
}
}