Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.39 KB | None | 0 0
  1. /*
  2.  
  3. Program: .java Last Date of this Revision: April , 2019
  4.  
  5. Purpose:
  6. Author: Kyle James
  7. School: LBHS
  8. Course: Computer Programming 30
  9.  
  10.  
  11. */
  12.  
  13. package pacman;
  14.  
  15. import java.awt.*;
  16. import javax.swing.*;
  17.  
  18. public class Pacman extends JPanel {
  19.  
  20. public static void main(String[] args) {
  21. Pacman cc = new Pacman();
  22. JFrame jf = new JFrame();
  23. jf.add(cc);
  24. jf.setSize(615, 935); //size 615 x 935
  25. jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //stop program when closed
  26. jf.setLocationRelativeTo(null);
  27. jf.setVisible(true);
  28. }
  29.  
  30. public void paint (Graphics g) {
  31. //Title
  32. super.paint(g);
  33. setBackground(Color.WHITE);
  34. g.setColor(Color.BLACK);
  35. g.fillRect(0, 0, 600, 290);
  36. //P
  37. g.setColor(Color.WHITE);
  38. g.fillRect(30, 20, 25, 80);
  39. g.fillRect(30, 20, 60, 45);
  40. g.setColor(Color.BLACK);
  41. g.fillRect(55, 40, 20, 20);
  42. //A
  43. g.setColor(Color.WHITE);
  44. int xA1[] = {100, 140, 190};
  45. int yA1[] = {100, 25, 100};
  46. g.fillPolygon(xA1, yA1, 3);
  47. g.setColor(Color.BLACK);
  48. int xA2[] = {120, 140, 170};
  49. int yA2[] = {100, 60, 100};
  50. g.fillPolygon(xA2, yA2, 3);
  51. g.setColor(Color.WHITE);
  52. g.fillRect(120, 75, 50, 10);
  53. //C
  54. g.setColor(Color.YELLOW);
  55. g.fillOval(195, 20, 80, 80);
  56. g.setColor(Color.BLACK);
  57. int xC[] = {210, 275, 275};
  58. int yC[] = {60, 40, 80};
  59. g.fillPolygon(xC, yC, 3);
  60. //M
  61. g.setColor(Color.WHITE);
  62. int xM[] = {275, 300, 310, 320, 335, 345, 370, 345, 335, 320, 305, 300};
  63. int yM[] = {100, 20, 20, 50, 20, 20, 90, 100, 50, 90, 60, 100};
  64. g.fillPolygon(xM, yM, 12);
  65. //A2
  66. g.setColor(Color.WHITE);
  67. int secondxA1[] = {390, 430, 480};
  68. int secondyA1[] = {100, 20, 100};
  69. g.fillPolygon(secondxA1, secondyA1, 3);
  70. g.setColor(Color.BLACK);
  71. int secondxA2[] = {410, 430, 460};
  72. int secondyA2[] = {100, 60, 100};
  73. g.fillPolygon(secondxA2, secondyA2, 3);
  74. g.setColor(Color.WHITE);
  75. g.fillRect(410, 75, 50, 10);
  76. //N
  77. g.fillRect(500, 20, 75, 80);
  78. g.setColor(Color.BLACK);
  79. int xN1[] = {520, 555, 550};
  80. int yN1[] = {20, 20, 60};
  81. g.fillPolygon(xN1, yN1, 3);
  82. int xN2[] = {520, 555, 525};
  83. int yN2[] = {100, 100, 60};
  84. g.fillPolygon(xN2, yN2, 3);
  85.  
  86. //ghosts
  87. int xInc = 0; //to move ghosts
  88. int count = 0; //determining color
  89. for (int i = 0; i < 4; i ++) {
  90. //body
  91. if (count == 0) {
  92. g.setColor(Color.ORANGE);
  93. g.fillRoundRect(150 + xInc, 250, 25, 25, 25, 25);
  94. g.fillRoundRect(151 + xInc, 263, 24, 15, 10, 10);
  95. } else if (count == 1) {
  96. g.setColor(Color.BLUE);
  97. g.fillRoundRect(150 + xInc, 250, 25, 25, 25, 25);
  98. g.fillRoundRect(151 + xInc, 263, 24, 15, 10, 10);
  99. } else if (count == 2) {
  100. g.setColor(Color.GREEN);
  101. g.fillRoundRect(150 + xInc, 250, 25, 25, 25, 25);
  102. g.fillRoundRect(151 + xInc, 263, 24, 15, 10, 10);
  103. } else if (count == 3) {
  104. g.setColor(Color.RED);
  105. g.fillRoundRect(150 + xInc, 250, 25, 25, 25, 25);
  106. g.fillRoundRect(151 + xInc, 263, 24, 15, 10, 10);
  107. }
  108. //eye
  109. g.setColor(Color.WHITE);
  110. g.fillOval(155 + xInc, 255, 9, 9);
  111. g.fillOval(165 + xInc, 255, 9, 9);
  112. //pupil
  113. g.setColor(Color.BLACK);
  114. g.fillOval(159 + xInc, 257, 5, 5);
  115. g.setColor(Color.BLACK);
  116. g.fillOval(169 + xInc, 257, 5, 5);
  117. xInc += 35; //changing position of pacman character.
  118. count++; //changing colour.
  119. }
  120. //smallGobler
  121. g.setColor(Color.YELLOW);
  122. g.fillOval(450, 250, 25, 25);
  123. //cutout
  124. g.setColor(Color.BLACK);
  125. int smallGobblerX[] = {460, 475, 475};
  126. int smallGobblerY[] = {262, 255, 270};
  127. g.fillPolygon(smallGobblerX, smallGobblerY, 3);
  128. //ball
  129. g.setColor(Color.WHITE);
  130. g.fillOval(525, 257, 15, 15);
  131.  
  132. //GameBoard
  133. int xTile = 0;
  134. int yTile = 0;
  135. for (int k = 0; k < 5; k++) {
  136.  
  137. for (int i = 0; i < 5; i++){
  138. g.setColor(Color.BLACK);
  139. g.fillRect(0 + xTile, 300 + yTile, 120, 120);
  140. xTile += 240;
  141. }
  142.  
  143. for (int i = 0; i < 5; i++){
  144. g.setColor(Color.BLACK);
  145. g.fillRect(120 + xTile, 300 + yTile, 120, 120);
  146. xTile += 240;
  147. }
  148.  
  149.  
  150. xTile = 0;
  151. yTile += 240;
  152. }
  153.  
  154.  
  155.  
  156. }
  157.  
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement