public Level createLevel(int id) { Level lev = new Level(id); for (SpriteBox box : myPaintableBoxes) { lev.addNewSprite(box.getSprite()); } return lev; }
public void addSprite(Sprite spr, int x, int y) { SpriteBox currentBox = nearestBox(x, y); if (checkAvailable(currentBox, spr.getWidth(), spr.getHeight())) { currentBox.addSprite(spr); myPaintableBoxes.add(currentBox); combineBoxes(currentBox, currentBox, spr.getWidth(), spr.getHeight()); } else { // TODO send Unavailable feedback } }
private boolean checkAvailable(SpriteBox current, double width, double height) { if (!current.isAvailable()) { return false; } boolean bool1 = true; boolean bool2 = true; if (width > mySpriteSize) { SpriteBox next = nearestBox(current.getX() + mySpriteSize, current.getY()); bool1 = checkAvailable(next, width - mySpriteSize, height); } if (height > mySpriteSize && bool1) { SpriteBox nextBox = nearestBox(current.getX(), current.getY() + mySpriteSize); bool2 = checkAvailable(nextBox, width, height - mySpriteSize); } return bool1 && bool2; }
private void combineBoxes(SpriteBox initial, SpriteBox current, double width, double height) { if (width > mySpriteSize) { SpriteBox next = nearestBox(current.getX() + mySpriteSize, current.getY()); initial.combineWith(next); combineBoxes(initial, next, width - mySpriteSize, height); } if (height > mySpriteSize) { SpriteBox next = nearestBox(current.getX(), current.getY() + mySpriteSize); initial.combineWith(next); combineBoxes(initial, next, width, height - mySpriteSize); } }
public void deleteSprite(int x, int y) { SpriteBox currentBox = nearestBox(x, y); currentBox.deleteSprite(); myPaintableBoxes.remove(currentBox); }
@Override public void paint(Graphics2D pen) { for (SpriteBox box : myPaintableBoxes) { box.paint(pen); } }