Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com;
- import java.awt.Rectangle;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Random;
- public class Area {
- private static final Random rand = new Random();
- public int x, y, w, h;
- public boolean visible = false;
- public List<Rectangle> objects = new ArrayList<>();
- public Area(int x, int y, int width, int height) {
- this.x = x;
- this.y = y;
- this.w = width;
- this.h = height;
- }
- public void fillObjects() {
- int count = 10 + rand.nextInt(10);
- loop: for (int i = 0; i < count; i++) {
- int ww = w / 3 + rand.nextInt(3);
- int hh = h / 3 + rand.nextInt(3);
- int xx = x + 3 + rand.nextInt(w - 6 - ww);
- int yy = y + 3 + rand.nextInt(h - 6 - hh);
- if (i < 5) {
- int offs = 10;
- ww = w - offs;
- hh = h - offs;
- xx = x + offs / 2 + 1;
- yy = y + offs / 2 + 1;
- if (rand.nextInt(4) != 0) {
- ww /= 2;
- if (rand.nextBoolean()) xx += ww;
- }
- if (rand.nextInt(4) != 0) {
- hh /= 2;
- if (rand.nextBoolean()) yy += hh;
- }
- }
- Rectangle obj = new Rectangle(xx, yy, ww, hh);
- for (Rectangle r : objects) {
- if (obj.intersects(r)) continue loop;
- }
- objects.add(obj);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement