xxxxxxxxxx
313
let positionY = 300;
let positionX = 10;
let particles = [];
let ramp = false;
let rampC = false;
let input, button, ans;
let constrainX = 600;
let bitFont;
let fontSize = 28;
let sceneNum;
function preload() {
bitFont = loadFont('PixelFont.ttf');
}
function setup() {
createCanvas(600, 400);
textFont(bitFont);
input = createInput();
me = new Me()
road = new Road()
for (let i = 0; i < 15; i += 2) {
particles[i] = new Particles(20, 20, 20)
}
// restart = new Restart(260, 180, 90, 30);
question = new Question()
}
function draw() {
background(0);
me.body();
me.move();
me.home();
me.checkCollision();
road.body();
road.move();
// restart.body();
question.body();
for (let i = 0; i < 15; i += 2) {
particles[i].body();
particles[i].move();
}
answer();
// switch (sceneNum) {
// case 0:
// console.log('scene 0')
// break;
// case 1:
// console.log('scene 1')
// break;
// case 2:
// console.log('scene 2')
// }
if (positionX > 550) {
sceneNum++
end();
console.log(sceneNum)
input.position(20, -175);
} else {input.position(20,175)}
}
function answer() {
const response = input.value();
for (let i = 0; i < 250; i += 50) {
if (response == 'a') {
positionX=mouseX; }
if (response == 'b') {
positionY= mouseY;
positionX+=0.15;
}
if (response == 'c') {
positionX=mouseY;
positionY= mouseX;
}
// if (response == 'b' && keyIsDown(32) && positionX > 100) {
// positionY -= 1;
// positionX += 0.015;
// } else if (positionX > 100) {
// positionY += 1;
// positionX += 0.015;
// }
// if (response == 'c' && keyIsDown(32) && positionX > 10) {
// positionX += 3;
// positionY += 0.5;
// }
// if (response == 'a' && keyIsDown(32) && positionX > 100) {
// positionY += 5;
// }
}
}
function scene0() {
background(0, 0, 255);
console.log('scene 1');
}
function scene1() {
background(0, 0, 255);
console.log('scene 2');
}
function scene2() {
background(0, 0, 255);
console.log('scene 3');
}
class Particles {
constructor() {
this.x = random(width);
this.y = random(height);
this.w = 10;
this.h = 10;
this.c = color(random(255), random(255), random(255));
}
body() {
fill(this.c)
ellipse(this.x, this.y, this.w, this.h)
}
move() {
// this.x -= random(1, 13);
this.y += 0.1
this.x -= 0.1
if (this.y > height) {
this.y = 200
}
}
}
class Road {
constructor() {
this.x = 0;
this.y = 350;
this.w = width;
this.h = 50;
this.c = color(60);
//pot holes
}
body() {
fill(this.c)
rect(0, this.y, this.w, this.h)
push()
fill(40);
ellipse(this.x + 200, this.y, this.w / 20, this.h / 2)
rect(0, -100, width, 200);
}
move() {
this.x -= 10;
if (this.x < -200) {
this.x = 350;
}
}
home() {
if (this.y < 0) {
sceneNum++
this.y = height - 50;
}
if (sceneNum > 2) {
sceneNum = 0;
}
}
}
class Me {
constructor(xx, xc, c) { // a special method that creates the car object
this.x = 10;
this.y = 300;
this.w = 50;
this.h = 50;
this.c = color(0, 255, 0);
}
body() {
fill(this.c);
this.xc = constrain(positionY, 0, 500);
this.xx = constrain(positionX, 10, constrainX);
rect(this.xx, this.xc, this.w, this.h);
}
move() {
if (keyIsDown(32)) {
positionY -= 8;
positionX++;
} else {
positionY = 300;
}
console.log(answer)
}
checkCollision() {
if (this.xc < 120) {
console.log('bumped' + this.xx);
this.w++;
if (this.w > 90) {
console.log('you dead')
this.xx = 10;
}
}
}
home() {
if (positionX > 550) {
sceneNum++
end();
console.log(sceneNum)
}
}
}
class Question {
constructor() {
this.x = 0;
this.y = 350;
this.w = width;
this.h = 50;
this.c = color(60);
//pot holes
}
body() {
push();
fill(255)
textSize(fontSize);
text("Select attributes to control the car using your mouse", 20, 50)
text("car(x,y,width,height){", 20, 80)
text("a. x position linked to mouseX ", 20, 110)
text("b. y position linked to mouseY", 20, 135)
text("c. x position to mouseY and y position to mouseX ", 20, 160)
push()
fill(40);
pop();
}
}
function end() {
fill(255)
rect(0, 0, width, height)
}