diff --git a/The-Pacman-Game-main/.github/ISSUE_TEMPLATE/bug_report.md b/The-Pacman-Game-main/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..3c42ccc --- /dev/null +++ b/The-Pacman-Game-main/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,40 @@ +--- +name: Bug Report +about: Create a report to help improve the project +title: "[BUG] " +labels: bug +assignees: '' + +--- + +# Bug Report + +## Description + +Describe the bug clearly. + +--- + +## Steps to Reproduce + +1. +2. +3. + +--- + +## Expected Behavior + +What should happen? + +--- + +## Screenshots + +Add screenshots if applicable. + +--- + +## Additional Context + +Add any other context here. diff --git a/The-Pacman-Game-main/.github/ISSUE_TEMPLATE/feature_request.md b/The-Pacman-Game-main/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..182ad1a --- /dev/null +++ b/The-Pacman-Game-main/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,32 @@ +--- +name: Feature Request +about: Suggest a new feature for the project +title: "[FEATURE] " +labels: enhancement +assignees: '' + +--- + +# Feature Request + +## Feature Description + +Describe the feature clearly. + +--- + +## Why is this feature useful? + +Explain why this feature should be added. + +--- + +## Possible Solution + +Describe your idea or approach. + +--- + +## Additional Context + +Add screenshots or references if needed. diff --git a/The-Pacman-Game-main/.github/pull_request_template.md b/The-Pacman-Game-main/.github/pull_request_template.md new file mode 100644 index 0000000..b18b49a --- /dev/null +++ b/The-Pacman-Game-main/.github/pull_request_template.md @@ -0,0 +1,32 @@ +# Pull Request + +## Description + +Please include a summary of the changes and the related issue. + +Fixes # (issue number) + +--- + +## Type of Change + +- [ ] Bug fix +- [ ] New feature +- [ ] UI improvement +- [ ] Documentation update +- [ ] Performance improvement + +--- + +## Checklist + +- [ ] My code follows the project style +- [ ] I tested my changes +- [ ] I have updated documentation if needed +- [ ] My changes generate no new warnings + +--- + +## Screenshots (if applicable) + +Add screenshots here. diff --git a/The-Pacman-Game-main/.gitignore b/The-Pacman-Game-main/.gitignore new file mode 100644 index 0000000..420eadd --- /dev/null +++ b/The-Pacman-Game-main/.gitignore @@ -0,0 +1,13 @@ +*.class +*.log +*.ctxt +.DS_Store + +.idea/ +.vscode/ + +out/ +build/ +target/ + +*.iml diff --git a/The-Pacman-Game-main/CODE_OF_CONDUCT.md b/The-Pacman-Game-main/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..5c963a4 --- /dev/null +++ b/The-Pacman-Game-main/CODE_OF_CONDUCT.md @@ -0,0 +1,35 @@ +# Code of Conduct + +## Our Pledge + +We are committed to providing a friendly, safe, and welcoming environment for everyone. + +--- + +## Expected Behavior + +- Be respectful to everyone +- Help beginners +- Use welcoming language +- Accept constructive feedback +- Collaborate professionally + +--- + +## Unacceptable Behavior + +- Harassment +- Personal attacks +- Trolling +- Discrimination +- Spam or abusive comments + +--- + +## Enforcement + +Project maintainers are responsible for maintaining a healthy environment and may take appropriate action when needed. + +--- + +Thank you for helping make open source welcoming for everyone! diff --git a/The-Pacman-Game-main/CONTRIBUTING.md b/The-Pacman-Game-main/CONTRIBUTING.md new file mode 100644 index 0000000..820969e --- /dev/null +++ b/The-Pacman-Game-main/CONTRIBUTING.md @@ -0,0 +1,47 @@ +# Contributing to The-Pacman-Game + +Thank you for your interest in contributing to this project! + +We welcome all contributors who want to improve this Pac-Man game and learn open-source development. + +--- + +## Steps to Contribute + +1. Fork the repository +2. Clone your forked repository +3. Create a new branch +4. Make your changes +5. Commit your changes +6. Push the code +7. Create a Pull Request + +--- + +## Contribution Rules + +- Follow Java coding standards +- Write clean and readable code +- Test your code before submitting +- Do not make unrelated changes in one PR +- Keep pull requests small and focused + +--- + +## Beginner Friendly Tasks + +- Improve UI design +- Add sound effects +- Improve ghost AI +- Add new levels +- Add pause menu +- Fix bugs +- Improve animations + +--- + +## Need Help? + +Feel free to open an issue for discussion. + +Happy Coding! diff --git a/The-Pacman-Game-main/LICENSE b/The-Pacman-Game-main/LICENSE new file mode 100644 index 0000000..cedf875 --- /dev/null +++ b/The-Pacman-Game-main/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 dishu4u + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/The-Pacman-Game-main/README.md b/The-Pacman-Game-main/README.md new file mode 100644 index 0000000..6cd7551 --- /dev/null +++ b/The-Pacman-Game-main/README.md @@ -0,0 +1,112 @@ +

+

🎮 The-Pacman-Game

+

+ Classic Pac-Man Game built using Java Swing/AWT +

+

+ +

+ + + + +

+ +A classic Pac-Man arcade game built using Java Swing/AWT. + +This project is designed for Java learners and open-source contributors interested in 2D game development. + +---# 📸 Screenshots + +## Gameplay + + + + +# 🚀 Features + +- Classic Pac-Man gameplay +- Ghost AI movement +- Keyboard controls +- Tile-based game board +- Sprite animations +- Score tracking +- Smooth gameplay mechanics +- Beginner-friendly Java project + +--- + +# 🛠️ Tech Stack + +- Java +- Swing +- AWT + +--- + +# 📂 Project Structure + +```bash +pacman-java/ +│── src/ +│── assets/ +│── README.md +``` + +--- + +# ▶️ How to Run + +1. Clone the repository + +```bash +git clone https://github.com/dishu4u/The-Pacman-Game.git +``` + +2. Open the project in your Java IDE + +3. Compile and run the game + +--- + +# 🤝 Contributing + +Contributions are welcome! + +Please read the CONTRIBUTING.md file before making contributions. + +--- + +# 📌 Beginner Friendly Issues + +This project contains beginner-friendly issues for open-source contributors. + +Look for labels like: + +- good first issue +- beginner +- enhancement +- bug + +--- + +# 🌟 Future Improvements + +- Add multiplayer mode +- Add sound effects +- Add pause menu +- Add levels +- Improve ghost AI +- Add leaderboard system + +--- + +# 📜 License + +This project is licensed under the MIT License. + +--- + +# ⭐ Support + +If you like this project, give it a star on GitHub! diff --git a/The-Pacman-Game-main/assets/screenshots/pacman_screenshot_1.png b/The-Pacman-Game-main/assets/screenshots/pacman_screenshot_1.png new file mode 100644 index 0000000..454e287 Binary files /dev/null and b/The-Pacman-Game-main/assets/screenshots/pacman_screenshot_1.png differ diff --git a/The-Pacman-Game-main/assets/screenshots/pacman_screenshot_2.png b/The-Pacman-Game-main/assets/screenshots/pacman_screenshot_2.png new file mode 100644 index 0000000..a49fce9 Binary files /dev/null and b/The-Pacman-Game-main/assets/screenshots/pacman_screenshot_2.png differ diff --git a/The-Pacman-Game-main/pacman-java/App.java b/The-Pacman-Game-main/pacman-java/App.java new file mode 100644 index 0000000..51f76b8 --- /dev/null +++ b/The-Pacman-Game-main/pacman-java/App.java @@ -0,0 +1,12 @@ +import javax.swing.SwingUtilities; + +public class App { + + public static void main(String[] args) { + + SwingUtilities.invokeLater(() -> { + new UserPanel(); + }); + + } +} \ No newline at end of file diff --git a/The-Pacman-Game-main/pacman-java/PacMan.java b/The-Pacman-Game-main/pacman-java/PacMan.java new file mode 100644 index 0000000..b335aa1 --- /dev/null +++ b/The-Pacman-Game-main/pacman-java/PacMan.java @@ -0,0 +1,469 @@ +import java.awt.*; +import java.awt.event.*; +import java.util.HashSet; +import java.util.Random; +import javax.swing.*; + +public class PacMan extends JPanel implements ActionListener, KeyListener { + + class Block { + int x; + int y; + int width; + int height; + Image image; + + int startX; + int startY; + char direction = 'U'; // U D L R + int velocityX = 0; + int velocityY = 0; + + Block(Image image, int x, int y, int width, int height) { + this.image = image; + this.x = x; + this.y = y; + this.width = width; + this.height = height; + this.startX = x; + this.startY = y; + } + + void updateDirection(char direction) { + char prevDirection = this.direction; + this.direction = direction; + updateVelocity(); + this.x += this.velocityX; + this.y += this.velocityY; + for (Block wall : walls) { + if (collision(this, wall)) { + this.x -= this.velocityX; + this.y -= this.velocityY; + this.direction = prevDirection; + updateVelocity(); + } + } + } + + void updateVelocity() { + if (this.direction == 'U') { + this.velocityX = 0; + this.velocityY = -tileSize/4; + } + else if (this.direction == 'D') { + this.velocityX = 0; + this.velocityY = tileSize/4; + } + else if (this.direction == 'L') { + this.velocityX = -tileSize/4; + this.velocityY = 0; + } + else if (this.direction == 'R') { + this.velocityX = tileSize/4; + this.velocityY = 0; + } + } + + void reset() { + this.x = this.startX; + this.y = this.startY; + } + } + + private int rowCount = 21; + private int columnCount = 19; + private int tileSize = 32; + private int boardWidth = columnCount * tileSize; + private int boardHeight = rowCount * tileSize; + + private Image wallImage; + private Image blueGhostImage; + private Image orangeGhostImage; + private Image pinkGhostImage; + private Image redGhostImage; + + private Image pacmanUpImage; + private Image pacmanDownImage; + private Image pacmanLeftImage; + private Image pacmanRightImage; + + //X = wall, O = skip, P = pac man, ' ' = food + //Ghosts: b = blue, o = orange, p = pink, r = red + private String[] tileMap = { + "XXXXXXXXXXXXXXXXXXX", + "X X X", + "X XX XXX X XXX XX X", + "X X", + "X XX X XXXXX X XX X", + "X X X X", + "XXXX XXXX XXXX XXXX", + "OOOX X X XOOO", + "XXXX X XXrXX X XXXX", + "X bpo X", + "XXXX X XXXXX X XXXX", + "OOOX X X XOOO", + "XXXX X XXXXX X XXXX", + "X X X", + "X XX XXX X XXX XX X", + "X X P X X", + "XX X X XXXXX X X XX", + "X X X X X", + "X XXXXXX X XXXXXX X", + "X X", + "XXXXXXXXXXXXXXXXXXX" + }; + + HashSet walls; + HashSet foods; + HashSet ghosts; + Block pacman; + + Timer gameLoop; + char[] directions = {'U', 'D', 'L', 'R'}; //up down left right + Random random = new Random(); + int score = 0; + int lives = 3; + boolean gameOver = false; + boolean gameOverDialogShown = false; + + PacMan() { + + + + setPreferredSize(new Dimension(boardWidth, boardHeight)); + setBackground(Color.BLACK); + addKeyListener(this); + setFocusable(true); + + //load images + wallImage = new ImageIcon(getClass().getResource("./wall.png")).getImage(); + blueGhostImage = new ImageIcon(getClass().getResource("./blueGhost.png")).getImage(); + orangeGhostImage = new ImageIcon(getClass().getResource("./orangeGhost.png")).getImage(); + pinkGhostImage = new ImageIcon(getClass().getResource("./pinkGhost.png")).getImage(); + redGhostImage = new ImageIcon(getClass().getResource("./redGhost.png")).getImage(); + + pacmanUpImage = new ImageIcon(getClass().getResource("./pacmanUp.png")).getImage(); + pacmanDownImage = new ImageIcon(getClass().getResource("./pacmanDown.png")).getImage(); + pacmanLeftImage = new ImageIcon(getClass().getResource("./pacmanLeft.png")).getImage(); + pacmanRightImage = new ImageIcon(getClass().getResource("./pacmanRight.png")).getImage(); + + loadMap(); +SoundManager.playBackgroundMusic("./bg_music.wav"); + for (Block ghost : ghosts) { + char newDirection = directions[random.nextInt(4)]; + ghost.updateDirection(newDirection); + } + //how long it takes to start timer, milliseconds gone between frames + gameLoop = new Timer(50, this); //20fps (1000/50) + gameLoop.start(); + + } + + public void loadMap() { + walls = new HashSet(); + foods = new HashSet(); + ghosts = new HashSet(); + + for (int r = 0; r < rowCount; r++) { + for (int c = 0; c < columnCount; c++) { + String row = tileMap[r]; + char tileMapChar = row.charAt(c); + + int x = c*tileSize; + int y = r*tileSize; + + if (tileMapChar == 'X') { //block wall + Block wall = new Block(wallImage, x, y, tileSize, tileSize); + walls.add(wall); + } + else if (tileMapChar == 'b') { //blue ghost + Block ghost = new Block(blueGhostImage, x, y, tileSize, tileSize); + ghosts.add(ghost); + } + else if (tileMapChar == 'o') { //orange ghost + Block ghost = new Block(orangeGhostImage, x, y, tileSize, tileSize); + ghosts.add(ghost); + } + else if (tileMapChar == 'p') { //pink ghost + Block ghost = new Block(pinkGhostImage, x, y, tileSize, tileSize); + ghosts.add(ghost); + } + else if (tileMapChar == 'r') { //red ghost + Block ghost = new Block(redGhostImage, x, y, tileSize, tileSize); + ghosts.add(ghost); + } + else if (tileMapChar == 'P') { //pacman + pacman = new Block(pacmanRightImage, x, y, tileSize, tileSize); + } + else if (tileMapChar == ' ') { //food + Block food = new Block(null, x + 14, y + 14, 4, 4); + foods.add(food); + } + } + } + } + + public void paintComponent(Graphics g) { + super.paintComponent(g); + draw(g); + } + + public void draw(Graphics g) { + g.drawImage(pacman.image, pacman.x, pacman.y, pacman.width, pacman.height, null); + + for (Block ghost : ghosts) { + g.drawImage(ghost.image, ghost.x, ghost.y, ghost.width, ghost.height, null); + } + + for (Block wall : walls) { + g.drawImage(wall.image, wall.x, wall.y, wall.width, wall.height, null); + } + + g.setColor(Color.WHITE); + for (Block food : foods) { + g.fillRect(food.x, food.y, food.width, food.height); + } + String soundStatus = + SoundManager.isMuted() + ? "MUTED" + : "SOUND ON"; + +g.drawString( + soundStatus, + boardWidth - 150, + 20 +); + //score + g.setFont(new Font("Arial", Font.PLAIN, 18)); + if (gameOver) { + g.drawString("Game Over: " + String.valueOf(score), tileSize/2, tileSize/2); + } + else { + g.drawString("x" + String.valueOf(lives) + " Score: " + String.valueOf(score), tileSize/2, tileSize/2); + } + } + private void restartGame() { + + loadMap(); + + resetPositions(); + + lives = 3; + score = 0; + + gameOver = false; + gameOverDialogShown = false; + + gameLoop.start(); +} +private void backToMenu() { + + JFrame currentFrame = + (JFrame) SwingUtilities.getWindowAncestor(this); + + if (currentFrame != null) { + currentFrame.dispose(); + } + + SwingUtilities.invokeLater(() -> { + new UserPanel(); + }); +} +private void showGameOverMenu() { + + String[] options = { + "Restart", + "Back", + "Exit" + }; + + int choice = JOptionPane.showOptionDialog( + this, + "Game Over!\n\nScore: " + score, + "Pac-Man", + JOptionPane.DEFAULT_OPTION, + JOptionPane.INFORMATION_MESSAGE, + null, + options, + options[0] + ); + + if (choice == 0) { + + restartGame(); + + } + else if (choice == 1) { + + backToMenu(); + + } + else { + + System.exit(0); + } +} + public void move() { + pacman.x += pacman.velocityX; + pacman.y += pacman.velocityY; + + //check wall collisions + for (Block wall : walls) { + if (collision(pacman, wall)) { + pacman.x -= pacman.velocityX; + pacman.y -= pacman.velocityY; + break; + } + } + + //check ghost collisions + for (Block ghost : ghosts) { +if (collision(ghost, pacman)) { + + SoundManager.playSound( + "pacman-java/sounds/collision.wav" + ); + + lives--; +System.out.println("Lives = " + lives); + if (lives <= 0) { + + SoundManager.stopBackgroundMusic(); + +SoundManager.playBackgroundMusic( + "pacman-java/sounds/game_music.wav" +); + SoundManager.playSound( + "pacman-java/sounds/gameover.wav" + ); + + gameOver = true; + + return; + } + + resetPositions(); +} + if (ghost.y == tileSize*9 && ghost.direction != 'U' && ghost.direction != 'D') { + ghost.updateDirection('U'); + } + ghost.x += ghost.velocityX; + ghost.y += ghost.velocityY; + for (Block wall : walls) { + if (collision(ghost, wall) || ghost.x <= 0 || ghost.x + ghost.width >= boardWidth) { + ghost.x -= ghost.velocityX; + ghost.y -= ghost.velocityY; + char newDirection = directions[random.nextInt(4)]; + ghost.updateDirection(newDirection); + } + } + } + + //check food collision + Block foodEaten = null; + for (Block food : foods) { +if (collision(pacman, food)) { + + foodEaten = food; + score += 10; + + SoundManager.playSound( + "pacman-java/sounds/eat.wav" + ); +} + } + foods.remove(foodEaten); + + if (foods.isEmpty()) { + loadMap(); + resetPositions(); + } + } + + public boolean collision(Block a, Block b) { + return a.x < b.x + b.width && + a.x + a.width > b.x && + a.y < b.y + b.height && + a.y + a.height > b.y; + } + + public void resetPositions() { + pacman.reset(); + pacman.velocityX = 0; + pacman.velocityY = 0; + for (Block ghost : ghosts) { + ghost.reset(); + char newDirection = directions[random.nextInt(4)]; + ghost.updateDirection(newDirection); + } + } + + @Override +public void actionPerformed(ActionEvent e) { + + move(); + repaint(); + + if (gameOver && !gameOverDialogShown) { + + gameOverDialogShown = true; + + gameLoop.stop(); + + showGameOverMenu(); +} +} + + @Override + public void keyTyped(KeyEvent e) {} + + @Override + public void keyPressed(KeyEvent e) {} + + @Override + public void keyReleased(KeyEvent e) { +if (e.getKeyCode() == KeyEvent.VK_M) { + + SoundManager.toggleMute(); + + repaint(); // update text immediately + + return; +} + if (gameOver) { + loadMap(); + resetPositions(); + lives = 3; + score = 0; + gameOver = false; + gameLoop.start(); + } + // System.out.println("KeyEvent: " + e.getKeyCode()); + if (e.getKeyCode() == KeyEvent.VK_UP) { + pacman.updateDirection('U'); + } + else if (e.getKeyCode() == KeyEvent.VK_DOWN) { + pacman.updateDirection('D'); + } + else if (e.getKeyCode() == KeyEvent.VK_LEFT) { + pacman.updateDirection('L'); + } + else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { + pacman.updateDirection('R'); + } + + if (pacman.direction == 'U') { + pacman.image = pacmanUpImage; + } + else if (pacman.direction == 'D') { + pacman.image = pacmanDownImage; + } + else if (pacman.direction == 'L') { + pacman.image = pacmanLeftImage; + } + else if (pacman.direction == 'R') { + pacman.image = pacmanRightImage; + } + } +} + diff --git a/The-Pacman-Game-main/pacman-java/SoundManager.java b/The-Pacman-Game-main/pacman-java/SoundManager.java new file mode 100644 index 0000000..6592eef --- /dev/null +++ b/The-Pacman-Game-main/pacman-java/SoundManager.java @@ -0,0 +1,137 @@ +import javax.sound.sampled.*; +import java.io.File; + +public class SoundManager { + + private static Clip backgroundClip; + private static boolean muted = false; + + // ============================= + // Background Music + // ============================= + public static void playBackgroundMusic(String path) { + + if (muted) return; + + try { + + stopBackgroundMusic(); + + AudioInputStream audio = + AudioSystem.getAudioInputStream( + new File(path)); + + backgroundClip = AudioSystem.getClip(); + + backgroundClip.open(audio); + + // Lower music volume + FloatControl gainControl = + (FloatControl) backgroundClip.getControl( + FloatControl.Type.MASTER_GAIN); + + gainControl.setValue(-10.0f); + + backgroundClip.loop( + Clip.LOOP_CONTINUOUSLY); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + // ============================= + // Stop Music + // ============================= + public static void stopBackgroundMusic() { + + if (backgroundClip != null) { + + backgroundClip.stop(); + backgroundClip.close(); + } + } + + // ============================= + // Normal Sound Effects + // ============================= + public static void playSound(String path) { + + if (muted) return; + + try { + + AudioInputStream audio = + AudioSystem.getAudioInputStream( + new File(path)); + + Clip clip = AudioSystem.getClip(); + + clip.open(audio); + + FloatControl gainControl = + (FloatControl) clip.getControl( + FloatControl.Type.MASTER_GAIN); + + gainControl.setValue(4.0f); + + clip.start(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + // ============================= + // Game Over Sound + // ============================= + public static void playGameOverSound(String path) { + + if (muted) return; + + try { + + AudioInputStream audio = + AudioSystem.getAudioInputStream( + new File(path)); + + Clip clip = AudioSystem.getClip(); + + clip.open(audio); + + FloatControl gainControl = + (FloatControl) clip.getControl( + FloatControl.Type.MASTER_GAIN); + + gainControl.setValue(10.0f); + + clip.start(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + // ============================= + // Mute / Unmute + // ============================= + public static void toggleMute() { + + muted = !muted; + + if (backgroundClip != null) { + + if (muted) { + backgroundClip.stop(); + } + else { + backgroundClip.loop( + Clip.LOOP_CONTINUOUSLY); + } + } + } + + public static boolean isMuted() { + return muted; + } +} \ No newline at end of file diff --git a/The-Pacman-Game-main/pacman-java/UserPanel.java b/The-Pacman-Game-main/pacman-java/UserPanel.java new file mode 100644 index 0000000..faa04a0 --- /dev/null +++ b/The-Pacman-Game-main/pacman-java/UserPanel.java @@ -0,0 +1,233 @@ +import javax.swing.*; +import javax.swing.border.EmptyBorder; +import java.awt.*; + +public class UserPanel extends JFrame { + + private JTextField playerField; + + + public UserPanel() { + +SoundManager.playBackgroundMusic( + "pacman-java/sounds/menu_music.wav" +); + setTitle("PAC-MAN"); + setSize(900, 650); + setLocationRelativeTo(null); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + JPanel background = new JPanel(new BorderLayout()) { + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + + Graphics2D g2 = (Graphics2D) g; + + GradientPaint gp = new GradientPaint( + 0, 0, + Color.BLACK, + 0, getHeight(), + new Color(0, 0, 90)); + + g2.setPaint(gp); + g2.fillRect(0, 0, getWidth(), getHeight()); + } + }; + + background.setBorder(new EmptyBorder(20, 20, 20, 20)); + + // ================= TITLE ================= + + JPanel titlePanel = new JPanel(); + titlePanel.setOpaque(false); + + JLabel title = new JLabel("PAC-MAN"); + title.setForeground(Color.YELLOW); + title.setFont(new Font("Arial", Font.BOLD, 52)); + + titlePanel.add(title); + + background.add(titlePanel, BorderLayout.NORTH); + + // ================= CENTER ================= + + JPanel centerPanel = new JPanel(new GridLayout(1, 2, 25, 0)); + centerPanel.setOpaque(false); + + // LEFT CARD + + JPanel leftCard = new JPanel(); + leftCard.setLayout(new BoxLayout(leftCard, BoxLayout.Y_AXIS)); + leftCard.setBackground(new Color(20, 20, 20)); + leftCard.setBorder(BorderFactory.createCompoundBorder( + BorderFactory.createLineBorder(Color.YELLOW, 2), + new EmptyBorder(20, 20, 20, 20))); + + JLabel welcome = new JLabel("WELCOME PLAYER"); + welcome.setAlignmentX(Component.CENTER_ALIGNMENT); + welcome.setForeground(Color.YELLOW); + welcome.setFont(new Font("Arial", Font.BOLD, 24)); + + JLabel desc = new JLabel( + "
" + + "Enter your name and begin your journey.
" + + "Collect pellets, avoid ghosts and score high." + + "
" + ); + + desc.setAlignmentX(Component.CENTER_ALIGNMENT); + desc.setForeground(Color.WHITE); + + JLabel playerLabel = new JLabel("PLAYER NAME"); + playerLabel.setForeground(Color.YELLOW); + playerLabel.setFont(new Font("Arial", Font.BOLD, 18)); + + playerField = new JTextField(); + playerField.setMaximumSize(new Dimension(300, 40)); + playerField.setFont(new Font("Arial", Font.PLAIN, 18)); + + JButton startBtn = createButton("▶ START GAME"); + JButton exitBtn = createButton("✖ EXIT"); + + startBtn.addActionListener(e -> startGame()); + exitBtn.addActionListener(e -> System.exit(0)); + + leftCard.add(welcome); + leftCard.add(Box.createVerticalStrut(20)); + leftCard.add(desc); + leftCard.add(Box.createVerticalStrut(40)); + leftCard.add(playerLabel); + leftCard.add(Box.createVerticalStrut(10)); + leftCard.add(playerField); + leftCard.add(Box.createVerticalStrut(30)); + leftCard.add(startBtn); + leftCard.add(Box.createVerticalStrut(15)); + leftCard.add(exitBtn); + + // RIGHT CARD + + JPanel rightCard = new JPanel(); + rightCard.setLayout(new BoxLayout(rightCard, BoxLayout.Y_AXIS)); + rightCard.setBackground(new Color(20, 20, 20)); + rightCard.setBorder(BorderFactory.createCompoundBorder( + BorderFactory.createLineBorder(Color.CYAN, 2), + new EmptyBorder(20, 20, 20, 20))); + + JLabel controlTitle = new JLabel("GAME CONTROLS"); + controlTitle.setAlignmentX(Component.CENTER_ALIGNMENT); + controlTitle.setForeground(Color.CYAN); + controlTitle.setFont(new Font("Arial", Font.BOLD, 24)); + + JTextArea controls = new JTextArea( + """ + ↑ Move Up + + ↓ Move Down + + ← Move Left + + → Move Right + + M = Mute / Unmute + + OBJECTIVE + + • Eat all pellets + • Avoid ghosts + • Score maximum points + • Survive with 3 lives + """ + ); + + controls.setEditable(false); + controls.setFocusable(false); + controls.setBackground(new Color(20, 20, 20)); + controls.setForeground(Color.WHITE); + controls.setFont(new Font("Segoe UI", Font.PLAIN, 18)); + + rightCard.add(controlTitle); + rightCard.add(Box.createVerticalStrut(20)); + rightCard.add(controls); + + centerPanel.add(leftCard); + centerPanel.add(rightCard); + + background.add(centerPanel, BorderLayout.CENTER); + + // ================= FOOTER ================= + + JLabel footer = new JLabel( + "PAC-MAN • Java Swing Edition", + SwingConstants.CENTER); + + footer.setForeground(Color.LIGHT_GRAY); + + background.add(footer, BorderLayout.SOUTH); + + add(background); + setVisible(true); + } + + private JButton createButton(String text) { + + JButton button = new JButton(text); + + button.setAlignmentX(Component.CENTER_ALIGNMENT); + button.setMaximumSize(new Dimension(250, 45)); + + button.setFont(new Font("Arial", Font.BOLD, 18)); + + button.setBackground(Color.YELLOW); + button.setForeground(Color.BLACK); + + button.setFocusPainted(false); + + return button; + } + + private void startGame() { +SoundManager.stopBackgroundMusic(); + +SoundManager.playBackgroundMusic( + "pacman-java/sounds/game_music.wav" +); + String playerName = playerField.getText().trim(); + + if (playerName.isEmpty()) { + + JOptionPane.showMessageDialog( + this, + "Please enter your name!" + ); + + return; + } + + JFrame frame = new JFrame("Pac Man - " + playerName); + + ImageIcon icon = + new ImageIcon( + App.class.getResource("pacmanRight.png") + ); + + frame.setIconImage(icon.getImage()); + + PacMan pacmanGame = new PacMan(); + + frame.add(pacmanGame); + frame.pack(); + + frame.setLocationRelativeTo(null); + frame.setResizable(false); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + frame.setVisible(true); + + pacmanGame.requestFocus(); + + dispose(); + + } + +} \ No newline at end of file diff --git a/The-Pacman-Game-main/pacman-java/blueGhost.png b/The-Pacman-Game-main/pacman-java/blueGhost.png new file mode 100644 index 0000000..e1ee979 Binary files /dev/null and b/The-Pacman-Game-main/pacman-java/blueGhost.png differ diff --git a/The-Pacman-Game-main/pacman-java/cherry.png b/The-Pacman-Game-main/pacman-java/cherry.png new file mode 100644 index 0000000..45c4f31 Binary files /dev/null and b/The-Pacman-Game-main/pacman-java/cherry.png differ diff --git a/The-Pacman-Game-main/pacman-java/cherry2.png b/The-Pacman-Game-main/pacman-java/cherry2.png new file mode 100644 index 0000000..6dea0ca Binary files /dev/null and b/The-Pacman-Game-main/pacman-java/cherry2.png differ diff --git a/The-Pacman-Game-main/pacman-java/desktop.ini b/The-Pacman-Game-main/pacman-java/desktop.ini new file mode 100644 index 0000000..03fd910 Binary files /dev/null and b/The-Pacman-Game-main/pacman-java/desktop.ini differ diff --git a/The-Pacman-Game-main/pacman-java/orangeGhost.png b/The-Pacman-Game-main/pacman-java/orangeGhost.png new file mode 100644 index 0000000..bcd1cb8 Binary files /dev/null and b/The-Pacman-Game-main/pacman-java/orangeGhost.png differ diff --git a/The-Pacman-Game-main/pacman-java/pacmanDown.png b/The-Pacman-Game-main/pacman-java/pacmanDown.png new file mode 100644 index 0000000..2c24dbe Binary files /dev/null and b/The-Pacman-Game-main/pacman-java/pacmanDown.png differ diff --git a/The-Pacman-Game-main/pacman-java/pacmanLeft.png b/The-Pacman-Game-main/pacman-java/pacmanLeft.png new file mode 100644 index 0000000..168f495 Binary files /dev/null and b/The-Pacman-Game-main/pacman-java/pacmanLeft.png differ diff --git a/The-Pacman-Game-main/pacman-java/pacmanRight.png b/The-Pacman-Game-main/pacman-java/pacmanRight.png new file mode 100644 index 0000000..7e370a0 Binary files /dev/null and b/The-Pacman-Game-main/pacman-java/pacmanRight.png differ diff --git a/The-Pacman-Game-main/pacman-java/pacmanUp.png b/The-Pacman-Game-main/pacman-java/pacmanUp.png new file mode 100644 index 0000000..9f4a39b Binary files /dev/null and b/The-Pacman-Game-main/pacman-java/pacmanUp.png differ diff --git a/The-Pacman-Game-main/pacman-java/pinkGhost.png b/The-Pacman-Game-main/pacman-java/pinkGhost.png new file mode 100644 index 0000000..12c3f84 Binary files /dev/null and b/The-Pacman-Game-main/pacman-java/pinkGhost.png differ diff --git a/The-Pacman-Game-main/pacman-java/powerFood.png b/The-Pacman-Game-main/pacman-java/powerFood.png new file mode 100644 index 0000000..3e91ad9 Binary files /dev/null and b/The-Pacman-Game-main/pacman-java/powerFood.png differ diff --git a/The-Pacman-Game-main/pacman-java/redGhost.png b/The-Pacman-Game-main/pacman-java/redGhost.png new file mode 100644 index 0000000..cfd374e Binary files /dev/null and b/The-Pacman-Game-main/pacman-java/redGhost.png differ diff --git a/The-Pacman-Game-main/pacman-java/scaredGhost.png b/The-Pacman-Game-main/pacman-java/scaredGhost.png new file mode 100644 index 0000000..9e26fff Binary files /dev/null and b/The-Pacman-Game-main/pacman-java/scaredGhost.png differ diff --git a/The-Pacman-Game-main/pacman-java/sounds/collision.wav b/The-Pacman-Game-main/pacman-java/sounds/collision.wav new file mode 100644 index 0000000..b89a306 Binary files /dev/null and b/The-Pacman-Game-main/pacman-java/sounds/collision.wav differ diff --git a/The-Pacman-Game-main/pacman-java/sounds/eat.wav b/The-Pacman-Game-main/pacman-java/sounds/eat.wav new file mode 100644 index 0000000..a162e31 Binary files /dev/null and b/The-Pacman-Game-main/pacman-java/sounds/eat.wav differ diff --git a/The-Pacman-Game-main/pacman-java/sounds/game_music.wav b/The-Pacman-Game-main/pacman-java/sounds/game_music.wav new file mode 100644 index 0000000..201e2f5 Binary files /dev/null and b/The-Pacman-Game-main/pacman-java/sounds/game_music.wav differ diff --git a/The-Pacman-Game-main/pacman-java/sounds/gameover.wav b/The-Pacman-Game-main/pacman-java/sounds/gameover.wav new file mode 100644 index 0000000..4ffd944 Binary files /dev/null and b/The-Pacman-Game-main/pacman-java/sounds/gameover.wav differ diff --git a/The-Pacman-Game-main/pacman-java/sounds/menu_music.wav b/The-Pacman-Game-main/pacman-java/sounds/menu_music.wav new file mode 100644 index 0000000..a065200 Binary files /dev/null and b/The-Pacman-Game-main/pacman-java/sounds/menu_music.wav differ diff --git a/The-Pacman-Game-main/pacman-java/wall.png b/The-Pacman-Game-main/pacman-java/wall.png new file mode 100644 index 0000000..ab12c87 Binary files /dev/null and b/The-Pacman-Game-main/pacman-java/wall.png differ diff --git a/pacman-java/desktop.ini b/pacman-java/desktop.ini index e65e49d..03fd910 100644 Binary files a/pacman-java/desktop.ini and b/pacman-java/desktop.ini differ diff --git a/pacman-java/out/desktop.ini b/pacman-java/out/desktop.ini index e65e49d..03fd910 100644 Binary files a/pacman-java/out/desktop.ini and b/pacman-java/out/desktop.ini differ diff --git a/pacman-java/out/production/desktop.ini b/pacman-java/out/production/desktop.ini index e65e49d..03fd910 100644 Binary files a/pacman-java/out/production/desktop.ini and b/pacman-java/out/production/desktop.ini differ diff --git a/pacman-java/out/production/pacman-java/desktop.ini b/pacman-java/out/production/pacman-java/desktop.ini index e65e49d..03fd910 100644 Binary files a/pacman-java/out/production/pacman-java/desktop.ini and b/pacman-java/out/production/pacman-java/desktop.ini differ