xxxxxxxxxx
112
var time;
var train;
let cross;
let cross1;
var track;
var tracks = [];
var ang;
function setup() {
// mySound.setVolume(0.05);
createCanvas(1000, 550);
cross = new crossing(870, 520, -300);
cross1 = new crossing(300, 280, -200);
cross.show();
cross1.show();
train = new train();
//mySound.loop();
for (var i = 0; i < 20; i++) {
tracks[i] = new Tracks(i * 60, 480);
}
}
function draw() {
let ang = constrain(cross.ang, -75, 0);
//mySound.stop();
background(98);
translate(0, 0)
rectMode(CORNER);
for (var i = 0; i < tracks.length; i++) {
tracks[i].show();
rect(0, 460, width, -20);
rect(0, 380, width, -20);
}
cross1.show();
train.show();
train.move();
cross.show();
cross.move();
cross1.move();
ellipse(350, 140, 50)
ellipse(400, 140, 50)
fill(255)
ellipse(350, 140, 35)
ellipse(400, 140, 35)
fill(0);
ellipse(920, 300, 50)
ellipse(970, 300, 50)
fill(255)
ellipse(920, 300, 35)
ellipse(970, 300, 35)
//if(cross.ang >= -73 && cross.ang < 0) {
time = frameCount % 20;
if (time == 1 && cross.ang >= -70 && cross.ang < 0) {
fill(255, 0, 0);
ellipse(350, 140, 35)
ellipse(920, 300, 35)
} else if (time == 10 && cross.ang >= -70 && cross.ang < 0) {
fill(255, 0, 0);
ellipse(400, 140, 35)
ellipse(970, 300, 35)
}
// if(cross.ang <= -70){
// mySound.pause();
//} else if(!mySound.isLooping() && cross.ang >= -60) {
// mySound.play();
// }
// if (!mySound.isLooping() && cross.ang > -65 && cross.ang < -2) {
// mySound.play();
//} else {
//mySound.pause();
//}
push();
fill(200);
translate(385, 230)
rotate(ang);
rect(0, 0, 300, -20);
pop();
push();
fill(200);
translate(935, 440);
rotate(ang * -1);
rect(0, 0, -300, -20);
pop();
}
function keyReleased() {
train.setDir(0);
cross.setDir(0);
cross1.setDir(0);
}
function keyPressed() {
if (keyCode === RIGHT_ARROW) {
train.setDir(1);
console.log("right");
} else if (keyCode === LEFT_ARROW) {
train.setDir(-1);
console.log("left");
} else if (keyCode === UP_ARROW) {
if (cross.ang >= -75) {
cross.setDir(-0.2);
cross1.setDir(0.2);
console.log("up");
}
} else if (keyCode === DOWN_ARROW) {
if (cross.ang < 0) {
cross.setDir(0.2);
cross1.setDir(-0.2);
}
}
}