Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package game.pong;
- import java.awt.Color;
- import java.awt.Graphics;
- public class Computer {
- private Screen field;
- private int y = Game.HEIGHT / 2;
- private int yVelocity = 0;
- public int score = 0;
- private int width = 15;
- private int height = 60;
- public Computer(Screen screen){
- this.field = screen;
- }
- public void update(){
- if(field.getBall().getY() < this.y){
- yVelocity = -3;
- }else if(field.getBall().getY() > this.y){
- yVelocity = 3;
- }
- y = y + yVelocity;
- }
- public void paint(Graphics g){
- g.setColor(Color.RED);
- g.fillRect(525, y, width, height);
- }
- public int getX() {
- return 15;
- }
- public int getY() {
- return y;
- }
- public int getWidth(){
- return width;
- }
- public int getHeight(){
- return height;
- }
- public int getScore(){
- return score;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement