Advertisement
taufiq123

Untitled

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