{"id":22320500,"url":"https://github.com/timothyjan/java-pong","last_synced_at":"2025-10-25T10:35:36.946Z","repository":{"id":65390474,"uuid":"590812418","full_name":"TimothyJan/Java-Pong","owner":"TimothyJan","description":"Java Pong Game","archived":false,"fork":false,"pushed_at":"2023-01-22T05:09:42.000Z","size":33,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T04:30:13.025Z","etag":null,"topics":["java","jframe"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TimothyJan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2023-01-19T09:14:41.000Z","updated_at":"2023-01-21T01:36:13.000Z","dependencies_parsed_at":"2023-02-12T14:30:44.760Z","dependency_job_id":null,"html_url":"https://github.com/TimothyJan/Java-Pong","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/TimothyJan/Java-Pong","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimothyJan%2FJava-Pong","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimothyJan%2FJava-Pong/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimothyJan%2FJava-Pong/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimothyJan%2FJava-Pong/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TimothyJan","download_url":"https://codeload.github.com/TimothyJan/Java-Pong/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimothyJan%2FJava-Pong/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270234669,"owners_count":24550171,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-13T02:00:09.904Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","jframe"],"created_at":"2024-12-04T00:13:52.887Z","updated_at":"2025-10-25T10:35:36.836Z","avatar_url":"https://github.com/TimothyJan.png","language":"Java","readme":"# Java-Pong\nJava Pong Game\n\n\u003ch3\u003eMain Menu\u003c/h3\u003e\n\u003cimg src=\"Screenshots/1-MainMenu.png\" alt=\"Main Menu\" width=\"75%\" height=\"75%\"\u003e\n\n\u003ch3\u003eGameplay\u003c/h3\u003e\n\u003cimg src=\"Screenshots/2-Game.png\" alt=\"Gameplay\" width=\"75%\" height=\"75%\"\u003e\n\n1-Creating the Window\n\u003cul\u003e\n    \u003cli\u003eCreate Window using JFrame methods in \u003ccode\u003eWindow.java\u003c/code\u003e.\u003c/li\u003e\n    \u003cli\u003eCreate \u003ccode\u003eConstants.java\u003c/code\u003e to hold constant values.\u003c/li\u003e\n    \u003cli\u003eCreate thread to run window.\u003c/li\u003e\n\u003c/ul\u003e\n\n2-The Game Loop\n\u003cul\u003e\n    \u003cli\u003eIn \u003ccode\u003eWindow.java\u003c/code\u003e, we want to call \u003ccode\u003eupdate\u003c/code\u003e method every frame of our game and we want to pass in how long it took to do the last frame.\u003c/li\u003e\n    \u003cli\u003eCreate \u003ccode\u003eTime.java\u003c/code\u003e to call Java's system get nano time to get the best time measurement on the OS we are running on.\u003c/li\u003e\n    \u003cli\u003eAdded code to \u003ccode\u003erun\u003c/code\u003e and \u003ccode\u003eupdate\u003c/code\u003e methods to check the frames per second(fps).\u003c/li\u003e\n    \u003cli\u003eImport \u003ccode\u003eGraphics2D\u003c/code\u003e to create Graphics \u003ccode\u003eg2\u003c/code\u003e in \u003ccode\u003eWindow\u003c/code\u003e method and update g2 in \u003ccode\u003eupdate\u003c/code\u003e method.\u003c/li\u003e\n\u003c/ul\u003e\n\n3-Handling User Input\n\u003cul\u003e\n    \u003cli\u003eCreate new class \u003ccode\u003eKL\u003c/code\u003e to implement KeyListener. Create methods \u003ccode\u003ekeyPressed\u003c/code\u003e, \u003ccode\u003ekeyReleased\u003c/code\u003e and \u003ccode\u003eisKeyPressed\u003c/code\u003e.\u003c/li\u003e\n    \u003cli\u003eInitialize new KL \u003ccode\u003ekeyListener\u003c/code\u003e in Window class and use using \u003ccode\u003ethis.addKeyListener(keyListener)\u003c/code\u003e in \u003ccode\u003epublic Window\u003c/code\u003e.\u003c/li\u003e\n    \u003cli\u003eAdd \u003ccode\u003ekeyListener\u003c/code\u003e to listen for \u003ccode\u003eKeyEvents\u003c/code\u003e in \u003ccode\u003eupdate\u003c/code\u003e method.\u003c/li\u003e\n\u003c/ul\u003e\n\n4-Drawing the Player\n\u003cul\u003e\n    \u003cli\u003eCreate paddles and ball on the screen and will use this to detect collisions.\u003c/li\u003e\n    \u003cli\u003eCreate class \u003ccode\u003eRect\u003c/code\u003e for paddle and ball.\u003c/li\u003e\n    \u003cli\u003eCreate new Constants for width/height/color for paddle/ball and padding.\u003c/li\u003e\n    \u003cli\u003eInitialize playerOne, ai, and ball as new \u003ccode\u003eRects\u003c/code\u003e in \u003ccode\u003epublic Window\u003c/code\u003e. Draw them in \u003ccode\u003eupdate\u003c/code\u003e method.\u003c/li\u003e\n\u003c/ul\u003e\n\n5-Making the Player Controller\n\u003cul\u003e\n    \u003cli\u003eImplement the PlayerController to move the player and ai.\u003c/li\u003e\n    \u003cli\u003eCreate new class \u003ccode\u003ePlayerController\u003c/code\u003e.\u003c/li\u003e\n    \u003cli\u003eInitialize \u003ccode\u003ePlayerController\u003c/code\u003e in \u003ccode\u003eWindow\u003c/code\u003e.\u003c/li\u003e\n    \u003cli\u003eFor smoother gameplay:\n        \u003cul\u003e\n            \u003cli\u003eChanged all int values to double values.\u003c/li\u003e\n            \u003cli\u003eIn \u003ccode\u003eupdate\u003c/code\u003e method, create an image \u003ccode\u003edbImage\u003c/code\u003e for double buffer image. Then create a Graphics \u003ccode\u003edbg\u003c/code\u003e for double buffer graphics.\u003c/li\u003e\n            \u003cli\u003eWe will draw everything to this dbg which will not be displayed to the user.\u003c/li\u003e\n            \u003cli\u003eThen we're going to return this dbg to our \u003ccode\u003edraw\u003c/code\u003e method and draw the image to the screen. \u003c/li\u003e\n            \u003cli\u003eThis way everything gets drawn incrementally on an off screen and then we swap buffers and show this buffer to the user.\u003c/li\u003e\n        \u003c/ul\u003e\n    \u003c/li\u003e\n    \u003cli\u003eCreate new constants \u003ccode\u003eTOOLBAR_HEIGHT\u003c/code\u003e and \u003ccode\u003eINSETS_BOTTOM\u003c/code\u003e to prevent paddles going off screen. \u003c/li\u003e\n    \u003cli\u003eCreate new constant \u003ccode\u003ePADDLE_SPEED\u003c/code\u003e for use in paddle movement.\u003c/li\u003e\n\u003c/ul\u003e\n\n6a - Moving the Ball\n\u003cul\u003e\n    \u003cli\u003eCreate new class \u003ccode\u003eBall\u003c/code\u003e to handle Ball movement and collisions.\u003c/li\u003e\n    \u003cli\u003eIn \u003ccode\u003eWindow.java\u003c/code\u003e, initialize \u003ccode\u003eBall ball\u003c/code\u003e and make sure it is updated in \u003ccode\u003eupdate\u003c/code\u003e method. Update and draw ball.\u003c/li\u003e\n\u003c/ul\u003e\n\n6-AI Controller\n\u003cul\u003e\n    \u003cli\u003eIn \u003ccode\u003ePlayerController\u003c/code\u003e,create a constructor for the AI that doesn't use the keyListener.\u003c/li\u003e\n    \u003cli\u003eCreate new class \u003ccode\u003eAIController\u003c/code\u003e. AI paddle will respond based on the ball being below or above the AI paddle.\u003c/li\u003e\n    \u003cli\u003eIn \u003ccode\u003eWindow\u003c/code\u003e, initialize a \u003ccode\u003eAIController\u003c/code\u003e for \u003ccode\u003eaiController\u003c/code\u003e. Update and draw ai.\u003c/li\u003e\n\u003c/ul\u003e\n\n7-Keeping Score\n\u003cul\u003e\n    \u003cli\u003eCreate new class \u003ccode\u003eText.java\u003c/code\u003e. \u003c/li\u003e\n    \u003cli\u003eCreate new constants for x/y positions for scores and score font size.\u003c/li\u003e\n    \u003cli\u003eIn \u003ccode\u003eWindow\u003c/code\u003e, create and initialize \u003ccode\u003eText leftScoreText\u003c/code\u003e/\u003ccode\u003erightScoreText\u003c/code\u003e.\u003c/li\u003e\n    \u003cli\u003eIn \u003ccode\u003eBall\u003c/code\u003e, add \u003ccode\u003eText leftScoreText\u003c/code\u003e/\u003ccode\u003erightScoreText\u003c/code\u003e as arguments to \u003ccode\u003eBall\u003c/code\u003e.\u003c/li\u003e\n    \u003cli\u003eCreate new constant for win score and add code to determine win condition after ball passes either paddle.\u003c/li\u003e\n\u003c/ul\u003e\n\n8-MainMenu\n\u003cul\u003e\n    \u003cli\u003eCreate new class MainMenu. Create \u003ccode\u003eTexts\u003c/code\u003e for \u003ccode\u003estartGame\u003c/code\u003e, \u003ccode\u003eexitGame\u003c/code\u003e and \u003ccode\u003epongTitle\u003c/code\u003e and draw them.\u003c/li\u003e\n    \u003cli\u003eCreate new class \u003ccode\u003eML\u003c/code\u003e for Mouse Listener to listen for mouse hover/click on the texts. Create and initialize \u003ccode\u003eML\u003c/code\u003e in \u003ccode\u003eMainMenu\u003c/code\u003e.\u003c/li\u003e\n    \u003cli\u003eIn \u003ccode\u003eupdate\u003c/code\u003e in \u003ccode\u003eMainMenu\u003c/code\u003e add code to change color when hovering over startGame and exitGame.\u003c/li\u003e\n    \u003cli\u003eUpdate \u003ccode\u003eMain\u003c/code\u003e for GameWindow(1) or MainMenu(0) states. Create method \u003ccode\u003echangeState\u003c/code\u003e to change states. \u003c/li\u003e\n    \u003cli\u003eIn \u003ccode\u003eMainMenu\u003c/code\u003e, update mouse hover with \u003ccode\u003eMain.changeState(1);\u003c/code\u003e. Add \u003ccode\u003ethis.dispose();\u003c/code\u003e to \u003ccode\u003erun\u003c/code\u003e method when game state is changed to close MainMenu window.\u003c/li\u003e\n    \u003cli\u003eIn \u003ccode\u003eWindow\u003c/code\u003e, add \u003ccode\u003ethis.dispose();\u003c/code\u003e to \u003ccode\u003erun\u003c/code\u003e method when game state is changed to close gameWindow.\u003c/li\u003e\n    \u003cli\u003eIn \u003ccode\u003eBall\u003c/code\u003e, change the game state to 2 when player/ai wins and kill all threads.\u003c/li\u003e\n\u003c/ul\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimothyjan%2Fjava-pong","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimothyjan%2Fjava-pong","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimothyjan%2Fjava-pong/lists"}