////interactive Toy by WangZiHao//////////
float GoalieX=190;//the postion of goalie
float Xspeed=6;//the speed of goalie
float Yspeed=2;//the speed of soccer ball
float BallY=360;//the postion of the soccer ball
boolean ballShot= false;
int score=0;//// score/////
//////SET UP/////
void setup(){
size (400,400);
rectMode(CORNER);
frameRate(60);
}
void draw(){
shot();
updateScore();
///background///
noStroke();
background(5,36,82);
///sky///
int x=180;
int y=250;
while(x>=0&&y>=0)
{
noStroke();
fill(35,102,9,y);
y-=20;
rect(0,x,400,20);
x=x-20;
}
///grass////
noStroke();
fill(39,108,0);
rect(0,200,width,70);
fill(92,146,58);
rect(0,270,width,10);
fill(78,141,0);
triangle(0,280,0,380,100,280);
quad(150,280,100,400,200,400,200,280);
triangle(300,280,400,280,400,380);
triangle(0,380,100,400,0,400);
fill(52,117,0);
quad(100,280,0,380,100,400,150,280);
quad(200,280,200,400,300,400,250,280);
triangle(300,400,400,380,400,400);
fill(89,155,0);
quad(250,280,300,400,400,380,300,280);
///goal bar and goal keeper///
noStroke();
fill(255);
ellipse(50,280,20,20);
rect(40,60,20,220);
ellipse(350,280,20,20);
rect(340,60,20,220);
rect(60,60,280,20);
quad(60,80,60,90,80,100,80,90);
quad(80,90,80,100,100,230,110,230);
quad(320,90,320,100,340,90,340,80);
quad(290,230,300,230,320,100,320,90);
quad(60,270,60,280,100,240,100,230);
quad(300,230,300,240,340,280,340,270);
rect(100,230,200,10);
///goalie///
GoalieX=GoalieX+Xspeed;//make the Goalie movement
if(GoalieX>320){
Xspeed*=-1;}
if(GoalieX<80){
Xspeed*=-1;}
fill(0);
triangle(GoalieX,190,GoalieX,250,GoalieX-30,290);
triangle(GoalieX,190,GoalieX,250,GoalieX+30,290);
fill(120);
noStroke();
ellipse(GoalieX,190,40,40);
quad(GoalieX-10,190,GoalieX-30,230,GoalieX-20,230,GoalieX,200);
quad(GoalieX-30,230,GoalieX-10,250,GoalieX,250,GoalieX-20,230);
quad(GoalieX,200,GoalieX+20,230,GoalieX+30,230,GoalieX+10,190);
quad(GoalieX+20,230,GoalieX+10,250,GoalieX+10,250,GoalieX+30,230);
///soccer ball////
fill(255);
stroke(0);
strokeWeight(3);
ellipse(mouseX,BallY,60,60);
ellipse(mouseX,BallY,30,30);
///score////
fill(255);
text ("SCORE:"+score, 10, 20);
}
void shot(){
if(mousePressed){
ballShot = true;
}
if(ballShot == true){
BallY =BallY - 8;////ball speed///
}
if(BallY < 240){
ballShot = false;
BallY = 360;//reset the ball postion/////
}
}
void updateScore(){
if (mouseX>GoalieX+20&mouseX<340&&BallY<241){
score=score+1;
}
if(mouseX<GoalieX-20&&mouseX>60&&BallY<241){
score=score+1;
}
}