Öncelikle herkese merhaba,

Cocos2d game engine üzerinden javascript ile basit bir Vacum Cleaner oyunu yapılması gerekiyor. Oyun için proje oluşturuldu sadece yönlendirmelerde if-else lerde sorun yaşıyorum. düzeltebilecek arkadaşlar ile ücretli veya ücretsiz yardım bekliyorum.




proje linki
https://we.tl/t-1DYBFWA2am


// Learn cc.Class:
// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html
// - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html
// Learn Attribute:
// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
// - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
// - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
extends: cc.Component,

properties: {
// maximal movement speed
maxMoveSpeed: 0,
// acceleration
accel: 0,
},

// LIFE-CYCLE CALLBACKS:

// onLoad () {},

start () {

},
onLoad : function(){
// Acceleration direction switch
this.accLeft = false;
this.accRight = false;
this.accUp = false;
this.accDown = false;
// The main character's current horizontal velocity
this.xSpeed = 0;
this.ySpeed = 0;

// Initialize the keyboard input listening
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_LEFT, this.onKeyLeft, this);
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_RIGHT, this.onKeyRight, this);
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP, this.onKeyUp, this);

},
onKeyDown (event) {
// set a flag when key pressed
switch(event.keyCode) {
case cc.macro.KEY.a:
this.accLeft = true;
break;
case cc.macro.KEY.d:
this.accRight = true;
break;

case cc.macro.KEY.w:
this.accUp = true;
break;
case cc.macro.KEY.s:
this.accDown = true;
break;
}
},

onKeyUp (event) {
// unset a flag when key released
switch(event.keyCode) {
case cc.macro.KEY.a:
this.accLeft = true;
break;
case cc.macro.KEY.d:
this.accRight = true;
break;
case cc.macro.KEY.w:
this.accUp = true;
break;
case cc.macro.KEY.s:
this.accDown = true;
break;
}
},
onKeyRight (event) {
// set a flag when key pressed
switch(event.keyCode) {
case cc.macro.KEY.a:
this.accLeft = true;
break;
case cc.macro.KEY.d:
this.accRight = true;
break;
case cc.macro.KEY.w:
this.accUp = true;
break;
case cc.macro.KEY.s:
this.accDown = true;
break;

}
},
onKeyLeft (event) {
// set a flag when key pressed
switch(event.keyCode) {
case cc.macro.KEY.a:
this.accLeft = true;
break;
case cc.macro.KEY.d:
this.accRight = true;
break;
case cc.macro.KEY.w:
this.accUp = true;
break;
case cc.macro.KEY.s:
this.accDown = true;
break;
}
},

update (dt) {
if (this.accLeft) {
this.xSpeed -= this.accel * dt;
}else if (this.accRight) {
this.xSpeed += this.accel * dt;
}else if (this.accUp) {
this.ySpeed -= this.accel * dt;
}else if (this.accDown) {
this.ySpeed += this.accel * dt;
}
if ( Math.abs(this.xSpeed) >= this.maxMoveSpeed ) {
// if speed reach limit, use max speed with current direction
this.xSpeed = this.maxMoveSpeed * this.xSpeed / Math.abs(this.xSpeed);
}
if ( Math.abs(this.ySpeed) >= this.maxMoveSpeed ) {
// if speed reach limit, use max speed with current direction
this.ySpeed = this.maxMoveSpeed * this.ySpeed / Math.abs(this.ySpeed);
}
// restrict the movement speed of the main character to the maximum movement speed

// update the position of the main character according to the current speed
this.node.x += this.xSpeed * dt;
this.node.y -= this.ySpeed * dt;
},

onDestroy () {
// Cancel keyboard input monitoring
cc.systemEvent.off(cc.SystemEvent.EventType.KEY_LEFT, this.onKeyLeft, this);
cc.systemEvent.off(cc.SystemEvent.EventType.KEY_RIGHT, this.onKeyRight, this);
cc.systemEvent.off(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
cc.systemEvent.off(cc.SystemEvent.EventType.KEY_UP, this.onKeyUp, this);
},
});