Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / In this project, you will implement a simplified version of the Pong game with Processing

In this project, you will implement a simplified version of the Pong game with Processing

Computer Science

In this project, you will implement a simplified version of the Pong game with Processing. You can write your code from scratch, or you may decide to reorganize your code from Project 2 and use it as your starting point. As you work on this project, it is strongly recommended to: 1. write (and use) methods, and 2. correctly indent your code frequently using the “Auto Indent” menu A demonstration of the completed game is posted in Canvas. If you are interested, here is a YouTube video of the original Pong game: https://www.youtube.com/watch?v=fiShX2pTz9A As you see in the demonstration video, you will implement a subset of the original features of the Pong game and also a few features of our own. 2 Before You Start Create an empty sketch in Processing and save the project as Pong. 3 Requirements You must implement the following features for the Pong game: • This is a two-player game, one paddle for each player on each side (left and right). – The left paddle’s player will be referred to as “Player One” – The right paddle’s player will be referred to as “Player Two” • Each paddle should be aligned at the boundary of the canvas (i.e., the left side of the left paddle should be aligned at the left boundary of the canvas and the right side of the right paddle should be aligned at the right boundary of the canvas). • The ball bounces against each paddle and the top/bottom boundary of the canvas. If the Player One fails to bounce the ball with the left paddle, let the ball pass through the left side of the canvas. Apply the same approach for the Player Two. – Ball starts in center of screen – Ball must have a trail (or tail) following it. The way the trail is drawn is different from the approach we explained in class. In Project 2, the trail effect was achievable by drawing a canvas-wide rectangle at each draw method call with small opacity value set) but for this project you will use a different approach. See Section 6.2 for details. • Visualization of the game status – Display the number of remaining lives for each player. A ‘life’ is lost when the ball passes that player’s paddle and leaves the canvas. See Section 6.1 for details on text display on canvas. – At the end of each round (i.e., the ball passes the paddle of a player and disappears from the screen), user may press ‘c’ or ‘C’ key to continue the game and re-launch the ball (as long as the player has remaining lives). The policy to set the ball position and the x-/y-velocity is given below. (For this project, you will not increase the velocity. Ball direction will only be changing at boundary or paddle hit.) – “Game Over” screen should be displayed when one player runs out of lives. Also shows which player won the game. (If Player One lost all lives, Player Two wins. If Player Two lost all lives, Player One wins.) In the demo video, an animation is given with the messages, but you are not required to do the animation. You can simply display the messages as seen in the last frame of the demo video. (Notice that only the messages are displayed – no border, no ball, no lives display) At the beginning of the game, use the following values for the size of the ball and paddles, and also the velocity of the ball: • Paddle width: 20 pixels • Paddle height: 100 pixels • Ball diameter: 20 pixels • Canvas dimensions: width of 800 pixels, height of 600 pixels • Ball should be initially centered in the canvas • Ball should NOT be drawn with an outline use noStroke(); 1 • Ball x-velocity: Randomly choose either −4 or 4 (not between). New x-velocity values will be chosen at the start of the game or at keyboard input ‘n’/‘N’. The choice of x-velocity will be different at the keyboard input ‘c’/‘C’. See below for details. • Ball y-velocity: Randomly choose in the ranges of either [−10, −3) or [3, 10) – i.e., exclude -3 and 10. New y-velocity values will be chosen at the start of the game and at keyboard input (‘n’/‘N’ or ’c’/‘C’). Players will control the paddles by pressing keys. Use the following keys for the paddle control: • ‘t’ or ‘T’ key: Start a game. This key will be used to start a game. • ‘w’ or ‘W’ key: Move Player One’s paddle upwards (in the negative y direction) • ‘s’ or ‘S’ key: Move Player One’s paddle downwards (in the positive y direction) • ‘i’ or ‘I’ key: Move Player Two’s paddle upwards (in the negative y direction) • ‘k’ or ‘K’ key: Move Player Two’s paddle downwards (in the positive y direction) • ‘n’ or ‘N’ key: Reset all values in the game, as if the program was being run fresh. • ‘c’ or ‘C’ key: After the ball leaves the canvas from one of the player’s side, set the ball position, at key press, to be next to the player’s paddle, and the y-velocity of the ball to a random value as previously explained. The x-velocity of the ball should be chosen from either −4 and 4 (NOT between) to serve the ball towards the other player’s paddle. For instance, if the ball passes Player One’s paddle and leaves the canvas on the left side, at ‘c’ or ‘C’ key press, the ball’s position should be reset to be to the right of Player One’s paddle, with newly created xand y-velocity value. • For simplicity, assume that only one player presses a key at a time, and that each player’s key press does not interfere with the other player’s key press. In reality, this is not true — you may encounter problems when one player’s key dominates or hides the other player’s key press event, making it an unfair game. For this project, ignore this problem (but see Section 6.4 for a partial solution). Follow a good coding style (e.g., http://www.cs.umd.edu/~nelson/classes/resources/javastyleguide/). You are expected to use meaningful variable names (See Section 6.3), to format your code well (use the Edit > AutoFormat feature), and to document your code properly. First few lines of your code should be the comments with the project, date, and author (you) information. Put comments in your code too (e.g., you may describe what specific lines in your code do). You are required to write your name, directory ID, university ID, and section number as a comment at the top of each file you submit from this project forward. Additionally, we expect you to write the honor pledge (I pledge on my honor that I have not given or received any unauthorized assistance on this assignment/examination.) as a comment near the top of the file you submit. 2 4 Grading Your submission will be evaluated based on the rubrics in the following table. Note that the table only shows the point assignment for the required features. For each requirement, partial credits will be considered only if your code clearly shows that the feature is mostly implemented and your code works most of the time, although it often shows buggy behavior. Otherwise, you usually get 0 or full points for each requirement. Requirements Points 1. The ball moves and bounces correctly at the top and bottom canvas boundary 10 2. The ball bounces correctly at paddles 10 3. The ball trail is correctly visualized 15 4. The paddles are controlled properly with the designated keys 15 5. Displaying Game Over messages 10 6. Displaying the remaining lives of each player 10 7. A game starts at t’ or ‘T’ key press 5 8. Reset game at ‘n’ or ‘N’ key press 5 9. Continue the game at ‘c’ or ‘C’ key press after the ball is lost. 10 10. Coding style (comments, indentation, meaningful variable and method names) 10 TOTAL 100 pts 5 Good Faith Attempt Policy for Projects • Your total points must be 50 points or higher • You must receive 50% or higher points for each of the following requirements. – Requirement 1 (must receive full credits) – Requirement 3 (must receive full credits) – Requirement 4 (must receive full credits) – Requirement 7 (must receive full credits) 3 6 Quick Reference Below, we provided some information that will help you get started. We also suggest you to visit the reference link in the Processing home page for details. https://processing.org/reference/ 6.1 Strings and Drawing Text In this project, it will be necessary to work with strings, at least at a basic level. It may be useful to refer to the following String examples: int myNumber = 136; String hello = "Hello"; println(hello); String world = "World"; println(hello + world); println(hello + " " + world); println(hello + " my favorite number: " + myNumber); hello = hello + " not my favorite number: "; myNumber++; println(hello + myNumber); The output of the above code is: Hello HelloWorld Hello World Hello my favorite number: 136 Hello not my favorite number: 137 Processing provides several useful methods for drawing strings: • textSize(float) =⇒ Sets the height of text in pixels to the float value passed in. • textWidth(String) =⇒ Returns the width of the string passed in, in pixels, according to the current textsize. • fill(color) or fill(float R,float G,float B) =⇒ The same fill method as before - the color of fill is used for the color of the text drawn. • text(String, float, float) =⇒ Draws the text of the String passed in on the canvas where the bottomleft point of the text is the float, float coordinate you passed in. For example, text("Game Over", 50, 300) will display the text on canvas with the bottom left of the “G” at coordinate (50, 300). We have provided sample code for drawing and aligning text in Processing. We recommend you use this as a resource as you write your own code. 6.2 Trailing the Ball Use the following approach towards displaying a trail for the ball: 1. Store the previous 20 x and y positions of the ball each in their own array (i.e., two variables of the float[] type). If the ball position is reset to the center of the canvas or set to the side of a paddle, the x and y position arrays should be initialized so all elements have the same position (e.g., the center of the ball at game start). 2. Each frame, shift each x and y position array by one to the right and store the new ball position in the first index of the array. 3. Using a loop, draw an ellipse for each of these x and y positions with decreasing radius from the original ball radius and with increasing transparency. (Recent ellipse positions should be drawn more opaquely and with larger radius than less recent ellipse positions.) 4 6.3 Requirements on readability and code Put comments in your code! Your code should be readable with appropriate comments, and you will need to use meaningful variable names to keep track of certain information about the animation. Good use of variables, rather than “magic numbers” (literal constants) is strongly recommended. There are no explicit requirements for how many and what type of variables. For readability including variable naming, we suggest you to use these rules: • Format the code clearly with blank lines, spacing and indents • Use self-documenting, meaningful variable names • Use variable names that begin with lower case and then camel case e.g., roomTemp if two words • Use capital letters (e.g., ALL CAPS ) for variables that encodes constant values that are not updated • Use appropriate comments that indicate what a section, or a complicated line, does 6.4 Open Problem (not graded) — Key Interference In this project, you may encounter a problem where the key press of one player may interfere with the key press of the other player. A partial solution to this problem involves using a new method — keyReleased . So far, you have probably only used the keyPressed method to detect when keys are pressed. Using keyReleased and keyPressed in conjunction can help reduce the problem considerably. When a key is pressed, the key is stored in the key variable and the keyPressed method will be called. Similarly, when a key is released, the key is stored in the key variable and the keyReleased method will be called. However, since key is the only place where this value is stored, it is possible for multiple keys to be pressed or released at the roughly the same time, causing only one of the keys to be updated and observed by Processing. Note that this problem is not completely solved; no matter how you detect key presses, Processing can only observe one key being pressed and released per frame. In this way, a key press or release can hide the key press or release of another key. Using both keyPressed and keyReleased gives us more control over the problem, but does not solve it perfectly. We do not require you to solve this problem in this project, but feel free to experiment with how you handle paddle controls to reduce or even eliminate this problem. 7 Submission 1. Locate the Pong folder 2. Compress the folder to a zip file 3. Rename the zip file to P3.zip 4. Submit the renamed zip file to the submit server at https://submit.cs.umd.edu/. 8 Academic Integrity Make sure you read the academic integrity section of the syllabus so you understand what you must not do. Note that we check your submission against other students’ submissions and that we are required to report academic dishonesty cases to the University’s Office of Student Conduct. As stated in Section 2, you are expected to write the honor pledge as a comment near the top of each file you submit.

Option 1

Low Cost Option
Download this past answer in few clicks

23.99 USD

PURCHASE SOLUTION

Already member?


Option 2

Custom new solution created by our subject matter experts

GET A QUOTE