xxxxxxxxxx
97
let pal;
let movbolax = 5;
let movbolay = 0;
let anchobola = 5;
let altobola =5;
let alturainiciobola = 198;
let distx;
let distx2;
let disty;
let rad;
let deg;
let distancefromtop;
let medidapala;
let angulo;
class Bolas {
constructor() {
this.x = (width / 2);
this.y = alturainiciobola ;
}
mostrarbola() {
rectMode(CENTER);
rect(this.x, this.y, anchobola*2, altobola*2);
}
moverbola() {
this.x += movbolax;
this.y += movbolay;
}
contactoizquierda(pal) {
distx = ((this.x) - (pal.xx));
if ((this.y > pal.yy-alto) && (this.y < (pal.yy + alto))
&&
// this.x - anchobola <= (pal.x + ancho)) {
distx <= 10
&& distx >5
)
{
//console.log(this.y,pal.yy,distx);
// disty =(this.y - (pal.y - alto));
// rad = radians(45);
// angulo = map(disty,0, alto*2, -rad, rad);
angulo = 3*PI / 4 * (this.y / alto) - PI / 8;
movbolax = 5 * sin(angulo);
movbolay= 5 * cos(angulo);
// console.log(sin(angulo),angulo,this.y,alto);
//movbolax *= -1;
}
}
contactoderecha(pal2) {
distx2 = ((pal2.xx-ancho) - (this.x+anchobola));
if (this.y > (pal2.yy-alto) && this.y < (pal2.yy+alto) &&
//this.x + anchobola >= (pal2.x - ancho)) {
distx2 <= 2 && distx2 >=-1){
disty =(this.y - (pal2.yy-alto));
//console.log(disty);
//rad = radians(135);
//angulo = map(disty,0, alto*2, -rad, rad);
distancefromtop = (this.y-(pal2.yy-alto));
medidapala = alto*2;
angulo = (5*PI/4 -(distancefromtop/medidapala)*4*PI/9);
deg = degrees( angulo);
//console.log(deg);
movbolax = 5 * cos(angulo);
movbolay= 5 * sin(angulo);
console.log(sin(angulo),deg,distancefromtop,medidapala);
//movbolax *= -1;
}
}
esquinas() {
if (this.y-altobola < 0 || this.y+altobola > height) {
movbolay *= -1;
}
}
reset () {
if (this.x<0 || this.x >800) {
this.x = (width / 2);
this.y = 198;
movbolax = 5;
movbolay = 0;
}
}
}
//(this.x == pal.x) &&