Advertisement
Guest User

Second Class

a guest
Jan 21st, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. import java.awt.*;
  2.  
  3. public class GameObject {
  4.  
  5.    
  6.     private int x,y;
  7.     private Color c;
  8.     private int a = 40;
  9.    
  10.    
  11.     public GameObject(){
  12.         this.x = (int)(Math.random()* 600);
  13.         this.y = (int)(Math.random()* 600);
  14.         this.c = new Color((int)(Math.random()*255),(int)(Math.random()*255),(int)(Math.random()*255));
  15.        
  16.     }
  17.    
  18.    
  19.     public void move(){
  20.        
  21.        
  22.        
  23.         this.x += Math.random() * 12;
  24.         this.x -= Math.random() * 10;
  25.         this.y += Math.random() * 12;
  26.         this.y -= Math.random() * 10;
  27.        
  28.        
  29.         if(this.x < 0){
  30.            
  31.         this.x = 3 * (int)(Math.random() * 60);
  32.                 }
  33.        
  34.         if(this.x > 600){
  35.            
  36.             this.x = 3 * (int)Math.random() * 60;
  37.         }
  38.        
  39.         if( this.y < 0){
  40.            
  41.             this.y = 10 * (int)Math.random() * 60;
  42.             }
  43.        
  44.         if(this.y > 600){
  45.            
  46.             this.y = 10 * (int)Math.random() * 60;
  47.         }
  48.    
  49.     }
  50.    
  51.     public void paint(Graphics g){
  52.         //g.drawRect(x, y, a, a);
  53.         g.setColor(c);
  54.         g.fillRect(x, y, a, a);
  55.        
  56.        
  57.     }
  58.        
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement