Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <script type="application/processing">
int level = 1;
int goes = 0;
float heading = 0;
float dHeading = .1;
float pX = 50;
float pY = 100;
float spX = 50;
float spY = 100;
float pR = 25;
boolean charging = false;
boolean moving = false;
float charge = 0;
float dCharge = .5;
float maxCharge = 20;
float speed = 0;
float minSpeed = 1;

boolean showFriend = false;
float fX = 250;
float fY = 250;
float fHeading = 0;
float fdHeading = -.15;

float goalX = 450;
float goalY = 100;
float goalR = 25;

String msgOne = "One Roomba";
String msgTwo = "Press to charge.";
String msgThree = "Press again to go.";

ArrayList<Bad> bads = new ArrayList<Bad>();

void setup(){
	size(500, 500);
	frameRate(30);
	textAlign(CENTER, CENTER);
	textSize(24);
	strokeWeight(4);
	stroke(255);
}

void mousePressed(){
	
	if(!moving){
		if(charging){
			 moving = true;
	   charging = false;
    speed = charge;
    goes++;
		}
		else{
		  charging = true;
	   charge = 0;
		}
	}
	
}

void draw(){
	background(64);
	
	fill(255);
	text(msgOne, width/2, 100);
	text(msgTwo, width/2, 250);
	text(msgThree, width/2, 400);
	
	if(moving){
		 pX += cos(heading)*speed;
	  pY += sin(heading)*speed;
	  
	  if(dist(pX, pY, goalX, goalY) < pR+goalR){
	  	  spX = pX;
	  	  spY = pY;
	  	  level++;
	    	startLevel();
	  }
	  
	  if(pX<pR){
	  	  pX = pR;
	  } 
	  if(pX>width-pR){
	  	  pX = width-pR;
	  }
	  if(pY<pR){
	  	  pY = pR;
	  }
	  if(pY >height-pR){
	  	  pY = height-pR;
	  }
	  
	  if(showFriend){
	    fX += cos(fHeading)*speed;
	    fY += sin(fHeading)*speed;
	  
	    if(fX<pR){
	    	  fX = pR;
   	  } 
   	  if(fX>width-pR){
	    	  fX = width-pR;
	    }
   	  if(fY<pR){
	  	    fY = pR;
	    }
	    if(fY >height-pR){
	  	    fY = height-pR;
	    }
	  }
	  
	  speed *= .9;
	  if(speed < minSpeed){
	  	  moving = false;
	  }
	}
  else if(!charging){
	   heading += dHeading;
    fHeading += fdHeading;
	}
	
	fill(0, 0, 255);
	ellipse(pX, pY, pR*2, pR*2);
	float hX = pX + cos(heading)*pR;
	float hY = pY + sin(heading)*pR;
	line(pX, pY, hX, hY);
	
	if(showFriend){
		 fill(0, 255, 0);
	  ellipse(fX, fY, pR*2, pR*2);
	  float fhX = fX + cos(fHeading)*pR;
   	float fhY = fY + sin(fHeading)*pR;
	  line(fX, fY, fhX, fhY);
		
	}
	
	if(charging){
		charge += dCharge;
		if(charge < 0 || charge > maxCharge){
			dCharge *= -1;
		}
		fill(0, 0, 255);
		ellipse(pX, pY, pR*2*charge/maxCharge, pR*2*charge/maxCharge);
	}
	
	fill(0, 255, 0);
	ellipse(goalX, goalY, goalR*2, goalR*2);
	
	for(int i = 0; i < bads.size(); i++){
		Bad b = bads.get(i);
		b.draw();
		
		if(dist(pX, pY, b.x, b.y) < pR+b.r){
			pX = spX;
			pY = spY;
			startLevel();
			break;
		}
	}
	
	fill(255);
	text(goes, 50, 20);
}

class Bad{
	float x;
	float y;
	float r;
	boolean chase;
	float xSpeed;
	float ySpeed;
	
	public Bad(float x, float y, float r, boolean chase, float xSpeed, float ySpeed){
		this.x = x;
		this.y = y;
		this.r = r;
		this.chase = chase;
		this.xSpeed = xSpeed;
		this.ySpeed = ySpeed;
	}
	
	void draw(){
		fill(255, 0, 0);
		ellipse(x, y, r*2, r*2);
		if(chase){
			PVector p = new PVector(pX-x, pY-y);
			p.normalize();
			xSpeed = p.x;
	  ySpeed = p.y;
		}
		x += xSpeed;
		y += ySpeed;
		if(x<r || x>width-r){
			xSpeed *= -1;
		}
		if(y<r || y>height-r){
			ySpeed *= -1;
		}
	}
}

void startLevel(){
	speed = 0;
	moving = false;
	charging = false;
	bads.clear();
	
	if(level == 2){
		goalX = 450;
		goalY = 450;
		msgOne = "I can't stop spinning.";
		msgTwo = "Am I broken?";
		msgThree = "Or is the world?";
	}
	else if(level == 3){
		goalX = 50;
		goalY = 50;
		msgOne = "Red is bad.";
		msgTwo = "";
		msgThree = "But am I good?";
		bads.add(new Bad(width/2, height/2, 75, false, 0, 0));
	}
	else if(level == 4){
		 goalY = 400;
		 bads.add(new Bad(200, 300, 25, false, 1, 0));
		 bads.add(new Bad(300, 300, 25, false, -1, 0));
		 
		 msgOne = "They move with such purpose.";
		 msgTwo = "But then why do I";
		 msgThree = "feel so lost?";
	}
	else if(level == 5){
		 goalX = 250;
		 goalY = 200;
		 msgOne = "Am I trapped?";
		 msgTwo = "Or am I free?";
		 msgThree = "Or neither?";
		 
		 bads.add(new Bad(450, 50, 25, false, 1, 1));
		 bads.add(new Bad(450, 50, 25, false, -1, -1));
	}
	else if(level == 6){
		goalX = 450;
		goalY = 450;
		msgOne = "Am I going towards something?";
		msgTwo = "Or away from something else?";
		msgThree = "Is there a difference?";
		 bads.add(new Bad(25, 25, 50, true, 1, -1));
		 bads.add(new Bad(475, 25, 50, true, 1, -1));
		 bads.add(new Bad(25, 475, 50, true, 1, -1));
	}
	else if(level == 7){
		 goalX = 50;
	  	goalY = 50;
  		msgOne = "At least they have each other.";
	  	msgTwo = "Why does that seem worse";
	  	msgThree = "than being alone?";
		 bads.add(new Bad(250, 250, 25, false, 1, -1));
		 bads.add(new Bad(250, 250, 25, false, -1, -1));
		 bads.add(new Bad(250, 250, 25, false, -1, 1)); 	
		 
	}
	else if(level == 8){
		 goalX = 450;
	  	goalY = 50;
  		msgOne = "";
	  	msgTwo = "";
	  	msgThree = "One Roomba";
		 bads.add(new Bad(250,50, 25, false,0,0));
   bads.add(new Bad(250,125, 25, false,0,0));
   bads.add(new Bad(250,200, 25, false,0,0));
 		 bads.add(new Bad(250, 275, 25, false, 0, 0));
		 bads.add(new Bad(250,350, 25, false, 0, 0));
	}
 else{
 	  fX = goalX;
 	  fY = goalY;
 	  goalX = -100;
 	  goalY = -100;
 	  showFriend = true;
 	  
 	  msgOne = "Two Roombas";
 	  msgTwo = "Thanks for playing!";
 	  msgThree = "@KevinAWorkman / HappyCoding.io"
 }
}
</script>
<canvas> </canvas>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console