// this is an abstract toy where you use a slingshot to hunt rectangles which are flies // press space to reload and mousebutton to shoot // variables for slingshot int aX,bX,cX,dX,aY,bY,cY,dY; // for left rubbrband int wX,xX,yX,zX,wY,xY,yY,zY; // for right rubberband int pX,qX,rX,sX,pY,qY,rY,sY; // for lower left stick int jX,kX,lX,mX,jY,kY,lY,mY; // for lower right stick int eX11,fX11,gX11,hX11,eY11,fY11,gY11,hY11; int eX22,fX22,gX22,hX22,eY22,fY22,gY22,hY22; int eX33,fX33,gX33,hX33,eY33,fY33,gY33,hY33; int eX44,fX44,gX44,hX44,eY44,fY44,gY44,hY44; boolean drawSquareOne = true; // this is to makesure flies dont get redrawn after being hit boolean drawSquareTwo = true; boolean drawSquareThree = true; boolean drawSquareFour = true; boolean drawSquareFive = true; // variables for slingshot end int count=0; // counter variable to keep track of the rubber streach and to set limit to rubber streach distance when the slingshot is pulled, count is basically how streached the rubberband is int limit; // limit is another counter, it is 1 when the rubberband is at max length that is when count is 50 and when its 1 it triggers the release of the srubberband. integer was used instead of bollean because it was glitching out int reset; int release; //int m=millis(); // variables for ball int ballX,ballY; //ball positon int ballH,ballW; // ball dimentions int speed=0; // the speed at which the ball moves in air int ballCounter=0; // int ballReset; int ballMove; int store; int temp; // variables for flies int l1X,l1Y; int l2X,l2Y; int l3X,l3Y; int l4X,l4Y; int l5X,l5Y; // declaring random variables to move flies int h1,h2,h3,h4,h5; //height of flies int w1,w2,w3,w4,w5; //width of flies int r1=0,r2; // this is to store value of random int change=0; void setup() { size(400,400); frameRate(60); } void draw() { println("click and hold left mouse button to ready slingshot"); println("press space to reload. hover over upper right corner to change pattern"); drawSlingshot(); fire(); drawBall(); flies(); drawSlingShot(); checkGraphic(); checkColision(); } void drawSlingshot() { background(255,142,90); fill(0); quad(aX,aY,bX,bY,cX,cY,dX,dY); quad(yX,yY,zX,zY,xX,xY,wX,wY); fill(108,77,61); quad(pX,pY,qX,qY,rX,rY,sX,sY); //quad(eX11,fX11,gX11,hX11,eY11,fY11,gY11,hY11); fill(255); } void fire() { //upper left //if(frameCount<60) //{ //limit=0; // } aX=mouseX-50; aY=mouseY; bX=mouseX-60; bY=mouseY+10; cX=mouseX-10; cY=mouseY+60+count; dX=mouseX; dY=mouseY+50+count; // left rubberband end // right rubberband of slingshot yX=mouseX+50; yY=mouseY; zX=mouseX+60; zY=mouseY+10; xX=mouseX+10; xY=mouseY+60+count; wX=mouseX-10; wY=mouseY+60+count; // right rubberband end // left lower stick fill(108,77,61); pX=mouseX-40; pY=mouseY+90; qX=mouseX-60; qY=mouseY+90; rX=mouseX-10; rY=mouseY+140; sX=mouseX; sY=mouseY+130; // lwft lower stick end fill(255); if (mousePressed&&count<=50&&limit==0&&release==1) // <50 is the rubber streach limit for string that is the string cant be streached more than 50 pixels limit =0 means r was pressed and everything was reset, release =1 basically means a key was pressed on keyboard { count++; // incriment count when mouse button is pressed } if(count==50) { limit=1; // this means limit has been reached, rubberband is at max and its time to release } if(limit==1) // was the limit reached? 1=yes then fire { count=-3; // rubberband released, shots fired reset=1; // println(count); // rubberband released time to reset for next shot if(count==-3) { ballCounter=1; } } /* // this is for me to debug in case of glitch please ignore // if(reset==1) // is reset==1 ? yes? then key was pressed user wants to reset this is for me to debug in case of glitch please ignore //&&count<=10 // { // limit=1; // m=0; //} */ } void keyReleased() // this is to basically signal that the shot has been fired successfully { limit=0; count=0; reset=0; release=1; ballReset=1; ballCounter=0;// speed=0; } void drawBall() { if(ballReset==1) { ballW=20; ballH=20; ballX=mouseX; ballY=mouseY+40+count; //temp++; store=ballX; // this stores value of ball to makesure its moving along with mouse, it has been used in line 202 } // ellipse(ballX,ballY,ballW,ballH); if(ballCounter==1) //count=-3 means rubber has been fully released ball counter tells the system tht string is fully released and ball can now continue in air it basically checks if the string is fully released twice if the count (speed of the string ) changes then -3 wouldent work as it is a manually calculated value. balllcounter is scalable { speed=speed+12; ballY=ballY-speed; speed=speed-5; ballH-=7; // decrease size give illusion of moving away ballW-=7; } fill(220,0,0); ellipse(store,ballY,ballW,ballH); //instead of store ballX can also be used they are the same thing fill(255); // ellipse(ballX,ballY,ballW,ballH); } void flies() { rectMode (CENTER); if(frameCount<60||l1X<0) // framecount is used to like reset the flies if they go out of screen and also give it a kick start to trigger it atlease ones in the start { l1X=431;l1Y=100; l2X=442;l2Y=150; // values are randomly set manually l3X=417;l3Y=320; l4X=450;l4Y=30; l5X=410;l5Y=200; } if(drawSquareOne) { w1=25;h1=15; } if(drawSquareTwo) { w2=30;h2=20; } if(drawSquareThree) { w3=10;h3=5; } if(drawSquareFour) { w4=45;h4=30; } if(drawSquareFive) { w5=50;h5=40; } int m1=(int)random(0,10); // this is used to generate randomness in the y axis if(m1==1||m1==5||m1==3) { //println("working"); l1Y++; l2Y++; l3Y++; l4Y+=1; l5Y+=3; /* rect(l1X--,l1Y+tan(TWO_PI),w1,h1); rect(l2X,l2Y,w2,h2); rect(l3X,l3Y,w3,h3); rect(l4X,l4Y,w4,h4); rect(l5X,l5Y,w5,h5); */ } if(m1==0||m1==2||m1==6) { l1Y-=02; l2Y-=1; l3Y-=2; l4Y-=3; l5Y-=2; // l1Y-=50*tan((frameCount/400)*TWO_PI); /*rect(l1X--,l1Y-tan(TWO_PI),w1,h1); rect(l2X,l2Y,w2,h2); rect(l3X,l3Y,w3,h3); rect(l4X,l4Y,w4,h4); rect(l5X,l5Y,w5,h5); */ } rect(l1X--,l1Y,w1,h1); rect(l2X--,l2Y,w2,h2); rect(l3X--,l3Y,w3,h3); rect(l4X--,l4Y,w4,h4); rect(l5X--,l5Y,w5,h5); /* for(int i=1;i<=5;i++) { for(int j=1;j<2;j++) { r2=((int)random(0,5))*10; r1= (int)random(0,1); if(i==1) { if(r1==0) { change-=1; l1X-=1; } if(r1==1) { l1X-=1; change+=1; j=0; } } } /* if(i==100&&m==m+1000) { w1=r2; h1=r2; } } */ } void drawSlingShot() { fill(108,77,61); eX11=mouseX-60; eY11=mouseY; fX11=mouseX-40; fY11=mouseY; gX11=mouseX-40; gY11=mouseY+90; hX11=mouseX-60; hY11=mouseY+90; quad(eX11,eY11,fX11,fY11,gX11,gY11,hX11,hY11); eX22=mouseX+60; eY22=mouseY; fX22=mouseX+40; fY22=mouseY; gX22=mouseX+40; gY22=mouseY+90; hX22=mouseX+60; hY22=mouseY+90; quad(eX22,eY22,fX22,fY22,gX22,gY22,hX22,hY22); eX33=mouseX+40; eY33=mouseY+90; fX33=mouseX+60; fY33=mouseY+90; gX33=mouseX; gY33=mouseY+150; hX33=mouseX-10; hY33=mouseY+140; quad(eX33,eY33,fX33,fY33,gX33,gY33,hX33,hY33); eX44=mouseX-10; eY44=mouseY+140; fX44=mouseX+10; fY44=mouseY+140; gX44=mouseX+10; gY44=mouseY+250; hX44=mouseX-10; hY44=mouseY+250; quad(eX44,eY44,fX44,fY44,gX44,gY44,hX44,hY44); fill(255); } void checkGraphic() { //int colors=0; quad(360,0,400,0,400,30,360,30); if(mouseX>=360&&mouseX<=400&&mouseY>=0&&mouseY<=30) { rectMode(CORNER); for(int i=0;i<=height;i+=10) { for(int j=0;j<width;j=j+10) { fill(j); rect(i,j,10,10); } } } } void checkColision() // this and rows/col method describen in processwork does not seem to work { if((ballX>=l1X&&ballX<l1X+3||ballX<=l1X&&ballX>l1X-3)&&(ballY>=l1Y&&ballY<=l1Y+3||ballY<=l1Y&&ballY>=l1Y+3)) { w1=0; h1=0; drawSquareOne = false; } if((ballX>=l2X&&ballX<l2X+3||ballX<=l2X&&ballX>l2X-3)&&(ballY>=l2Y&&ballY<=l2Y+3||ballY<=l2Y&&ballY>=l2Y+3)) { w2=0; h2=0; drawSquareTwo = false; } if(ballX>=l3X&&ballX<l3X+3||ballX<=l3X&&ballX>l3X-3&&(ballY>=l3Y&&ballY<=l3Y+3||ballY<=l3Y&&ballY>=l3Y+3)) { w3=0; h3=0; drawSquareThree = false; } if(ballX>=l4X&&ballX<l4X+3||ballX<=l4X&&ballX>l4X-3&&(ballY>=l4Y&&ballY<=l4Y+3||ballY<=l4Y&&ballY>=l4Y+3)) { w4=0; h4=0; drawSquareFour = false; } if(ballX>=l5X&&ballX<l5X+3||ballX<=l5X&&ballX>l5X-3&&(ballY>=l5Y&&ballY<=l5Y+3||ballY<=l5Y&&ballY>=l5Y+3)) { w5=0; h5=0; drawSquareFive = false; } }