xxxxxxxxxx
269
let inTouch = false;
let wave = 0;
let waveAngle = 0;
let player;
let backgroundBrightness = 0;
let backgroundHue = 0;
let backgroundSaturation = 0;
let stageEvolution = [25000, 50000]
let gothamFont;
let popSound;
let backgroundElements = [];
let obstacle;
function preload() {
gothamFont = loadFont('Gotham.otf');
popSound = loadSound('Pop.mp3')
}
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
colorMode(HSB);
angleMode(DEGREES);
// popSound.playMode('restart');
popSound.loop = false;
noCursor();
textFont(gothamFont)
textSize(350);
textAlign(CENTER);
pixelDensity(displayDensity());
player = new Player(0, 0, 135, 50, 1);
for (let x = -10000; x < 10000; x = x + 250) {
backgroundElements.push(new Element(x, player.y-4000, player.z-random(0,5000), 100, 100, 100))
}
}
function draw() {
background(backgroundHue, backgroundSaturation, backgroundBrightness);
// if (inTouch)
backgroundBrightness = map(player.y, 0, -stageEvolution[0], 0, 100);
push();
specularMaterial(180, 0, map(player.y, 0, -stageEvolution[0], 100, 0));
translate(player.x, player.y - 3000, player.z + 650)
rotateX(-90)
text((floor(-player.y / 350) * 10), 0, 0)
pop();
//orbitControl();
camera(0, player.y + 350, 250, 0, player.y - 550 + player.y / 2, 0, 0, 1, 0);
// ambientMaterial(10,10,10);
ambientLight(0, 0, 100);
pointLight(0, 0, 100, player.x, player.y + 50, player.z + 50);
// for (let i = 0; i < backgroundElements.length; i = i + 1) {
// backgroundElements[i].update()
// }
player.update();
push();
specularMaterial(180, 0, map(player.y, 0, -stageEvolution[0], 100, 0));
box(width / 3, 5000000, 100);
pop();
push();
translate(0, -16000, 0);
specularMaterial(0, 100, map(player.y, 0, -stageEvolution[0], 100, 0));
box(width / 3, 100, 300);
pop();
push();
translate(0, -12000, 0);
box(width / 3, 100, 300);
pop();
push();
translate(0, -8000, 0);
box(width / 3, 100, 300);
pop();
print(player.y);
if (player.y < -stageEvolution[0]) {
backgroundBrightness = 100 //random(0,100);
backgroundHue = 0 //random(0,360);
backgroundSaturation = 100;
}
if (touches.length > 1) {
popSound.play();
if (player.jumpSpeed < 15)
player.jumpSpeed = player.jumpSpeed + player.jumpAcceleration
} else {
if (player.jumpSpeed > 0) {
player.jumpSpeed = player.jumpSpeed + player.jumpDeceleration
}
}
// }else{if(player.z>135){player.jumpSpeed = player.jumpSpeed + player.acceleration}}
if (player.speed > 0) {
player.speed = player.speed + player.deceleration;
}
// if (dist(player.x,player.y,element.x,element.y, element.z)>10){
// player.x=0;
// player.y=0;
// player.z =0;}
}
function touchStarted() {
inTouch = true;
return false;
}
function touchEnded() {
inTouch = false;
return false;
// if(player.speed > 0)
// {player.speed = player.speed - player.acceleration;}
}
function touchMoved() {
player.rotation = player.rotation + player.rotationSpeed;
player.rotationSpeed = player.rotationSpeed + 1;
if (player.speed <= player.maxSpeed) {
player.speed = player.speed + player.acceleration;
}
// player.speed = player.speed - player.acceleration}
}
class Player {
constructor(x, y, z, r, rotationSpeed) {
this.x = x;
this.y = y;
this.z = z;
this.r = r;
this.rotation = 0;
this.rotationSpeed = rotationSpeed;
this.jumpHeight = 0;
this.jumpSpeed = 0;
this.jumpAcceleration = 10;
this.acceleration = 1;
this.speed = 0;
this.minSpeed = 0;
this.maxSpeed = 35;
this.deceleration = this.acceleration / -8
this.jumpDeceleration = this.jumpAcceleration / -2
this.gravity = -9.81
}
update() {
push();
translate(this.x, this.y, this.z);
strokeWeight(1);
stroke(0, 0, 0, 0)
specularMaterial(180, 100, 75);
rotateX(this.rotation);
sphere(this.r);
pop();
this.y = this.y - this.speed;
if (this.z > 150) {
this.z = this.z + this.gravity;
}
if (this.z < 275) {
this.z = this.z + this.jumpSpeed
}
// this.speed = this.speed +this.acceleration;
// this.jumpHeight = this.jumpHeight + this.jumpSpeed
// this.jumpSpeed = this.jumpSpeed + this.acceleration
//this.rotation = this.rotation + this.rotationSpeed;
}
}
class Element {
constructor(x, y, z, w, h, d) {
this.x = x
this.y = y
this.z = z
this.w = w
this.h = h
this.d = d
}
update() {
push();
translate(this.x, this.y, this.z)
specularMaterial(180, 100, 85);
box(this.w, this.h, this.d)
pop();
}
}
class Obstacles {
constructor(x, y, z, w, h, d) {
this.x = x
this.y = y
this.z = z
this.w = w
this.h = h
this.d = d
}
update() {
push();
translate(this.x, this.y, this.z)
specularMaterial(0, 100, 100);
box(this.w, this.h, this.d)
pop();
}
}