Skip to content
Permalink
2abd3d2170
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
99 lines (79 sloc) 2.3 KB
//////////////////////////////////////////////////////////////////
// Global Variables
//////////////////////////////////////////////////////////////////
// Debug Variable
// WARNING: Do not delete this variable, it's being used in some
// classes
boolean debug = true;
//////////////////////////////////
// Main Objects
//////////////////////////////////
// A path object (series of connected points)
Path path;
// Two vehicles
Vehicle car1;
Vehicle car2;
//////////////////////////////////////////////////////////////////
// Setup
//////////////////////////////////////////////////////////////////
void setup()
{
// Set canvas size
size(1000, 1000);
// Call a function to generate new Path object
newPath();
// Each vehicle has different maxspeed and maxforce for demo purposes
car1 = new Vehicle(new PVector(0, height/2), 1, 0.04);
car2 = new Vehicle(new PVector(0, height/2), 1, 2);
}
//////////////////////////////////////////////////////////////////
// Draw
//////////////////////////////////////////////////////////////////
void draw()
{
// Background
background(255);
// Display the Road and center line path
path.display(true);
// The boids follow the path
car1.follow(path);
car2.follow(path);
// Call the generic run method (update, borders, display, etc.)
car1.run();
car2.run();
//car1.borders(path);
//car2.borders(path);
//car1.borders();
//car2.borders();
// Instructions
fill(0);
}
// Here define the element of the track
/*void newPath()
{
// A path is a series of connected points
// A more sophisticated path might be a curve, if you want to have a try.
path = new Path();
path.addPoint(100, height/2);
path.addPoint(100,height/2+200);
path.addPoint(300,height/2+200);
path.addPoint(300,height/2);
// path.addPoint(200, height/2+5);
}*/
void newPath() {
// A path is a series of connected points
// A more sophisticated path might be a curve
path = new Path();
float offset = 30;
path.addPoint(offset,offset);
path.addPoint(width-offset,offset);
path.addPoint(width-offset,height-offset);
path.addPoint(width/2,height-offset*3);
path.addPoint(offset,height-offset);
}
public void keyPressed()
{
if (key == ' ') {
debug = !debug;
}
}