গেম স্প্রিং

এই লাল ব্লক পৃষ্ঠভূমির উপর আসলে হাঁটে উঠবে:


হাঁটানো

আমরা যোগ করতে চাই আরেকটি ফিচার bounce প্রতিযোগী

bounce এই প্রতিযোগীটি জগ্রতির কারণে ভূমির উপর আসলে এবং পুনরায় আসবে কি না তা ইনডিকেট করে

bounce প্রতিযোগী মানগুলি সংখ্যাত্মক হতে হবে। ০ পূর্ণ রিবন্সকে না করে, ১ কম্পোনেন্টটি যাতে সূচনা থেকে আসা যায় তার জন্য

ইনস্ট্যান্স

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 rockbottom = this.gamearea.canvas.height - this.height;
    if (this.y > rockbottom) {
      this.y = rockbottom;
      this.gravitySpeed = -(this.gravitySpeed * this.bounce);
    }
  }
}

আমরা নিজেদের দ্বারা প্রয়াস করি