forked from mperes/ZombieAttack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFloorGenerator.pde
31 lines (27 loc) · 910 Bytes
/
FloorGenerator.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class FloorGenerator {
PImage floorImage;
PImage[] floorTiles;
color baseColor = color(0);
int tileMargin = 1;
int tileSize = 11;
FloorGenerator(int floorWidth, int floorHeight) {
floorTiles = new PImage[10];
for(int i=0; i<floorTiles.length; i++) {
floorTiles[i] = loadImage(IMGPATH+"floortiles/floortile_"+(i+1)+".png");
}
PGraphics pg = createGraphics(floorWidth, floorHeight, JAVA2D);
pg.beginDraw();
pg.background(baseColor);
for(int r=0; r<ceil(floorHeight/(tileMargin+tileSize)); r++) {
for(int c=0; c<ceil(floorWidth/(tileMargin+tileSize)); c++) {
int floorImage = round(random(floorTiles.length-1));
pg.image(floorTiles[floorImage], c*(tileMargin+tileSize), r*(tileMargin+tileSize));
}
}
pg.endDraw();
floorImage = pg.get(0, 0, pg.width, pg.height);
}
void draw() {
set(0, 0, floorImage);
}
}