Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Program: .java Last Date of this Revision: April , 2019
- Purpose:
- Author: Kyle James
- School: LBHS
- Course: Computer Programming 30
- */
- package pacman;
- import java.awt.*;
- import javax.swing.*;
- public class Pacman extends JPanel {
- public static void main(String[] args) {
- Pacman cc = new Pacman();
- JFrame jf = new JFrame();
- jf.add(cc);
- jf.setSize(615, 935); //size 615 x 935
- jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //stop program when closed
- jf.setLocationRelativeTo(null);
- jf.setVisible(true);
- }
- public void paint (Graphics g) {
- //Title
- super.paint(g);
- setBackground(Color.WHITE);
- g.setColor(Color.BLACK);
- g.fillRect(0, 0, 600, 290);
- //P
- g.setColor(Color.WHITE);
- g.fillRect(30, 20, 25, 80);
- g.fillRect(30, 20, 60, 45);
- g.setColor(Color.BLACK);
- g.fillRect(55, 40, 20, 20);
- //A
- g.setColor(Color.WHITE);
- int xA1[] = {100, 140, 190};
- int yA1[] = {100, 25, 100};
- g.fillPolygon(xA1, yA1, 3);
- g.setColor(Color.BLACK);
- int xA2[] = {120, 140, 170};
- int yA2[] = {100, 60, 100};
- g.fillPolygon(xA2, yA2, 3);
- g.setColor(Color.WHITE);
- g.fillRect(120, 75, 50, 10);
- //C
- g.setColor(Color.YELLOW);
- g.fillOval(195, 20, 80, 80);
- g.setColor(Color.BLACK);
- int xC[] = {210, 275, 275};
- int yC[] = {60, 40, 80};
- g.fillPolygon(xC, yC, 3);
- //M
- g.setColor(Color.WHITE);
- int xM[] = {275, 300, 310, 320, 335, 345, 370, 345, 335, 320, 305, 300};
- int yM[] = {100, 20, 20, 50, 20, 20, 90, 100, 50, 90, 60, 100};
- g.fillPolygon(xM, yM, 12);
- //A2
- g.setColor(Color.WHITE);
- int secondxA1[] = {390, 430, 480};
- int secondyA1[] = {100, 20, 100};
- g.fillPolygon(secondxA1, secondyA1, 3);
- g.setColor(Color.BLACK);
- int secondxA2[] = {410, 430, 460};
- int secondyA2[] = {100, 60, 100};
- g.fillPolygon(secondxA2, secondyA2, 3);
- g.setColor(Color.WHITE);
- g.fillRect(410, 75, 50, 10);
- //N
- g.fillRect(500, 20, 75, 80);
- g.setColor(Color.BLACK);
- int xN1[] = {520, 555, 550};
- int yN1[] = {20, 20, 60};
- g.fillPolygon(xN1, yN1, 3);
- int xN2[] = {520, 555, 525};
- int yN2[] = {100, 100, 60};
- g.fillPolygon(xN2, yN2, 3);
- //ghosts
- int xInc = 0; //to move ghosts
- int count = 0; //determining color
- for (int i = 0; i < 4; i ++) {
- //body
- if (count == 0) {
- g.setColor(Color.ORANGE);
- g.fillRoundRect(150 + xInc, 250, 25, 25, 25, 25);
- g.fillRoundRect(151 + xInc, 263, 24, 15, 10, 10);
- } else if (count == 1) {
- g.setColor(Color.BLUE);
- g.fillRoundRect(150 + xInc, 250, 25, 25, 25, 25);
- g.fillRoundRect(151 + xInc, 263, 24, 15, 10, 10);
- } else if (count == 2) {
- g.setColor(Color.GREEN);
- g.fillRoundRect(150 + xInc, 250, 25, 25, 25, 25);
- g.fillRoundRect(151 + xInc, 263, 24, 15, 10, 10);
- } else if (count == 3) {
- g.setColor(Color.RED);
- g.fillRoundRect(150 + xInc, 250, 25, 25, 25, 25);
- g.fillRoundRect(151 + xInc, 263, 24, 15, 10, 10);
- }
- //eye
- g.setColor(Color.WHITE);
- g.fillOval(155 + xInc, 255, 9, 9);
- g.fillOval(165 + xInc, 255, 9, 9);
- //pupil
- g.setColor(Color.BLACK);
- g.fillOval(159 + xInc, 257, 5, 5);
- g.setColor(Color.BLACK);
- g.fillOval(169 + xInc, 257, 5, 5);
- xInc += 35; //changing position of pacman character.
- count++; //changing colour.
- }
- //smallGobler
- g.setColor(Color.YELLOW);
- g.fillOval(450, 250, 25, 25);
- //cutout
- g.setColor(Color.BLACK);
- int smallGobblerX[] = {460, 475, 475};
- int smallGobblerY[] = {262, 255, 270};
- g.fillPolygon(smallGobblerX, smallGobblerY, 3);
- //ball
- g.setColor(Color.WHITE);
- g.fillOval(525, 257, 15, 15);
- //GameBoard
- int xTile = 0;
- int yTile = 0;
- for (int k = 0; k < 5; k++) {
- for (int i = 0; i < 5; i++){
- g.setColor(Color.BLACK);
- g.fillRect(0 + xTile, 300 + yTile, 120, 120);
- xTile += 240;
- }
- for (int i = 0; i < 5; i++){
- g.setColor(Color.BLACK);
- g.fillRect(120 + xTile, 300 + yTile, 120, 120);
- xTile += 240;
- }
- xTile = 0;
- yTile += 240;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement