گیم جیوٹری

ਕੁਝ ਖੇਡਾਂ ਵਿੱਚ ਕੰਪੋਨੈਂਟ ਨੂੰ ਇੱਕ ਦਿਸ਼ਾ ਵੱਲ ਖਿੱਚਣ ਵਾਲੀ ਸ਼ਕਤੀ ਹੁੰਦੀ ਹੈ, ਉਦਾਹਰਣ ਵਜੋਂ ਗੂਰੇਤਾ ਵਿਸ਼ੇਸ਼ ਤੌਰ 'ਤੇ ਕੰਪੋਨੈਂਟ ਨੂੰ ਜ਼ਮੀਨ ਵੱਲ ਖਿੱਚਦਾ ਹੈ。


ਗੂਰੇਤਾ

ਜੇਕਰ ਤੁਸੀਂ ਇਹ ਵਿਸ਼ੇਸ਼ਤਾ ਸਾਡੇ ਕੰਪੋਨੈਂਟ ਬਣਾਉਣ ਵਾਲੇ ਫੰਕਸ਼ਨ ਵਿੱਚ ਜੋੜਣਾ ਚਾਹੁੰਦੇ ਹੋ, ਤਾਂ ਪਹਿਲਾਂ ਇੱਕ ਜੋੜੇ ਜੋੜੇ ਕਰੋ gravity 属性، ਇਹ ਵਿਸ਼ੇਸ਼ਤਾ ਮੌਜੂਦਾ ਗੂਰੇਤਾ ਸੈਟ ਕਰਦੀ ਹੈ। ਫਿਰ ਇੱਕ ਜੋੜੇ ਜੋੜੇ ਕਰੋ gravitySpeed ਲੋੜੀਂਦੇ ਅਕਾਰ, ਹਰ ਵਾਰ ਜਦੋਂ ਅਸੀਂ ਫਰੇਮ ਅੱਪਡੇਟ ਕਰਦੇ ਹਾਂ ਤਾਂ ਇਹ ਵਧਦਾ ਹੈ:

مثال

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.05;
  this.gravitySpeed = 0;
  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.newPos = function() {
    this.gravitySpeed += this.gravity;
    this.x += this.speedX;
    this.y += this.speedY + this.gravitySpeed;
    this.hitBottom();
  }
  this.hitBottom = function() {
    var rockbottom = myGameArea.canvas.height - this.height;
    if (this.y > rockbottom) {
      this.y = rockbottom;
    }
  }

خود کا تجربہ کریں

ਤੇਜ਼

ਗੇਮ ਵਿੱਚ ਜਦੋਂ ਇੱਕ ਤਾਕਤ ਚੌਕੇ ਨੂੰ ਨਿਚੋਰ ਲੈ ਜਾਂਦੀ ਹੈ ਤਾਂ ਤੁਸੀਂ ਇੱਕ ਤਰੀਕਾ ਦਾ ਤਿਆਰੀ ਕਰਨਾ ਚਾਹੀਦਾ ਹੈ ਜਿਸ ਵਿੱਚ ਤੁਸੀਂ ਯੰਤਰ ਨੂੰ ਤੇਜ਼ ਕਰਨ ਲਈ ਮਜ਼ਬੂਰ ਕਰੋ:

ਜਦੋਂ ਕੋਈ ਬਟਨ ਨੂੰ ਕਲਿੱਕ ਕਰਦਾ ਹੈ ਤਾਂ ਇੱਕ ਫੰਕਸ਼ਨ ਚਲਾਉਣ ਲਈ ਟ੍ਰਿਗਰ ਹੁੰਦਾ ਹੈ ਜਿਸ ਵਿੱਚ ਲਾਲ ਚੌਕਾ ਹਵਾ ਵਿੱਚ ਚੱਲ ਜਾਵੇ:

مثال

<script>
function accelerate(n) {
  myGamePiece.gravity = n;
}
</script>
<button onmousedown="accelerate(-0.2)" onmouseup="accelerate(0.1)">ਤੇਜ਼</button>

خود کا تجربہ کریں

ایک گیم

ماضی میں سیکھی ہوئی معلومات کا استعمال کرکے ایک گیم بنائیں:

مثال

خود کا تجربہ کریں

پچھلئی بٹن کلک کریں تاکہ شروع ہو جائیں。

کوئی دیر کا نہیں؟ پچھلئی بٹن استعمال کریں تاکہ آسمان میں رہ جائیں。