Advertisement
Guest User

Untitled

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