Bullets bullets; Piksels piksels; int counter = 100; int level = 100; boolean isGameOver = false; void setup() { size(200, 200); // Size should be the first statement noStroke(); // Set line drawing color to white frameRate(25); bullets = new Bullets(); piksels = new Piksels(); } void draw() { if(isGameOver){ gameOver(); return; } if(counter > level){ level--; counter = 0; piksels.create(); } background(0); // Set the background to black bullets.draw(); piksels.draw(); for(int i = 0; i= height) this.fifo(); } } } /* piksels: create lines of evil piksels eating our screen. */ class Piksels{ int rows = height/10; int cols = width/10; int w = width/cols; int h = width/rows; int lines = 0; int[] blocks = new int[rows*cols]; int[] colors = new int[rows*cols]; color[] palette = {#99CCFF, #CC99FF, #FF99CC, #CCFF99, #99FFCC, #990000}; Piksels(){ for(int i=0; i= rows){ isGameOver = true; return; // gameover } for(int i=0;i 0){ fill(palette[colors[i]]); rect(x, y, w, h); } } } // detects collison and calls clear() when needed boolean collision(int x, int y){ int col = floor(x/w); int row = rows-ceil(y/h)-1; int index = col + row * cols; if(row < 0) return false; if(blocks[index] > 0){ blocks[index] = 0; // nullify the block for(int i = row*cols; i 0) return true;// return immediately if the line is not empty } this.clear(row); } return false; } // clears an empty row and moves it to the end of the array void clear(int row){ lines--; int start = row*cols; for(int i=start; i < start+cols; i++){ blocks[i] = 0; } int[] r = subset(blocks, start, cols);// save the empty row if(start == 0){ blocks = subset(blocks, cols); } else{ int[] after = subset(blocks, start+cols); blocks = (int[])subset(blocks, 0, start); blocks = splice(blocks, after, blocks.length); } blocks = splice(blocks, r, blocks.length); } } void gameOver(){ PFont font; // The font must be located in the sketch's // "data" directory to load successfully stroke(#000000); font = loadFont("Freshbot-48.vlw"); textFont(font); fill(#CC0000); text("Game Over", 0, 90); exit(); } void mousePressed(){ bullets.create(); }