Permalink
Cannot retrieve contributors at this time
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?
RaceCarSim/simulation.pde
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
88 lines (69 sloc)
2.06 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////////////////////////////////////////// | |
// 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 sanme maxspeed and different maxforce for different peroformance. | |
//You could set different parameters to check different perfomance. | |
car1 = new Vehicle(new PVector(0, height/2-400), 1, 0.04); | |
car2 = new Vehicle(new PVector(0, height/2-400), 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 | |
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; | |
} | |
} |