xxxxxxxxxx
82
let pal;
let movbolax = 5;
let movbolay = 0;
let anchobola = 5;
let altobola =5;
let distx;
let distx2;
let disty;
let rad;
let angulo;
class Bolas {
constructor() {
this.x = (width / 2);
this.y = 88;
}
mostrarbola() {
rectMode(CENTER);
rect(this.x, this.y, anchobola*2, altobola*2);
}
moverbola() {
this.x += movbolax;
this.y += movbolay;
}
contactoizquierda(pal) {
distx = ((this.x-anchobola) - (pal.x + ancho));
if ((this.y > pal.y - alto) && (this.y < (pal.y + alto)) &&
// this.x - anchobola <= (pal.x + ancho)) {
distx <= 1) {
// disty =(this.y - (pal.y - alto));
// rad = radians(45);
// angulo = map(disty,0, alto*2, -rad, rad);
// movbolax = 5 * cos(angulo);
// movbolay= 3 * sin (angulo);
//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);
//console.log(disty);
//rad = radians(135);
//angulo = map(disty,0, alto*2, -135, 135);
angulo = PI / 4 * (this.y / alto) - PI / 8
movbolax = 5 * cos(angulo);
movbolay= 5 * sin (angulo);
console.log(angulo);
//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 = 88;
movbolax = 5;
movbolay = 0;
}
}
}
//(this.x == pal.x) &&