Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Graphics;
- import java.awt.Color;
- public class Paddle
- {
- public int x, y, height = 250, width = 50; //Location and shape
- public int score; //Keep score
- public int paddleNumber; //Player #1 || #2
- public Paddle(Pong pong, int paddleNumber)
- {
- this.paddleNumber = paddleNumber;
- if(paddleNumber == 1){
- this.x = 0;
- }
- if(paddleNumber == 1){
- this.x = pong.width - width;
- }
- this.y = pong.height/2 - this.height/2;
- }
- public void render(Graphics g)
- {
- g.setColor(Color.BLACK);
- g.fillRect(x, y, width, height);
- }
- public void move(boolean up)
- {
- int speed = 15;
- if (up)
- {
- if (y - speed > 0)
- {
- y -= speed;
- }
- else
- {
- y = 0;
- }
- }
- else
- {
- if (y + height + speed < Pong.pong.height)
- {
- y += speed;
- }
- else
- {
- y = Pong.pong.height - height;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement