Advertisement
Guest User

Computer.java

a guest
May 18th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1. package game.pong;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics;
  5.  
  6. public class Computer {
  7.    
  8.     private Screen field;
  9.    
  10.     private int y = Game.HEIGHT / 2;
  11.        
  12.     private int yVelocity = 0;
  13.    
  14.     public int score = 0;
  15.    
  16.     private int width = 15;
  17.     private int height = 60;
  18.        
  19.     public Computer(Screen screen){
  20.         this.field = screen;
  21.     }
  22.        
  23.     public void update(){
  24.         if(field.getBall().getY() < this.y){
  25.             yVelocity = -3;
  26.         }else if(field.getBall().getY() > this.y){
  27.             yVelocity = 3;
  28.         }
  29.        
  30.         y = y + yVelocity;
  31.     }
  32.        
  33.     public void paint(Graphics g){
  34.         g.setColor(Color.RED);
  35.         g.fillRect(525, y, width, height);
  36.     }
  37.        
  38.     public int getX() {
  39.         return 15;
  40.     }
  41.  
  42.     public int getY() {
  43.         return y;
  44.     }
  45.        
  46.     public int getWidth(){     
  47.         return width;
  48.     }
  49.        
  50.     public int getHeight(){
  51.         return height;
  52.     }
  53.    
  54.     public int getScore(){
  55.         return score;
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement