Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- public class GameObject {
- private int x,y;
- private Color c;
- private int a = 40;
- public GameObject(){
- this.x = (int)(Math.random()* 600);
- this.y = (int)(Math.random()* 600);
- this.c = new Color((int)(Math.random()*255),(int)(Math.random()*255),(int)(Math.random()*255));
- }
- public void move(){
- this.x += Math.random() * 12;
- this.x -= Math.random() * 10;
- this.y += Math.random() * 12;
- this.y -= Math.random() * 10;
- if(this.x < 0){
- this.x = 3 * (int)(Math.random() * 60);
- }
- if(this.x > 600){
- this.x = 3 * (int)Math.random() * 60;
- }
- if( this.y < 0){
- this.y = 10 * (int)Math.random() * 60;
- }
- if(this.y > 600){
- this.y = 10 * (int)Math.random() * 60;
- }
- }
- public void paint(Graphics g){
- //g.drawRect(x, y, a, a);
- g.setColor(c);
- g.fillRect(x, y, a, a);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement