အက်ဥပဒ်ထုတ်လုပ် အကြား

အကြီးအဖွား အဖြူ အပိုင်း တံတား မြောက် သို့ လိုက်သွား ပြီး ပြန်ပန်းလာသည်


အပြန်ပန်း

ကျွန်တော်တို့ အသုံးပြုရန် ရှိသေးသည် အခြား သတိပုံ တစ်ခု ဖြစ်သည် bounce အချက်အလက်。

bounce အချက်အလက် သည် တံတား မြောက် သို့ ဆင်းနေစဉ် အပြန်ပန်း ဖြစ်ပါသည်။

bounce သုံးစွဲမှုသည် ပုံစံ သတင်းအရ ပုံစံ အသုံးပြုသူ အချက်အလက် ဖြစ်ပါသည်။ 0 သည် အပြန်ပန်းမှု မရှိသေးသည်၊ 1 သည် အပြန်ပန်းသည် စတင် ကျဆင်းခြင်း သို့ လမ်းကြောင်း ပြန်ပြန်လာသည်။

အကြိမ်

function component(width, height, color, x, y, type) {
  this.type = type;
  this.width = width;
  this.height = height;
  this.x = x;
  this.y = y;
  this.speedX = 0;
  this.speedY = 0;
  this.gravity = 0.1;
  this.gravitySpeed = 0;
  this.bounce = 0.6;
  this.update = function() {
    ctx = myGameArea.context;
    ctx.fillStyle = color;
    ctx.fillRect(this.x, this.y, this.width, this.height);
  }
  this.newPos = function() {
    this.gravitySpeed += this.gravity;
    this.x += this.speedX;
    this.y += this.speedY + this.gravitySpeed;
    this.hitBottom();
  }
  this.hitBottom = function() {
    var တံတားမြောက် = this.gamearea.canvas.height - this.height;
    if (this.y > တံတားမြောက်) {
      this.y = တံတားမြောက်;
      this.gravitySpeed = -(this.gravitySpeed * this.bounce);
    }
  }
}

亲自试一试