Advertisement
Ramdan51-062

Paddle

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