Week 5 - Basketball Interactive Video



This week, I tried to draw basketball play. 


Condition 1 : 

When the player presses arrow keys, the hand and the ball move to that direction. 

Player can set to proper position to shoot the ball to the basket.


Condition 2 

Although, the ball and the hand can move in the animation, 

they don't move when they reach to specific point of display window. 


Condition 3

After the player sets proper position, player can press the mouse. 

And when the mouse is clicked, the hand shoots the ball.



When the ball goes into the basket, game ends, while another chance is given to the player 

when is failed to goal in. 



<CODE>


PImage gym;

PImage basket;

PImage basketball;

PImage hand;

PImage basketballplayer;

PFont font;

float xBasket = random(0,420);

float xHand = 200;

float yHand = 150;

float xBall = 375;

float yBall = 290;

float sizeBall = 250;

boolean isBallThrown = false;

boolean isBallGoingUp = true;

boolean isBallInside = false;

boolean isRetry = false;

boolean isEnd = false;


void setup() {

  size(600,400);

  noStroke();

  gym = loadImage("gym.jpg");

  basket = loadImage("basket.png");

  basketball = loadImage("basketball.png");

  hand = loadImage("hand.png");

  basketballplayer = loadImage("basketballplayer.png");

  font = loadFont("FortunaDot.vlw");

}


void draw() {

  drawBackground();

  drawBeginning();

  drawEnding();

}


void drawBackground() {

  imageMode(CORNER);

  image(gym,-50,0,width+100,height+100);

  fill(255,191,73);

  quad(187,73,374,54,372,77,192,121);

  fill(255,229,93);

  quad(191,121,376,75,361,182,184,185);

 

  //basket

  image(basket,xBasket,0,180,180);

}


void drawBeginning() {

  drawBall();

  drawHand();

}


void drawBall() {

  imageMode(CENTER);

  image(basketball,xBall,yBall,sizeBall,sizeBall*1.08);

  if(keyPressed && isBallThrown==false) {

    if(keyCode == UP && yHand>120) {

      yBall -= 1.5;

    }

    if(keyCode == DOWN && yHand<180) {

      yBall += 1.5;  

    }

    if(keyCode == LEFT && xHand>-30) {

      xBall -= 3;

    }

    if(keyCode == RIGHT && xHand<290) {

      xBall += 3;

    }

  }

  if(mousePressed) {

    isBallThrown = true;

  }

  if(xBall<xBasket+80+20 && xBall>xBasket+80-20) {

    isBallInside = true;

  }

  if(isBallThrown && isBallInside) {

    drawBallGoal();

  }

  else if(isBallThrown) {

    drawBallThrown();

  }

}


void drawBallThrown() {

  if(sizeBall>50) {

    sizeBall -= 4;

  }

  if(yBall>70 && isBallGoingUp == true) {

    yBall -= 16;

  }

  else if(yBall>-60 && isBallGoingUp == true) {

    yBall -= 10;

  }

  if(yBall<-60) {

    isBallGoingUp = false;

  }

  if(isBallGoingUp == false && yBall<340) {

    yBall += 5;

  }

  if(isBallGoingUp == false && yBall>340)  {

    drawRetry();

  }

}


void drawBallGoal() {

  if(sizeBall>50) {

    sizeBall -= 4;

  }

  if(yBall>70 && isBallGoingUp == true) {

    yBall -= 16;

  }

  else if(yBall>-60 && isBallGoingUp == true) {

    yBall -= 10;

  }

  if(yBall<-60) {

    isBallGoingUp = false;

  }

  if(isBallGoingUp == false && yBall<170) {

    yBall += 5;

  }

  if(isBallGoingUp == false && yBall>170) {

    isEnd = true;

  }

}


void drawHand() {

  imageMode(CORNER);

  image(hand,xHand,yHand,300,300);

  if(keyPressed) {

    if(keyCode == UP && yHand>120) {

      yHand -= 1.5;

    }

    if(keyCode == DOWN && yHand<180) {

      yHand += 1.5;  

    }

    if(keyCode == LEFT && xHand>-30) {

      xHand -= 3;

    }

    if(keyCode == RIGHT && xHand<290) {

      xHand += 3;

    }

  }

}


void drawRetry() {

  xHand = 200;

  yHand = 150;

  xBall = 375;

  yBall = 290;

  sizeBall = 250;

  isBallThrown = false;

  isBallGoingUp = true;

}


void drawEnding() {

  if(isEnd) {

  fill(0);

  rect(0,0,width,height);

  image(basketballplayer,10,50,300,300);

  fill(255);

  textFont(font,80);

  text("GOAL", 310, 220);

  }

}


덧글

댓글 입력 영역