Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int startup = 0;
- int x = 400;
- int y = 500;
- int x2 = (int) (Math.random() * (600 + 1));
- int y2 = (int) (Math.random() * (600 + 1));
- int xVelocity = 1;
- int yVelocity = 1;
- int x2Velocity = 1;
- int y2Velocity = 1;
- int curry = 700;
- int currx = 600;
- int counter = 2;
- @Override
- public void init() {
- setSize(1440, 900);
- setBackground(Color.black);
- setFont(new Font("Helvetica", Font.BOLD, 36));
- }
- @Override
- public boolean keyDown(Event evt, int key) {
- startup = startup + 1;
- repaint();
- if (key == Event.RIGHT) {
- currx += 10;
- }
- if (key == Event.LEFT) {
- currx -= 10;
- }
- if (currx == 1400) {
- currx = 10;
- }
- if (currx == 20) {
- currx = 1399;
- }
- repaint();
- return false;
- }
- public void run(Graphics g) {
- startup = 0;
- while (counter > 0) {
- try {
- Thread.sleep(30);
- } catch (InterruptedException e) {
- }
- x += xVelocity;
- y += yVelocity;
- g.setColor(Color.blue);
- g.fillRect(currx, curry, 300, 25);
- g.setColor(Color.red);
- g.fillOval(x, y, 30, 30);
- for (int j = 0; j < 20000000; j++);
- g.setColor(Color.black);
- g.fillOval(x, y, 30, 30);
- //Bounce the ball off the wall or paddle
- if (x >= 1400 || x <= 0) {
- xVelocity = -xVelocity;
- }
- if (y >= 800 || y <= 0) {
- yVelocity = -yVelocity;
- }
- if (((y == 675)) && ((currx <= x) && (currx + 300) >= x)) {
- yVelocity = -yVelocity;
- y = y - 10;
- repaint();
- }
- }
- }
- public void paint(Graphics g) {
- if (startup == 0) {
- g.setColor(Color.white);
- g.drawString("Welcome To PONG", 0, 100);
- g.drawString("Created by Caden Anton", 0, 200);
- g.drawString("copyright May 3rd, 2019 ©", 0, 300);
- g.drawString("Press any key to continue", 0, 400);
- }
- if (startup == 1) {
- g.setColor(Color.white);
- g.drawString("RULES:", 0, 100);
- g.drawString("Press the arrwow keys to move the paddle", 0, 200);
- g.drawString("Your objective is to keep the ball from touching the ground", 0, 300);
- g.drawString("Once the ball hits the ground you lose the game", 0, 400);
- }
- if (startup >= 2) {
- //Input Run thread start here.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement