ဂိမ်းဆွဲငင်အား
အချို့ဂိမ်းများတွင် မြေဆွဲအားဆွဲငင်အားကဲ့သို့ ဂိမ်းအစိတ်အပိုင်းကို တစ်နေရာတည်းသို့ ဆွဲငင်နိုင်သော စွမ်းအားများရှိသည်။
ဆွဲငင်အား
ဤလုပ်ဆောင်နိုင်စွမ်းကို ကျွန်ုပ်တို့၏အစိတ်အပိုင်းတည်ဆောက်သူသို့ထည့်ရန် gravity
၊ လက်ရှိဆွဲငင်အားကိုသတ်မှတ်ပေးသည့် ပစ္စည်တစ်ခုကို ဦးစွာထည့်ပါ။ ထို့နောက် gravitySpeed
frame ကို အပ်ဒိတ်လုပ်တိုင်း တိုးလာမည့် ပိုင်ဆိုင်မှုတစ်ခုကို ထည့်ပါ-
ဥပမာ
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)">ACCELERATE</button>
ဂိမ်းတစ်ခု
ယခုအချိန်အထိ ကျွန်ုပ်တို့ သင်ယူခဲ့သည့်အရာအပေါ် အခြေခံ၍ ဂိမ်းတစ်ခု ဖန်တီးပါ-