KatherineVargas
PImage chili; //opensource PImage hoop; //opensource PImage court; //opensource
int x_player,y_player,y_hoop,x_hoop,move_speed,direction,hoop_direction, score, miss;
boolean shoot,inhand,lose;
float ballgravity = 0; float ballangle =0 ; float ballspeed = 1; float ballcurve = 0.3; float ballx,bally;
Ball newBall = new Ball();
void setup(){
size (720,480);
hoop=loadImage("hoop.png"); chibi=loadImage("chibi.png"); court=loadImage("court.jpg");
shoot=false; inhand= true; lose = false; score=0; miss=0;
x_player = width-200; y_player = 440; y_hoop = 100; x_hoop = 100; direction = -1; hoop_direction = 1; move_speed = 2;
} void draw() {
background(0); image(court,0,0,720,480);
newBall.CreateBall(); //MoveBall(); Movement(); HoopMove(); newBall.ShootBall(); newBall.MakeBasket();
textSize(24); text("Score",580,50); text(score,660,50); text("Miss",30,50); text(miss,100,50);
//CheckBall();
}
void CheckBall() {
if (newBall.ballx < 0||newBall.bally >height) {
inhand=true; newBall.ballx = x_player; newBall.bally = y_player; shoot = false;
miss +=1;
}
}
void Movement(){
x_player += move_speed * direction ;
if (x_player > width-200){
direction = - direction; } else if (x_player < 300){
direction = 1; }
image (chibi,x_player,y_player-140);
}
void HoopMove(){
y_hoop += move_speed * hoop_direction;
if (y_hoop > height/2-50){
hoop_direction = -hoop_direction;
} else if (y_hoop<50){
hoop_direction = 1; }
image (hoop,0,y_hoop);
if(score>9){ move_speed=2*2; }
}
void MoveBall(){
if (shoot) {
ballx = width/2+sin(radians(ballangle)) * ballgravity; bally = width/2+cos(radians(ballangle)) * ballgravity;
ballangle += ballcurve;
if (ballangle > 90 ){ ballangle = 0; ballgravity = 1;}
image(newBall.ball,ballx, bally);
ballgravity -= ballspeed;
}
}
void mousePressed(){
if (!shoot&& inhand){
shoot=true;
}
}
class Ball {
PImage ball; float ballx,bally; boolean makebasket;
float ballgravity = 0; float ballangle =0 ; float ballspeed = 5.0; float ballcurve = 0.7;
Ball(){
}
void CreateBall(){
ball=loadImage( "Basket_Ball.png");
}
void ShootBall(){
// the if statement reads if SHOOT is true then go ahead and RUN THIS SECTION OF THE CODE
if (shoot) {
inhand=false;
ballx = x_player+sin(radians(ballangle)) * ballgravity + 10; bally = y_player+cos(radians(ballangle)) * ballgravity - 65;
ballangle += ballcurve;
if (ballangle > 90 ){
ballangle = 0; ballgravity = 0; shoot=false; miss +=1; ballx = x_player + 10; // I MADE THE BALL X AXIS TO EQUAL THE PLAYER X AXIS WHICH MAKES IT MOVE WITH THE PLAYER bally = y_player - 65; inhand=true;
}
ballgravity -= ballspeed;
}
else { // THIS ELSE STATEMENT IS VERY IMPORTANT. IT MEANS IF THHE BALL IS NOT BEING SHOT THAT SET THE X,Y FOR THE BALL BACK TO THE PLAYER.
ballx = x_player + 10 ; // I MADE THE BALL X AXIS TO EQUAL THE PLAYER X AXIS WHICH MAKES IT MOVE WITH THE PLAYER bally = y_player - 65; inhand=true;
}
image (ball,ballx,bally); // HERE I CREATE THE BALL. NOTICE I ALWAYS CREATE THE IMAGES AFTER I SET VARIBLAES>
}
// THIS FUCNTION JUST CHECK FOR TEH DISTANCE OF THE BALL AND BASKET
void MakeBasket(){
float basket;
basket = dist(ballx,bally,x_hoop,y_hoop); // i store the distance in basket
if (basket<40) {
makebasket=true;
} else makebasket =false;
if (makebasket){
inhand=true; shoot=false; score+=1; }
if (miss==3) { textSize(50); text("R TO RESTART",width/4,height/4); text("YOU LOSE",width/4,height/2); noLoop(); }
}
} void keyPressed(){
if (key=='r'){
redraw(); setup(); loop(); } }
I couldn't solve the ball bounce back nor arc the ball the way i wanted to, but everything is good. It is a one player game, you miss 3 then you lose. the basket goes faster after a certain score.
https://drive.google.com/open?id=0B5gaNLBpbBXLNjZqNUZnY3E0THM














