Question
This is done in the Process Development Environment. This is the starter code float x, y, r = 15; // ball location and size float
This is done in the Process Development Environment.
This is the starter code
float x, y, r = 15; // ball location and size float speedX=0, speedY=0; // speed of ball float xt, yt, rt = 19; // target location and size int score = 0; // keep score
void setup(){ size(200,200); textSize(14); //ball initially at sketch center x = width/2; y = height/2; //target initially at random location within the sketch xt = random(rt, width-rt); yt = random(rt, height-rt); }
void draw(){ background(0); // draw score fill(255,0,0); text("Score: " + score, 5, 15); //draw ball noStroke(); fill(255); ellipse(x, y, 2*r, 2*r); //draw target stroke(255,180,0); fill(255,180,0,50); ellipse(xt, yt, 2*rt, 2*rt); //move ball x += speedX; y += speedY; //REQ1: Add code here to bounce ball off sketch edges. [+1 mark] //REQ2: Add code here to: // Check if ball is completely inside target (hint: dist() function). [+2 marks] // If it is, do two things: [+2 marks] // a) increment score // b) move target to a new random location }
void keyPressed(){ //REQ3: Add code here to react to key presses as following: // a) UP decrements speedY by 1, DOWN increments speedY by 1. speedY must stay in the range [-5,5] inclusive. [+2 marks] // b) LEFT decrements speedX by 1, RIGHT increments speedX by 1. speedX must stay in the range [-5,5] inclusive. [+2 marks] // c) SPACE freezes the ball and places it in the center of the sketch [+1 mark] }
For each question in this assignment, you need to do the following 1) Download the starter code. 2) Run the starter code and observe the output. 3) Fi in the missing code as per the instructions given in the starter code. These instructions are written as comments that start with "REQ" Q1.+10] Aim-for-Target Game: in class, we created a simple animation of a ball bouncing off the edges of a sketch. In this question, we will turn this animation into a simple game where the player tries to score by directing the bouncing ball into a target circle. The player should use the arrow keys to slightly modify the direction of the ball. Whenever the ball is completely inside the target, the score is incremented and the target moves to a new random location. To make the game challenging, the target is designed to be just a little bigger than the ball. Score: 1 Score: 1 Score: 1 Player uses the arrow keys to direct the ball into the orange target Once the ball is completely inside the target, the target changes its position and the score is incremented, while the ball keeps moving in the same direction This one doesn't count as the ball is not completely inside target Marking Guide: +1 for bouncing the ball off the edges +4 for checking if the ball is inside the target and taking actions if it does +5 for reacting to key presses BONUS: +up to 2 bonus marks are given for replacing the ball with an image and making any necessary changes (e.g. changing the target to a square if the shape in the image is a square) For each question in this assignment, you need to do the following 1) Download the starter code. 2) Run the starter code and observe the output. 3) Fi in the missing code as per the instructions given in the starter code. These instructions are written as comments that start with "REQ" Q1.+10] Aim-for-Target Game: in class, we created a simple animation of a ball bouncing off the edges of a sketch. In this question, we will turn this animation into a simple game where the player tries to score by directing the bouncing ball into a target circle. The player should use the arrow keys to slightly modify the direction of the ball. Whenever the ball is completely inside the target, the score is incremented and the target moves to a new random location. To make the game challenging, the target is designed to be just a little bigger than the ball. Score: 1 Score: 1 Score: 1 Player uses the arrow keys to direct the ball into the orange target Once the ball is completely inside the target, the target changes its position and the score is incremented, while the ball keeps moving in the same direction This one doesn't count as the ball is not completely inside target Marking Guide: +1 for bouncing the ball off the edges +4 for checking if the ball is inside the target and taking actions if it does +5 for reacting to key presses BONUS: +up to 2 bonus marks are given for replacing the ball with an image and making any necessary changes (e.g. changing the target to a square if the shape in the image is a square)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started