Skip to content

Commit

Permalink
增加AI,优化移动效果。
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoyuexing committed Sep 28, 2018
1 parent 7beef13 commit 8a7bd86
Show file tree
Hide file tree
Showing 16 changed files with 402 additions and 24,524 deletions.
6 changes: 3 additions & 3 deletions client/assets/resources/prefab/player.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"r": 0,
"g": 0,
"b": 0,
"a": 255
},
"_cascadeOpacityEnabled": true,
Expand Down
2 changes: 1 addition & 1 deletion client/assets/scenes/cover.fire
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@
},
"_contentSize": {
"__type__": "cc.Size",
"width": 166,
"width": 160,
"height": 45
},
"_rotationX": 0,
Expand Down
21 changes: 15 additions & 6 deletions client/assets/scenes/game.fire
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_isTrimmedMode": false,
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_atlas": null
Expand Down Expand Up @@ -361,9 +361,9 @@
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"r": 0,
"g": 0,
"b": 0,
"a": 255
},
"_cascadeOpacityEnabled": true,
Expand Down Expand Up @@ -468,7 +468,10 @@
"userName": {
"__id__": 8
},
"sendInterval": 0
"sendInterval": 0,
"robotMoveToDistance": 10,
"robotMoveDistance": 12,
"robotMoveSyncTime": 0
},
{
"__type__": "cc.Sprite",
Expand Down Expand Up @@ -1721,7 +1724,13 @@
"_enabled": true,
"dot": {
"__id__": 47
}
},
"left_Down": false,
"right_Down": false,
"up_Down": false,
"down_Down": false,
"posY": 0,
"posX": 0
},
{
"__type__": "cc.Node",
Expand Down
11 changes: 6 additions & 5 deletions client/assets/scenes/lobby.fire
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@
},
"_contentSize": {
"__type__": "cc.Size",
"width": 56,
"width": 58,
"height": 56
},
"_rotationX": 0,
Expand Down Expand Up @@ -1484,7 +1484,7 @@
},
"_contentSize": {
"__type__": "cc.Size",
"width": 112,
"width": 114,
"height": 64
},
"_rotationX": 0,
Expand Down Expand Up @@ -1894,7 +1894,7 @@
},
"_contentSize": {
"__type__": "cc.Size",
"width": 196,
"width": 198,
"height": 64
},
"_rotationX": 0,
Expand Down Expand Up @@ -2148,7 +2148,7 @@
},
"_contentSize": {
"__type__": "cc.Size",
"width": 196,
"width": 198,
"height": 64
},
"_rotationX": 0,
Expand Down Expand Up @@ -7734,7 +7734,8 @@
"node": {
"__id__": 2
},
"_enabled": true
"_enabled": true,
"getRoomDetailTimer": null
},
{
"__type__": "cc.Node",
Expand Down
29 changes: 26 additions & 3 deletions client/assets/scripts/Cover/Cover.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,22 @@ let GameData = require('../Global/GameData');
cc.Class({
extends: cc.Component,


onLoad() {
cc.director.setDisplayStats(false);
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN,this.onKeyDown,this);
LocalStore_Clear();

this.mvsBind();

// 断线之后需要重新init
// if (GameData.initStatus !== 6) {
this.isCoverHide = false
this.init();
if (GameData.isPremiseInit) {
this.premiseInit();
} else {
this.init();
}
// }
},

Expand Down Expand Up @@ -63,6 +69,14 @@ cc.Class({
this.mvsInit(response, channel, platform, gameId);
},

premiseInit() {
var endport = "172.25.119.77";
var gameID = 201226 ;
let response = Mvs.response;
var result = Mvs.engine.premiseInit(response, endport, gameID);
console.log("独立部署初始化返回值"+result);
},

mvsInit(response, channel, platform, gameId) {
let result = Mvs.engine.init(response, channel, platform, gameId);

Expand All @@ -80,7 +94,7 @@ cc.Class({
},

mvsInitResponse(status) {
if (status === 200) {
if (status == 200) {
GameData.initStatus = 6;
console.log('response init ok', status);
} else {
Expand Down Expand Up @@ -133,5 +147,14 @@ cc.Class({
} else {
console.warn('please wait matchvs init');
}
},

onKeyDown:function(event) {
console.warn('keyCode',event.keyCode);
switch (event.keyCode) {
case 1005:
this.play();
break;
}
}
});
});
75 changes: 72 additions & 3 deletions client/assets/scripts/Game/Control/Joystick.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ cc.Class({

properties: {
dot: cc.Node,
left_Down:false,
right_Down:false,
up_Down:false,
down_Down:false, //四个方向键是否被按下的状态
posY : 0,
posX: 0
},

onLoad() {
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN,this.onKeyDown,this);
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP, this.onKeyUp, this);
this.ringRadius = this.node.width / 2;

// this.joyStickPoint = this.node.getPosition();
//操纵杆X坐标
this.joyStickX = this.node.getPosition().x;
Expand All @@ -26,6 +33,68 @@ cc.Class({
this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchCancelEventHandle, this);
},

onKeyDown(event) {
switch (event.keyCode) {
case 1003:
this.up_Down = true;
break;
case 1004:
this.down_Down = true;
break;
case 1000:
this.left_Down = true;
break;
case 1001:
this.right_Down = true;
break;
}
this.gamepad();
},

onKeyUp(event) {
switch (event.keyCode) {
case 1003:
this.up_Down = false;
break;
case 1004:
this.down_Down = false;
break;
case 1000:
this.left_Down = false;
break;
case 1001:
this.right_Down = false;
break;
}
this.gamepad();
},


gamepad() {
this.posX = this.joyStickX;
this.posY = this.joyStickY;
if(!this.up_Down&&!this.down_Down&&!this.left_Down&&!this.right_Down) {
this.touchEndEventHandle();
return;
}
if (this.right_Down) {
this.posX = this.joyStickX + (this.ringRadius/2);
}
if (this.up_Down) {
this.posY = this.joyStickY + (this.ringRadius/2);
}
if (this.down_Down) {
this.posY = this.joyStickY - (this.ringRadius/2);
}
if (this.left_Down) {
this.posX = this.joyStickX - (this.ringRadius/2);
}
this.dot.setPosition(cc.p(this.posX, this.posY));
GameData.angle = this.getAngle(cc.p(this.posX, this.posY));
GameData.speed1 = 180;
},


touchStartEventHandle(event) {
if (GameData.isServerErrorCode1000) {
return;
Expand Down Expand Up @@ -69,14 +138,14 @@ cc.Class({
GameData.speed1 = 180;
},

touchEndEventHandle() {
touchEndEventHandle: function () {
if (GameData.isServerErrorCode1000) {
return;
}

this.dot.setPosition(this.node.getPosition());

GameData.angle = 0;
GameData.angle = null;
GameData.speed1 = 0;
},

Expand Down
3 changes: 3 additions & 0 deletions client/assets/scripts/Game/Control/Speed.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ cc.Class({
this.node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMoveEventHandle, this);
this.node.on(cc.Node.EventType.TOUCH_END, this.touchEndEventHandle, this);
this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchCancelEventHandle, this);
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN,this.onKeyDown,this);
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP, this.onKeyUp, this);
},


initOnEvent() {
cc.director.GlobalEvent.off('playerNoGold').on('playerNoGold', (data) => {
this.canSpeedUp = false;
Expand Down
65 changes: 54 additions & 11 deletions client/assets/scripts/Game/Food/Food.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ cc.Class({
}

// 别的玩家碰撞了食物, 这里不处理
if (!(other && other.node && other.node.userId && other.node.userId === Const.userId)) {
if (!(other && other.node && other.node.userId && (other.node.userId === Const.userId || other.node.userId === GameData.robotIDs[0] || other.node.userId === GameData.robotIDs[1]))) {
return;
}

Expand All @@ -27,20 +27,63 @@ cc.Class({
// other tag 1
// food tag 999
if (other.tag === 1 && self.tag === 999) {
if (other.node.isInvin) {
return;
if (!other.node.isInvin) {
let data = {
food: self.node,
score: self.node.score,
foodId: self.node.foodId,
userId: other.node.userId,
userScore: GameData.players[0].score,
};

for(var i = 0; i < GameData.players.length;i++) {
if (data.userId == GameData.players[i].userId) {
data.userScore = GameData.players[i].score;
}
}
console.log("userID : userScore :", data.userId+":"+data.userScore);
cc.director.GlobalEvent.emit('playerEatAFood', data);
}

let data = {
food: self.node,
score: self.node.score,
foodId: self.node.foodId,
userId: other.node.userId,
if (other.node.userId === GameData.robotIDs[0]) {
self.node.userId = other.node.userId;

this.robotVolume(self.node,1);
}
if (other.node.userId === GameData.robotIDs[1]) {
self.node.userId = other.node.userId;
this.robotVolume(self.node,2);
}

userScore: GameData.players[0].score,
};

cc.director.GlobalEvent.emit('playerEatAFood', data);
}
},

/**
* 计算机器人的
* @param data
* @param i
*/
robotVolume (data,i) {
let score = data.score ,addWidth = score / 30
, lastWidth = GameData.players[i].lastWidth
, scaleAdd = (lastWidth + addWidth) / lastWidth;

var scale = Number( GameData.players[i].scale * scaleAdd).toFixed(2);
GameData.players[i].lastScale = scale; // 上一次应该放大的值
GameData.players[i].scale = scale; // 上一次应该放大的值
GameData.players[i].lastWidth = lastWidth + addWidth;

// var otherScript = cc.find('Canvas/bg').getComponent('Other');
// console.log("AI 吃score1", GameData.players[i].score);
// otherScript.otherAddSize(data.userId, GameData.players[i].score, index, other);
let _data = {
userId: data.userId,
scale: scale,
index:i,
lastWidth: GameData.players[i].lastWidth
};
cc.director.GlobalEvent.emit('otherChangeSize', _data)
}

});
Loading

0 comments on commit 8a7bd86

Please sign in to comment.