dewimardanic

Untitled

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