Advertisement
nawamkihafahd

Untitled

Nov 30th, 2017
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. package pong;
  2.  
  3.  
  4. /**
  5. * Write a description of class Paddle here.
  6. *
  7. * @author (your name)
  8. * @version (a version number or a date)
  9. */
  10. import java.awt.Color;
  11. import java.awt.Graphics;
  12.  
  13. public class Paddle
  14. {
  15.  
  16. public int paddleNumber;
  17.  
  18. public int x, y, width = 50, height = 250;
  19.  
  20. public int score;
  21.  
  22. public Paddle(Pong pong, int paddleNumber)
  23. {
  24. this.paddleNumber = paddleNumber;
  25.  
  26. if (paddleNumber == 1)
  27. {
  28. this.x = 0;
  29. }
  30.  
  31. if (paddleNumber == 2)
  32. {
  33. this.x = pong.width - width;
  34. }
  35.  
  36. this.y = pong.height / 2 - this.height / 2;
  37. }
  38.  
  39. public void render(Graphics g)
  40. {
  41. g.setColor(Color.WHITE);
  42. g.fillRect(x, y, width, height);
  43. }
  44.  
  45. public void move(boolean up)
  46. {
  47. int speed = 15;
  48.  
  49. if (up)
  50. {
  51. if (y - speed > 0)
  52. {
  53. y -= speed;
  54. }
  55. else
  56. {
  57. y = 0;
  58. }
  59. }
  60. else
  61. {
  62. if (y + height + speed < Pong.pong.height)
  63. {
  64. y += speed;
  65. }
  66. else
  67. {
  68. y = Pong.pong.height - height;
  69. }
  70. }
  71. }
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement