class Stage2D { // PROPERTIES ##################################################################### int w; //number of columns int h; //number of rows int cellSize; //size of each square [px] // CONSTRUCTORS #################################################################### Stage2D(int a, int b, int cs) { w = a; h = b; cellSize = cs; } // METHODS ######################################################################### //draws the comlete stage //one square for each field void drawStage() { for(int i = 0; i < w; i++) //cycle through the columns { for(int j = 0; j < h; j++) //cycle through the rows { // calculate the x and y quad positions int x = (i*cellSize)-(cellSize*w/2); int y = (j*cellSize)-(cellSize*h/2); if (theWorld.fieldMem[i][j][1] != 9) { // change the color / even - odd if((i+j) % 2 == 0) { fill( 50, 50, 50, 255); }else { fill(0, 0, 0, 255); } color smelly; Field currField = (Field) theWorld.getField(i,j); float blue = 255/ (float)(currField.nestSmell+1) /0.001; smelly = color(255-(255/ (currField.foodSmell+1)),blue,blue); fill(smelly); // draw quad beginShape(QUADS); vertex(x, y, 0); vertex(x+cellSize, y, 0); vertex(x+cellSize, y+cellSize,0); vertex(x, y+cellSize, 0); endShape(); drawFood(x, y, currField.getFoodAmount()); } else { //draw the boundary float xB = x+(cellSize/2.0); float yB = y+(cellSize/2.0); fill(0); pushMatrix(); translate(xB, yB, cellSize/4.0); box(cellSize, cellSize, cellSize/2.0); popMatrix(); } } } drawNest(theWorld.nestX, theWorld.nestY, theWorld.nestSize, theWorld.getWidth(), theWorld.getHeight()); } int getCellSize() { return cellSize; } void drawNestOLD(int centerX, int centerY, int amount, int wWidth, int wHeight) { float xB = -wWidth/2*cellSize +centerX*cellSize+(cellSize/2.0); float yB = -wHeight/2*cellSize +centerY*cellSize+(cellSize/2.0); for (int i=0; i=0; level--) { for(int i=levelSize[level]-1; i>=0; i--) { for (int k=levelSize[level]-1; k>=0; k--) { if (amount<=0) break; amount--; pushMatrix(); translate(xB+ i*cellSize, yB+ k*cellSize, fHeight/2.0 -fHeight*level+ fHeight*(levelSize.length-1)); noStroke(); box(fSize, fSize, fHeight*0.9); popMatrix(); } } } /* for(int level=levelSize.length-1; level>=0; level--) { for(int i=levelSize[level]-1; i>=0; i--) { for (int k=levelSize[level]-1; k>=0; k--) { if (amount<=0) break; amount--; pushMatrix(); translate(xB+ i*cellSize, yB+ k*cellSize, fHeight/2.0 -fHeight*level+ fHeight*(levelSize.length-1)); noStroke(); box(fSize, fSize, fHeight*0.9); popMatrix(); } } } */ } int[] getPyramidLevels(int amount) { int q = 1; int nsize = amount; int[] levSize; levSize = new int[0]; do { int sq = round(pow(q, 2)); levSize = append(levSize, q); nsize = nsize -sq; q += 2; } while (nsize > 0); return levSize; } void drawFood(int x, int y, int amount) { float xB = x+(cellSize/2.0); float yB = y+(cellSize/2.0); if (amount>0) { float fHeight = cellSize; float fSize = cellSize*0.9; fill(200, 200, 0, 100); noFill(); stroke(200); pushMatrix(); translate(xB, yB, fHeight*amount/2.0); // stroke(0); // strokeWeight(3); box(fSize, fSize, fHeight*amount*0.9); noStroke(); popMatrix(); } } void drawFoodOLD(int x, int y, int amount) { float xB = x+(cellSize/2.0); float yB = y+(cellSize/2.0); for (int i=0; i