Blocks blocks = new Blocks(); final static int MAX_PARTICLES = 300; Particle particles[] = new Particle[MAX_PARTICLES]; int particle_count = 0; void setup() { size(200,200); framerate(20); } void mouseDragged() { if (particle_count=0 && y>=0 && x < blockX && y < blockY) return blocks[x+y*blockX]!=0; return false; } boolean isSolid(float x, float y) { return isSolidTile(int(x/blockW),int(y/blockH)); } boolean isSolid(float x, float y, float radius) { return isSolid(x+radius,y) || isSolid(x-radius,y) || isSolid(x,y+radius) || isSolid(x,y-radius); } } class Particle { float x,y; float dx, dy; float radius = 5; Particle(float x, float y) { this.x = x; this.y = y; } void update(int i) { while (i=0) { x+=stepx; y+=stepy; // Check if x edge hit something if (blocks.isSolid(x+(dx>0?radius:-radius),y)) { x-=stepx; dx=0; stepx=0; } // Check if y edge hit something if (blocks.isSolid(x,y+(dy>0?radius:-radius))) { y-=stepy; dy=0; stepy=0; } } } void draw() { fill(0,0,80); ellipseMode(CENTER_RADIUS); ellipse(x,y,radius,radius); } }