Public paste
Undefined
By: Guest | Date: Jul 13 2010 10:00 | Format: None | Expires: never | Size: 18.25 KB | Hits: 848

  1. import java.applet.*;
  2.  
  3. public class Game extends Applet implements Runnable {
  4.  
  5.         Image dbI;
  6.         Graphics dbg;
  7.         Random rnd = new Random();
  8.         Button start;
  9.         Button pause;
  10.         Button play;
  11.         Font f = new Font("Mistral", Font.BOLD, 32);
  12.         Font f2 = new Font("Serif", Font.BOLD, 16);
  13.         AudioClip bounce;
  14.         AudioClip score;
  15.  
  16.         //FIELD
  17.         int size_x = 800;                                               //length of x-axis (width of field)
  18.         int size_y = (size_x / 10) * 7;                 //length of y-axis (height of field)
  19.        
  20.         int middle_x = size_x / 2;                              //middle of x-axis
  21.         int middle_y = size_y / 2;                              //middle of y-axis
  22.        
  23.         //PONG-BALL
  24.         int radius = 7;                                                 //radius for ball
  25.         int ball_pos_x = middle_x;                              //position on x-axis
  26.         int ball_pos_y = middle_y;                              //position on y-axis
  27.         double ball_speed_x = 0;                                        //speed of position on x-axis | pos:right       - neg:left
  28.         double ball_speed_y = 0;                                        //speed of position on y-axis | pos:down        - neg:up
  29.  
  30.         double speed = 10;                                                      //speed at the beginning
  31.         double temp_x;                                                          //for saving the x-coordinate of the ball when pausing the game
  32.         double temp_y;                                                          //for saving the y-coordinate of the ball when pausing the game
  33.        
  34.         //GLOBAL PLAYERS
  35.         int player_height = size_y / 8;
  36.         int player_width = (int) (size_x * 0.02);
  37.        
  38.         double ptenth = player_height / 10;                     //a tenth of the player's height
  39.         double ptenth2 = ptenth * 2;
  40.         double ptenth3 = ptenth * 3;
  41.         double ptenth4 = ptenth * 4;
  42.         double ptenth5 = ptenth * 5;
  43.         double ptenth6 = ptenth * 6;
  44.         double ptenth7 = ptenth * 7;
  45.         double ptenth8 = ptenth * 8;
  46.         double ptenth9 = ptenth * 9;
  47.        
  48.        
  49.         //LEFT PLAYER
  50.         int player_l_pos_x = size_x / 100 * 2;
  51.         int player_l_pos_y = middle_y - player_height / 2;
  52.         int player_l_midpos_y;
  53.         int mouse_pos_y;
  54.         int player_l_score = 0;
  55.  
  56.         //RIGHT PLAYER
  57.         int player_r_pos_x = size_x - size_x / 100 * 5;
  58.         int player_r_pos_y = middle_y - player_height / 2;
  59.         int player_r_midpos_y;
  60.         int player_r_score = 0;
  61.         int player_r_speed = 5;
  62.  
  63.         public void init() {
  64.                 this.setLayout(null);
  65.                 start = new Button("Spiel starten");
  66.                 pause = new Button("Pause");
  67.                 play = new Button("Weiter");
  68.                 start.setBounds((int) middle_x - 100, (int) middle_y - 10, 80, 20);
  69.                 pause.setBounds((int) middle_x - 40, (int) size_y, 80, 20);
  70.                 play.setBounds((int) middle_x - 40, (int) size_y, 80, 20);
  71.                 pause.setVisible(false);
  72.                 play.setVisible(false);
  73.                 add(start);
  74.                 add(pause);
  75.                 add(play);
  76.                 setFont(f);
  77.                 start.setFont(f2);
  78.                 play.setFont(f2);
  79.                 pause.setFont(f2);
  80.                 bounce = getAudioClip (getCodeBase(), "drip.au");
  81.                 score = getAudioClip (getCodeBase(), "game_win.au");
  82.                 bounce.play();
  83.                 bounce.stop();
  84.                 score.play();
  85.                 score.stop();
  86.         }
  87.  
  88.         public boolean action(Event e, Object args) {
  89.                 if (e.target == start) {
  90.                         pause.setVisible(true);
  91.                         start.setVisible(false);
  92.                         ball_speed_x = speed * -1;
  93.                         ball_speed_y = 0;
  94.                 }
  95.                 if (e.target == pause) {
  96.                         play.setVisible(true);
  97.                         pause.setVisible(false);
  98.                         temp_x = ball_speed_x;
  99.                         temp_y = ball_speed_y;
  100.                         ball_speed_x = 0;
  101.                         ball_speed_y = 0;
  102.                 }
  103.                 if (e.target == play) {
  104.                         pause.setVisible(true);
  105.                         play.setVisible(false);
  106.                         ball_speed_x = temp_x;
  107.                         ball_speed_y = temp_y;
  108.                 }
  109.                 return false;
  110.         }
  111.  
  112.         public void start() {
  113.                 Thread th = new Thread(this);
  114.                 th.start();
  115.         }
  116.  
  117.         public void stop() {
  118.         }
  119.  
  120.         public void destroy() {
  121.         }
  122.  
  123.         public boolean mouseMove(Event e, int x, int y) {
  124.                 mouse_pos_y = y;
  125.                 return true;
  126.         }
  127.  
  128.         public void run() {
  129.  
  130.                 Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
  131.                 while (true) {
  132.                                                
  133.                         //-----------------------------------------------------------------------------------------
  134.                         //----------------------------------------PONG-BALL----------------------------------------
  135.                         //-----------------------------------------------------------------------------------------
  136.                        
  137.                         //TOP BOUND
  138.                         if (ball_pos_y >= size_y - radius) {
  139.                                 ball_speed_y *= -1;
  140.                                 bounce.play();
  141.                         }
  142.                         //BOTTOM BOUND
  143.                         if (ball_pos_y <= radius) {
  144.                                 ball_speed_y *= -1;
  145.                                 bounce.play();
  146.                         }
  147.                         //MOVEMENT
  148.                         ball_pos_x += ball_speed_x;
  149.                         ball_pos_y += ball_speed_y;
  150.                        
  151.                         //MAX-SPEED
  152.                         if(ball_speed_x >= 30) {
  153.                                 ball_speed_x--;
  154.                         }
  155.  
  156.                         //-------------------------------------------------------------------------------------------
  157.                         //----------------------------------------LEFT PLAYER----------------------------------------
  158.                         //-------------------------------------------------------------------------------------------
  159.  
  160.                         //MOVEMENT (OVER MOUSE)
  161.                         player_l_pos_y = mouse_pos_y - player_height/2;
  162.                         player_l_midpos_y = player_l_pos_y + player_height/2;
  163.                        
  164.                         //TOP BOUND
  165.                         if (player_l_pos_y <= 0) {
  166.                                 player_l_pos_y = 0;
  167.                         }
  168.                         //BOTTOM BOUND
  169.                         if (player_l_pos_y >= size_y - player_height) {
  170.                                 player_l_pos_y = size_y - player_height;
  171.                         }
  172.  
  173.                         //PLAYER SCORES
  174.                         if (ball_pos_x > player_r_pos_x + radius * 2) {
  175.                                 score.play();
  176.                                 player_l_score++;
  177.                                 start.setVisible(true);
  178.                                 pause.setVisible(false);
  179.                                 ball_speed_x = 0;
  180.                                 ball_speed_y = 0;
  181.                                 ball_pos_x = middle_x;
  182.                                 ball_pos_y = middle_y;
  183.                         }
  184.                        
  185.                         //PONG-BOUNCE
  186.                         if (    ball_pos_y + radius >= player_l_pos_y &&
  187.                                         ball_pos_y - radius <= player_l_pos_y + player_height &&
  188.                                         ball_pos_x - radius <= player_width + player_l_pos_x) {
  189.                                
  190.                                 bounce.play();
  191.                                 ball_speed_x *= -1;
  192.                                 ball_speed_x += 1;
  193.  
  194.                                 //UPPERPART
  195.                                 if (ball_pos_y < player_l_midpos_y) {
  196.                                         if (ball_pos_y + radius > player_l_pos_y &&
  197.                                                 ball_pos_y < player_l_pos_y + ptenth) {
  198.                                                 ball_speed_y = ptenth5 / 4 * -1;} else
  199.                                                        
  200.                                         if (ball_pos_y > player_l_pos_y + ptenth &&
  201.                                                 ball_pos_y < player_l_pos_y + ptenth2) {
  202.                                                 ball_speed_y = ptenth4 / 4 * -1;} else
  203.                                                        
  204.                                         if (ball_pos_y > player_l_pos_y + ptenth2 &&
  205.                                                 ball_pos_y < player_l_pos_y + ptenth3) {
  206.                                                 ball_speed_y = ptenth3 / 4 * -1;} else
  207.                                                        
  208.                                         if (ball_pos_y > player_l_pos_y + ptenth3 &&
  209.                                                 ball_pos_y < player_l_pos_y + ptenth4) {
  210.                                                 ball_speed_y = ptenth2 / 4 * -1;} else
  211.                                                        
  212.                                         if (ball_pos_y > player_l_pos_y + ptenth4 &&
  213.                                                 ball_pos_y < player_l_pos_y + ptenth5) {
  214.                                                 ball_speed_y = ptenth / 4 *-1;} else {
  215.                                                         if (ball_speed_y > 0) {
  216.                                                                 ball_speed_y++;
  217.                                                         } else if (ball_speed_y < 0) {
  218.                                                                 ball_speed_y--;
  219.                                                         } else if(ball_speed_y == 0) {
  220.                                                                 ball_speed_y = rnd.nextInt((int) speed);
  221.                                                         }
  222.                                                 }
  223.                                 }
  224.                                 //UNDERPART
  225.                                 if (ball_pos_y > player_l_midpos_y) {
  226.                                         if (ball_pos_y > player_l_pos_y + ptenth5 &&
  227.                                                 ball_pos_y < player_l_pos_y + ptenth6) {
  228.                                                 ball_speed_y = ptenth / 4;} else
  229.                                                        
  230.                                         if (ball_pos_y > player_l_pos_y + ptenth6 &&
  231.                                                 ball_pos_y < player_l_pos_y + ptenth7) {
  232.                                                 ball_speed_y = ptenth2 / 4;} else
  233.                                                        
  234.                                         if (ball_pos_y > player_l_pos_y + ptenth7 &&
  235.                                                 ball_pos_y < player_l_pos_y + ptenth8) {
  236.                                                 ball_speed_y = ptenth3 / 4;} else
  237.                                                        
  238.                                         if (ball_pos_y > player_l_pos_y + ptenth8 &&
  239.                                                 ball_pos_y < player_l_pos_y + ptenth9) {
  240.                                                 ball_speed_y = ptenth4 / 4;} else
  241.                                                        
  242.                                         if (ball_pos_y - radius> player_l_pos_y + ptenth9 &&
  243.                                                 ball_pos_y < player_l_pos_y + player_height) {
  244.                                                 ball_speed_y = ptenth5 / 4;} else {
  245.                                                         if (ball_speed_y > 0) {
  246.                                                                 ball_speed_y++;
  247.                                                         } else if (ball_speed_y < 0) {
  248.                                                                 ball_speed_y--;
  249.                                                         } else if(ball_speed_y == 0) {
  250.                                                                 ball_speed_y = rnd.nextInt((int) speed);
  251.                                                         }
  252.                                                 }
  253.                                 }
  254.                         }
  255.                        
  256.                         //--------------------------------------------------------------------------------------------
  257.                         //----------------------------------------RIGHT PLAYER----------------------------------------
  258.                         //--------------------------------------------------------------------------------------------
  259.  
  260.                         player_r_midpos_y = player_r_pos_y + player_height/2;
  261.                         player_r_speed = player_r_midpos_y / 50;
  262.                        
  263.                         //TOP BOUND
  264.                         if (player_r_pos_y <= 0) {
  265.                                 player_r_speed = 0;
  266.                                 player_r_pos_y = 0;
  267.                         }
  268.                        
  269.                         //BOTTOM BOUND
  270.                         if (player_r_pos_y >= size_y - player_height) {
  271.                                 player_r_speed = 0;
  272.                                 player_r_pos_y = size_y - player_height;
  273.                         }
  274.                        
  275.                         //PLAYER SCORES
  276.                         if (ball_pos_x < player_l_pos_x - radius * 2) {
  277.                                 score.play();
  278.                                 player_r_score++;
  279.                                 start.setVisible(true);
  280.                                 pause.setVisible(false);
  281.                                 ball_speed_x = 0;
  282.                                 ball_speed_y = 0;
  283.                                 ball_pos_x = middle_x;
  284.                                 ball_pos_y = middle_y;
  285.                         }
  286.                        
  287.                         //PONG-BOUNCE
  288.                         if (    ball_pos_y + radius >= player_r_pos_y &&
  289.                                         ball_pos_y - radius <= player_r_pos_y + player_height &&
  290.                                         ball_pos_x + radius >= player_r_pos_x) {
  291.  
  292.                                 bounce.play();
  293.                                 ball_speed_x *= -1;
  294.                                 ball_speed_x -= 1;
  295.  
  296.                                 //UPPERPART
  297.                                 if (ball_pos_y < player_r_midpos_y) {
  298.                                         if (ball_pos_y + radius> player_r_pos_y &&
  299.                                                 ball_pos_y < player_r_pos_y + ptenth) {
  300.                                                 ball_speed_y = ptenth5 / 4 * -1;} else
  301.                                                        
  302.                                         if (ball_pos_y > player_r_pos_y + ptenth &&
  303.                                                 ball_pos_y < player_r_pos_y + ptenth2) {
  304.                                                 ball_speed_y = ptenth4 / 4 * -1;} else
  305.                                                        
  306.                                         if (ball_pos_y > player_r_pos_y + ptenth2 &&
  307.                                                 ball_pos_y < player_r_pos_y + ptenth3) {
  308.                                                 ball_speed_y = ptenth3 / 4 * -1;} else
  309.                                                        
  310.                                         if (ball_pos_y > player_r_pos_y + ptenth3 &&
  311.                                                 ball_pos_y < player_r_pos_y + ptenth4) {
  312.                                                 ball_speed_y = ptenth2 / 4 * -1;} else
  313.                                                        
  314.                                         if (ball_pos_y > player_r_pos_y + ptenth4 &&
  315.                                                 ball_pos_y < player_r_pos_y + ptenth5) {
  316.                                                 ball_speed_y = ptenth / 4 *-1;} else {
  317.                                                         if (ball_speed_y > 0) {
  318.                                                                 ball_speed_y++;
  319.                                                         } else if (ball_speed_y < 0) {
  320.                                                                 ball_speed_y--;
  321.                                                         } else if(ball_speed_y == 0) {
  322.                                                                 ball_speed_y = rnd.nextInt((int) speed);
  323.                                                         }
  324.                                                 }
  325.                                 }
  326.                                 //UNDERPART
  327.                                 if (ball_pos_y  > player_l_midpos_y) {
  328.                                         if (ball_pos_y > player_r_pos_y + ptenth5 &&
  329.                                                 ball_pos_y < player_r_pos_y + ptenth6) {
  330.                                                 ball_speed_y = ptenth / 4;} else
  331.                                                        
  332.                                         if (ball_pos_y > player_r_pos_y + ptenth6 &&
  333.                                                 ball_pos_y < player_r_pos_y + ptenth7) {
  334.                                                 ball_speed_y = ptenth2 / 4;} else
  335.                                                        
  336.                                         if (ball_pos_y > player_r_pos_y + ptenth7 &&
  337.                                                 ball_pos_y < player_r_pos_y + ptenth8) {
  338.                                                 ball_speed_y = ptenth3 / 4;} else
  339.                                                        
  340.                                         if (ball_pos_y > player_r_pos_y + ptenth8 &&
  341.                                                 ball_pos_y < player_r_pos_y + ptenth9) {
  342.                                                 ball_speed_y = ptenth4 / 4;} else
  343.                                                        
  344.                                         if (ball_pos_y - radius > player_r_pos_y + ptenth9 &&
  345.                                                 ball_pos_y < player_r_pos_y + player_height) {
  346.                                                 ball_speed_y = ptenth5 / 4;} else {
  347.                                                         if (ball_speed_y > 0) {
  348.                                                                 ball_speed_y++;
  349.                                                         } else if (ball_speed_y < 0) {
  350.                                                                 ball_speed_y--;
  351.                                                         } else if(ball_speed_y == 0) {
  352.                                                                 ball_speed_y = rnd.nextInt((int) speed);
  353.                                                         }
  354.                                                 }
  355.                                 }
  356.                         }
  357.                        
  358.                         // ----------------------------------------ARTIFICIAL INTELLIGENCE----------------------------------------
  359.  
  360.                        
  361.                         //                      ||
  362.                         //      O<<             ||      PONG FLY AWAY FROM PLAYER
  363.                         //                      ||
  364.                         if (ball_speed_x < 0) {
  365.                                 if (player_r_midpos_y < middle_y + 10 && player_r_midpos_y > middle_y - 10) {
  366.                                         player_r_pos_y = middle_y - player_height/2;
  367.                                         player_r_speed = 0;
  368.                                 }
  369.  
  370.                                 if (player_r_midpos_y < middle_y) {
  371.                                         player_r_pos_y += player_r_speed;
  372.                                 } else if (player_r_midpos_y > middle_y) {
  373.                                         player_r_pos_y -= player_r_speed;
  374.                                 }
  375.                         } else
  376.                                
  377.                         //                      ||
  378.                         //      >>O             ||      PONG FLY TOWARDS PLAYER
  379.                         //                      ||
  380.                                 if (ball_speed_x > 0) {
  381.                                         if (player_r_speed >= 1) {
  382.                                                 if(player_r_pos_x - ball_pos_x <= 10) {
  383.                                                         player_r_speed -= 1;
  384.                                                         }
  385.                                                 }
  386.                                        
  387.                                         //PLAYER'S SPEED ADJUSTMENT
  388.                                         if (    player_r_pos_y - ball_pos_y < size_y * 0.05 && player_r_pos_y - ball_pos_y > -size_y * 0.05) {
  389.                                                 player_r_speed = ball_pos_x / 80;
  390.                                                 } else
  391.                                         if (    player_r_pos_y - ball_pos_y < size_y * 0.1 && player_r_pos_y - ball_pos_y > size_y * 0.05 ||
  392.                                                         player_r_pos_y - ball_pos_y > -size_y * 0.1 && player_r_pos_y - ball_pos_y < -size_y * 0.05) {
  393.                                                 player_r_speed = ball_pos_x / 70;
  394.                                                 } else
  395.                                         if (    player_r_pos_y - ball_pos_y < size_y * 0.2 && player_r_pos_y - ball_pos_y > size_y * 0.1 ||
  396.                                                         player_r_pos_y - ball_pos_y > -size_y * 0.2 && player_r_pos_y - ball_pos_y < -size_y * 0.1) {
  397.                                                 player_r_speed = ball_pos_x / 60;
  398.                                                 } else
  399.                                         if (    player_r_pos_y - ball_pos_y < size_y * 0.3 && player_r_pos_y - ball_pos_y > size_y * 0.2 ||    
  400.                                                         player_r_pos_y - ball_pos_y > -size_y * 0.3 && player_r_pos_y - ball_pos_y < -size_y * 0.2) {
  401.                                                 player_r_speed = ball_pos_x / 50;
  402.                                                 } else
  403.                                         if (    player_r_pos_y - ball_pos_y < size_y * 0.4 && player_r_pos_y - ball_pos_y > size_y * 0.3 ||
  404.                                                         player_r_pos_y - ball_pos_y > -size_y * 0.4 && player_r_pos_y - ball_pos_y < -size_y * 0.3) {
  405.                                                 player_r_speed = ball_pos_x / 40;
  406.                                                 } else
  407.                                         if (    player_r_pos_y - ball_pos_y < size_y * 0.5 && player_r_pos_y - ball_pos_y > size_y * 0.4 ||
  408.                                                         player_r_pos_y - ball_pos_y > -size_y * 0.5 && player_r_pos_y - ball_pos_y < -size_y * 0.4) {
  409.                                                 player_r_speed = ball_pos_x / 30;
  410.                                                 } else
  411.                                         if (    player_r_pos_y - ball_pos_y < size_y * 0.6 && player_r_pos_y - ball_pos_y > size_y * 0.5 ||
  412.                                                         player_r_pos_y - ball_pos_y > -size_y * 0.6 && player_r_pos_y - ball_pos_y < -size_y * 0.5) {
  413.                                                 player_r_speed = ball_pos_x / 25;
  414.                                                 } else
  415.                                         if (    player_r_pos_y - ball_pos_y < size_y * 0.7 && player_r_pos_y - ball_pos_y > size_y * 0.6 ||
  416.                                                         player_r_pos_y - ball_pos_y > -size_y * 0.7 && player_r_pos_y - ball_pos_y < -size_y * 0.6) {
  417.                                                 player_r_speed = ball_pos_x / 20;
  418.                                                 } else
  419.                                         if (    player_r_pos_y - ball_pos_y < size_y * 0.8 && player_r_pos_y - ball_pos_y > size_y * 0.7 ||
  420.                                                         player_r_pos_y - ball_pos_y > -size_y * 0.8 && player_r_pos_y - ball_pos_y < -size_y * 0.7) {
  421.                                                 player_r_speed = ball_pos_x / 15;
  422.                                                 } else
  423.                                         if (    player_r_pos_y - ball_pos_y < size_y * 0.9 && player_r_pos_y - ball_pos_y > size_y * 0.8 ||
  424.                                                         player_r_pos_y - ball_pos_y > -size_y * 0.9 && player_r_pos_y - ball_pos_y < -size_y * 0.8) {
  425.                                                 player_r_speed = ball_pos_x / 10;
  426.                                                 } else
  427.                                         if (    player_r_pos_y - ball_pos_y < size_y && player_r_pos_y - ball_pos_y > size_y * 0.9 ||
  428.                                                         player_r_pos_y - ball_pos_y > -size_y && player_r_pos_y - ball_pos_y < -size_y * 0.9) {
  429.                                                 player_r_speed = ball_pos_x / 5;
  430.                                                 }
  431.                                        
  432.                                         //PLAYER'S ACUITY
  433.                                        
  434.                                         //1ST FIFTH OF FIELD (LEFT BOUND)
  435.                                         if (ball_pos_x < size_x * 0.2) {
  436.                                                 if (player_r_pos_y != ball_pos_y - rnd.nextInt((int) (size_x * 0.8) / 2) + size_x * 0.8 / 4) {
  437.                                                         if (ball_pos_y - rnd.nextInt((int) (size_x * 0.8) / 2) + (size_x * 0.8) / 4 < player_r_pos_y + player_height/2) {player_r_pos_y -= player_r_speed;}
  438.                                                         else if (ball_pos_y - rnd.nextInt((int) (size_x * 0.8) / 2) + (size_x * 0.8) / 4 > player_r_pos_y + player_height/2) {player_r_pos_y += player_r_speed;}
  439.                                                 }
  440.                                         }
  441.                                         //2ND FIFTH OF FIELD
  442.                                         else if (ball_pos_x > size_x * 0.2 && ball_pos_x < size_x * 0.4) {
  443.                                                 if (player_r_pos_y != ball_pos_y - rnd.nextInt((int) (size_x * 0.6) / 2) + size_x * 0.6 / 4) {
  444.                                                         if (ball_pos_y - rnd.nextInt((int) (size_x * 0.6) / 2) + (size_x * 0.6) / 4 < player_r_pos_y + player_height/2) {player_r_pos_y -= player_r_speed;}
  445.                                                         else if (ball_pos_y - rnd.nextInt((int) (size_x * 0.6) / 2) + (size_x * 0.6) / 4 > player_r_pos_y + player_height/2) {player_r_pos_y += player_r_speed;}
  446.                                                 }
  447.                                         }
  448.                                         //3RD FIFTH OF FIELD
  449.                                         else if (ball_pos_x > size_x * 0.4 && ball_pos_x < size_x * 0.6) {
  450.                                                 if (player_r_pos_y != ball_pos_y - rnd.nextInt((int) (size_x * 0.4) / 2) + size_x * 0.4 / 4) {
  451.                                                         if (ball_pos_y - rnd.nextInt((int) (size_x * 0.4) / 2) + (size_x * 0.4) / 4 < player_r_pos_y + player_height/2) {player_r_pos_y -= player_r_speed;}
  452.                                                         else if (ball_pos_y - rnd.nextInt((int) (size_x * 0.4) / 2) + (size_x * 0.4) / 4 > player_r_pos_y + player_height/2) {player_r_pos_y += player_r_speed;}
  453.                                                 }
  454.                                         }
  455.                                         //4TH FIFTH OF FIELD
  456.                                         else if (ball_pos_x > size_x * 0.6 && ball_pos_x < size_x * 0.8) {
  457.                                                 if (player_r_pos_y != ball_pos_y - rnd.nextInt((int) (size_x * 0.2) / 2) + size_x * 0.4 / 4) {
  458.                                                         if (ball_pos_y - rnd.nextInt((int) (size_x * 0.2) / 2) + (size_x * 0.2) / 4 < player_r_pos_y + player_height/2) {player_r_pos_y -= player_r_speed;}
  459.                                                         else if (ball_pos_y - rnd.nextInt((int) (size_x * 0.2) / 2) + (size_x * 0.2) / 4 > player_r_pos_y + player_height/2) {player_r_pos_y += player_r_speed;}
  460.                                                 }
  461.                                         }
  462.                                         //5TH FIFTH OF FIELD (RIGHT BOUND)
  463.                                         else if (ball_pos_x > size_x * 0.8 && ball_pos_x < size_x) {
  464.                                                 if (player_r_pos_y != ball_pos_y) {
  465.                                                         if (ball_pos_y < player_r_pos_y + player_height/2) {player_r_pos_y -= player_r_speed;}
  466.                                                         else if (ball_pos_y > player_r_pos_y + player_height/2) {player_r_pos_y += player_r_speed;}
  467.                                                 }
  468.                                         }
  469.                                 }
  470.                         // ----------------------------------------AI END----------------------------------------
  471.                        
  472.                         repaint();
  473.                         try {Thread.sleep(20);} catch (InterruptedException ex) {}
  474.                         Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
  475.                 }
  476.         }
  477.  
  478.         public void paint(Graphics g) {
  479.                 this.setBackground(Color.black);       
  480.                 ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);                          //FONT & SHAPE SMOOTHING
  481.                 g.setColor(Color.white);                                                                                                                                                                                        //OBJECT & FONT COLOR
  482.                 g.fillOval((int) ball_pos_x - (int) radius, (int) ball_pos_y - (int) radius, 2 * (int) radius, 2 * (int) radius);       //PONG-BALL
  483.                 g.fillRect((int) player_l_pos_x, (int) player_l_pos_y, (int) player_width, (int) player_height);                                        //LEFT PLAYER
  484.                 g.fillRect((int) player_r_pos_x, (int) player_r_pos_y, (int) player_width, (int) player_height);                                        //RIGHT PLAYER
  485.                 g.drawString((int) player_l_score + "", (int) middle_x / 2, 30);                                                                                                        //LEFT PLAYER'S SCOREBOARD
  486.                 g.drawString(player_r_score + " ", (int) middle_x / 2 * 3, 30);                                                                                                         //RIGHT PLAYER'S SCOREBOARD
  487.                 g.fillRect(0, (int) size_y, (int) size_x, 2);                                                                                                                                           //BOTTOM-LINE
  488.                 g.fillRect((int) middle_x, 0, 2, (int) size_y);                                                                                                                                         //CENTERLINE
  489.                
  490.                 this.setSize((int) size_x, (int) size_y + 60);                                                                                                                                          // APPLET-SIZE
  491.         }
  492.        
  493.         //DOUBLE-BUFFERING
  494.         public void update(Graphics g) {
  495.                 if (dbI == null) {
  496.                         dbI = createImage(this.getSize().width, this.getSize().height);
  497.                         dbg = dbI.getGraphics();
  498.                 }
  499.                
  500.                 dbg.setColor(getBackground());
  501.                 dbg.fillRect(0, 0, this.getSize().width, this.getSize().height);
  502.                
  503.                 dbg.setColor(getForeground());
  504.                 paint(dbg);
  505.                
  506.                 g.drawImage(dbI, 0, 0, this);
  507.         }
  508. }