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) { float mag = distance*distance*distance/1000; float angle = atan2(y-p.y, x-p.x) + random(-0.01,0.01); float ddx = mag * cos(angle); float ddy = mag * sin(angle); dx += ddx; dy += ddy; p.dx -= ddx; p.dy -= ddy; } i++; } dy+=0.5; // Move the particle in small increments to check for rigid collisions float rate = max(dx,dy); int steps = max(1,(int)(rate / 0.5)); // Calculate step float stepx = dx/steps; float stepy = dy/steps; while (--steps>=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); } }