xxxxxxxxxx
298
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 = 1;
function preload() {
bitFont = loadFont('PixelFont.ttf');
}
function setup() {
createCanvas(600, 400);
textFont(bitFont);
input = createInput();
input.position(20, 175);
me = new Me()
road = new Road()
for (let i = 0; i < 5; i += 2) {
particles[i] = new Particles(20, 20, 20)
}
// restart = new Restart(260, 180, 90, 30);
question = new Question()
}
function answer() {
const response = input.value();
for (let i = 0; i < 250; i += 50) {
if (response == 'a') {
fill(255)
rect(200 + i, 350, 50, 50);
ramp = true;
} else if (response == 'b') {
fill(255)
rect(200, 50 + i, 50, 50)
ramp = false;
} else if (response == 'c') {
fill(255)
rect(200, 50, 50, 50 * i)
rampC = true;
} else {
ramp = false;
push();
fill(65, 170, 166)
textSize(25)
text('Choose one of the options', 20, 20)
pop();
}
}
}
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 < 5; 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')
}
}
function scene0() {
background(0, 0, 255);
console.log('scene 2');
}
function scene1() {
background(0, 0, 255);
console.log('scene 2');
}
function scene2() {
background(0, 0, 255);
console.log('scene 2');
}
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, 270, 120, 250)
}
move() {
this.x -= 10;
if (this.x < -200) {
this.x = 350;
}
}
}
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 - 80, 0, 500);
this.xx = constrain(positionX, 10, constrainX);
rect(this.xx, this.xc, this.w, this.h);
}
move() {
console.log(positionX)
// jump
if (keyIsDown(32) && positionX > 100) {
positionY -= 5;
positionX++;
}
else if (positionX > 100) {
positionY += 5;
positionX += 0.5;
}
// if (mouseIsPressed) {
// positionY -= 5;
// positionX++;
// }
// else if (positionX > 100) {
// positionY += 5;
// positionX += 0.5;
// }
// else{ positionX+=0.5}
}
// if (this.xx > 120) {
// positionY += 20;
// }
// }
checkCollision() {
if (this.xc > 300) {
console.log('bumped' + this.xx);
}
}
home() {
if (positionX > 560) {
sceneNum++
scene2();
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 for flight when the space bar is down", 20, 50)
text("If keyIsDown(32){", 20, 80)
text("a. Increase y position", 20, 110)
text("b. Decrease y position", 20, 135)
text("c. Increase x position", 20, 160)
// if (keyIsDown(32) && positionX > 100) {
// positionY -= 5;
// positionX++;
push()
fill(40);
pop();
}
}