Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. int startup = 0;
  2. int x = 400;
  3. int y = 500;
  4. int x2 = (int) (Math.random() * (600 + 1));
  5. int y2 = (int) (Math.random() * (600 + 1));
  6. int xVelocity = 1;
  7. int yVelocity = 1;
  8. int x2Velocity = 1;
  9. int y2Velocity = 1;
  10. int curry = 700;
  11. int currx = 600;
  12. int counter = 2;
  13.  
  14. @Override
  15. public void init() {
  16. setSize(1440, 900);
  17. setBackground(Color.black);
  18. setFont(new Font("Helvetica", Font.BOLD, 36));
  19.  
  20. }
  21.  
  22. @Override
  23. public boolean keyDown(Event evt, int key) {
  24.  
  25. startup = startup + 1;
  26. repaint();
  27.  
  28. if (key == Event.RIGHT) {
  29. currx += 10;
  30. }
  31. if (key == Event.LEFT) {
  32. currx -= 10;
  33. }
  34.  
  35. if (currx == 1400) {
  36. currx = 10;
  37. }
  38. if (currx == 20) {
  39. currx = 1399;
  40. }
  41.  
  42. repaint();
  43. return false;
  44.  
  45. }
  46.  
  47. public void run(Graphics g) {
  48. startup = 0;
  49. while (counter > 0) {
  50.  
  51. try {
  52. Thread.sleep(30);
  53. } catch (InterruptedException e) {
  54. }
  55.  
  56. x += xVelocity;
  57. y += yVelocity;
  58.  
  59. g.setColor(Color.blue);
  60. g.fillRect(currx, curry, 300, 25);
  61.  
  62. g.setColor(Color.red);
  63. g.fillOval(x, y, 30, 30);
  64.  
  65. for (int j = 0; j < 20000000; j++);
  66. g.setColor(Color.black);
  67. g.fillOval(x, y, 30, 30);
  68.  
  69. //Bounce the ball off the wall or paddle
  70. if (x >= 1400 || x <= 0) {
  71. xVelocity = -xVelocity;
  72. }
  73. if (y >= 800 || y <= 0) {
  74. yVelocity = -yVelocity;
  75. }
  76. if (((y == 675)) && ((currx <= x) && (currx + 300) >= x)) {
  77. yVelocity = -yVelocity;
  78. y = y - 10;
  79. repaint();
  80.  
  81. }
  82. }
  83. }
  84.  
  85. public void paint(Graphics g) {
  86. if (startup == 0) {
  87. g.setColor(Color.white);
  88. g.drawString("Welcome To PONG", 0, 100);
  89. g.drawString("Created by Caden Anton", 0, 200);
  90. g.drawString("copyright May 3rd, 2019 ©", 0, 300);
  91. g.drawString("Press any key to continue", 0, 400);
  92. }
  93.  
  94. if (startup == 1) {
  95. g.setColor(Color.white);
  96. g.drawString("RULES:", 0, 100);
  97. g.drawString("Press the arrwow keys to move the paddle", 0, 200);
  98. g.drawString("Your objective is to keep the ball from touching the ground", 0, 300);
  99. g.drawString("Once the ball hits the ground you lose the game", 0, 400);
  100. }
  101. if (startup >= 2) {
  102. //Input Run thread start here.
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement