Left click to move forwards, left/right arrows to drive left or right
A fork of Infinite Car Driving V1 by TomOwen
xxxxxxxxxx
let buildings = []
let myCamera;
let myFont;
function preload() {
myFont = loadFont('Roboto-Black.ttf');
}
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
myCar = new Car()
myCamera = createCamera();
// myCamera.setPosition(0,-100,0)
}
function draw() {
background("lightblue");
if (frameCount % 60 === 0){
createBuildings()
createRoads()
keyPressedDown()
}
buildings = buildings.filter(building => building.pos.dist(myCar.pos) < 4000)
myCamera.setPosition(myCar.pos.x-400, myCar.pos.y-150, myCar.pos.z+50)
myCamera.lookAt(myCar.pos.x, myCar.pos.y, myCar.pos.z);
// orbitControl(5, 5, 0.01);
textFont(myFont);
textSize(36);
// text("test", myCar.pos.x,myCar.pos.y)
myCar.draw()
myCar.update()
push()
fill("black")
translate(myCar.pos.x+2000, 0, 0)
box(10000, 0, 200)
pop()
for(let i = 0; i<400; i++){
push()
fill("yellow")
translate(i*400, -0.1,0)
box(100, 0, 20)
pop()
}
push()
fill("darkgrey")
strokeWeight(1)
stroke("black")
translate(myCar.pos.x+2000, 0, -115)
box(10000, -15, 75)
pop()
push()
fill("grey")
translate(myCar.pos.x+2000, 1, -115)
box(10000, 0, 20000)
pop()
//Add some lights (every frame!) ------------------------------------------------
//Add directional light to surfaces which face it
directionalLight(color(150, 100, 0), createVector(-0.8, -0.5, -0.2));
//Add a little light evenly to ALL surfaces. Not too much or we'll see no shadow
ambientLight(180, 150, 150);
noStroke();
ambientMaterial(color("#ed6663")); //Material for the next shape(s) to be drawn
drawBuildings(1)
}
function createRoads(){
}
function drawBuildings(count){
for (let building of buildings){
building.drawBuilding()
}
}
function keyPressed() {
if (keyCode === 86) {
myCamera.setPosition(100, -400, 300);
}
}
function createBuildings(){
for(let i = 0; i<10; i++){
buildings.push(new Building(myCar.pos.x+1000*i, random(200,250)))
buildings.push(new Building(myCar.pos.x+1000*i, -random(200,250)))
}
}
function keyPressedDown() {
if (keyIsDown(UP_ARROW)) {
myCar.vel.mult(1.1)
myCar.vel.limit(5)
}
if (keyIsDown(DOWN_ARROW)) {
myCar.vel.mult(0.5)
}
}