(function() {
var nodeEnv = typeof require !== 'undefined' && typeof process !== 'undefined';
var __module = nodeEnv ? module : {exports:{}};
var __filename = 'preview-scripts/assets/script/game.js';
var __require = nodeEnv ? function (request) {
return cc.require(request);
} : function (request) {
return __quick_compile_project__.require(request, __filename);
};
function __define (exports, require, module) {
if (!nodeEnv) {__quick_compile_project__.registerModule(__filename, module);}"use strict";
cc._RF.push(module, '84b0eutjxlBXKT3048Yr0hC', 'game');
// script/game.js
"use strict";
cc.Class({
"extends": cc.Component,
properties: {
//将脚本和line、clickLayer关联
line: cc.Node,
clickLayer: cc.Node,
starLayer: cc.Node,
preStar: cc.Prefab,
monsterLayer: cc.Node,
preMonster: cc.Prefab
},
loadRes: function loadRes() {
var _this = this;
//将资源加载到一个icon列表之中
// cc.loader.loadRes(
// 路径
// 类型
// 回调
// );
//cc.log("ok");
this.clip = {};
var clipNum = 0;
var lst = ["bg1", "bg2"];
var _loop2 = function _loop2() {
var name = _lst[_i];
clipNum++;
cc.loader.loadRes("audio/" + name, //只写"resources"下级路径
cc.AudioClip, function (err, data) {
if (err) {
cc.log(err);
return;
}
_this.clip[name] = data;
clipNum--; //cc.log(clipNum);
if (!clipNum) {
//cc.log(this.icon);
cc.log(_this.clip["bg1"]);
cc.audioEngine.playMusic(_this.clip["bg1"]);
}
});
};
for (var _i = 0, _lst = lst; _i < _lst.length; _i++) {
_loop2();
}
this.icon = {};
var num = 0;
var _loop = function _loop(i) {
num++;
cc.loader.loadRes("texture/icon/" + i, //只写"resources"下级路径
cc.SpriteFrame, function (err, data) {
if (err) {
cc.log(err);
return;
}
_this.icon[i] = data;
num--;
if (!num) {
//cc.log(this.icon);
_this.createMonster();
}
});
};
for (var i = 1000; i <= 1037; ++i) {
_loop(i);
}
},
addStar: function addStar() {
this.starNum++;
},
addScore: function addScore(score) {
this.score += score;
this.lbScore.string = this.score;
},
delStar: function delStar() {
this.tempStarNum--;
if (this.tempStarNum <= 0) {
this.createMonster();
}
},
createMonster: function createMonster() {
var _this2 = this;
var cnt = Math.floor(Math.random() * 6) + 3; //每次生成的怪物的数量
//cc.log(cnt);
var arr = [];
for (var i = 0; i < 8; ++i) {
arr.push(i);
} //cc.log(arr);
arr.sort(function () {
return 0.5 - Math.random();
});
for (var _i2 = 0; _i2 < cnt; ++_i2) {
var monster = cc.instantiate(this.preMonster);
this.monsterLayer.addChild(monster);
monster.x += arr.pop() * 77.5;
monster.game = this;
var iconId = Math.floor(Math.random() * 37) + 1001; // hp = int(1~3) + floor( floor(star*0.5 + score*0.1) * (0.6~1.4) )
var hp = Math.floor(Math.random() * 3) + 1 + Math.floor(Math.floor(this.starNum * 0.5 + this.score * 0.1) * (Math.random() * 0.8 + 0.6)); // 20%变成星星怪
var ratio = Math.random();
if (ratio < 0.2) {
iconId = 1000;
hp = -1;
}
monster.script.initMonster(this.icon[iconId], hp);
}
var flag = true; //true-没有怪物进攻 false-有怪物进攻
var num = 0; //统计下移动画播完
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
var _loop3 = function _loop3() {
var child = _step.value;
num++;
child.runAction(cc.sequence(cc.moveBy(0.5, 0, -77.5), cc.callFunc(function () {
if (child.y <= -400) {
//满足进攻条件
flag = false;
child.runAction(cc.sequence(cc.moveBy(0.3, 0, -500), cc.callFunc(function () {
//cc.log(child, child.script);
_this2.hurtByMonster(child.script);
child.destroy();
})));
}
num--; //播完下移--
if (num == 0) {
if (flag) {
_this2.touchLock = false;
} else {
setTimeout(function () {
_this2.touchLock = false;
}, 300);
}
}
})));
};
for (var _iterator = this.monsterLayer.children[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
_loop3();
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator["return"] != null) {
_iterator["return"]();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
},
hurtByMonster: function hurtByMonster(monster) {
if (this.hp <= 0) {
return;
}
this.hp -= monster.getAttack();
this.lbHp.string = this.hp;
if (this.hp <= 0) {
this.gameOver();
}
},
gameOver: function gameOver() {
this.monsterLayer.removeAllChildren();
this.tempStarNum = 0;
this.touchLock = true;
this.hp = 100;
this.lbHp.string = this.hp;
this.score = 0;
this.lbScore.string = this.score;
this.starNum = 1;
this.lbStar.string = this.starNum;
this.createMonster();
},
doLaunch: function doLaunch(cnt) {
var _this3 = this;
var star = cc.instantiate(this.preStar);
this.starLayer.addChild(star);
star.game = this;
star.x = this.line.x;
star.y = this.line.y;
var rb = star.getComponent(cc.RigidBody);
var power = 1000;
var angle = -this.line.angle;
var x = Math.sin(angle * Math.PI / 180) * power;
var y = Math.cos(angle * Math.PI / 180) * power;
rb.linearVelocity = cc.v2(x, y); //设置初始线速度
cnt--;
if (cnt > 0) {
setTimeout(function () {
_this3.doLaunch(cnt);
}, 200);
}
},
launch: function launch() {
this.touchLock = true;
this.tempStarNum = this.starNum;
this.doLaunch(this.starNum);
},
syncLine: function syncLine(e) {
//改变发射线倾斜角
var pos = e.getLocation(); //获取点的位置对象
pos = this.line.parent.convertToNodeSpaceAR(pos); //转化成局部坐标
//cc.log(pos.x, pos.y);
var x = pos.x - this.line.x;
var y = pos.y - this.line.y;
var ang = -Math.atan(x / y) * 180 / Math.PI; //* 180 / Math.PI 弧度转成角度
if (y < 0) {
ang += 180;
}
this.line.angle = ang; //angle是内置的,不能改
},
onTouchStart: function onTouchStart(e) {
if (this.touchLock) {
return;
}
this.line.active = true;
this.syncLine(e);
},
onTouchMove: function onTouchMove(e) {
if (this.touchLock) {
return;
}
this.syncLine(e);
},
onTouchEnd: function onTouchEnd(e) {
if (this.touchLock) {
return;
}
this.line.active = false;
this.launch();
this.createMonster();
},
//LIFE CYCLE FUNCTION:
onLoad: function onLoad() {
var mgr = cc.director.getPhysicsManager();
mgr.enabled = true; //开启物理引擎
mgr.gravity = cc.v2(0, 0); //初始时在真空环境下,不受重力影响
},
start: function start() {
var _this4 = this;
this.touchLock = true;
this.tempStarNum = 0;
this.starNum = 1;
this.hp = 100;
this.score = 0;
this.lbHp = cc.find("Canvas/lbHp").getC
没有合适的资源?快使用搜索试试~ 我知道了~
tanyitantanyitan
共617个文件
json:275个
png:142个
meta:100个
需积分: 0 0 下载量 68 浏览量
2024-05-14
09:36:56
上传
评论
收藏 12.62MB ZIP 举报
温馨提示
tanyitan
资源推荐
资源详情
资源评论
收起资源包目录
tanyitantanyitan (617个子文件)
a579b610-0aa7-4a8b-b36b-be34cc834dcc.bin 157KB
buffer.bin 157KB
83f5eff8-3385-4f95-9b76-8da0aa1d96cd.bin 48KB
14c74869-bdb4-4f57-86d8-a7875de2be30.bin 46KB
3bbdb0f6-c5f6-45de-9f33-8b5cbafb4d6d.bin 46KB
b430cea3-6ab3-4106-b073-26c698918edd.bin 7KB
a1ef2fc9-9c57-418a-8f69-6bed9a7a0e7f.bin 5KB
7a17de6e-227a-46b1-8009-e7157d4d3acf.bin 4KB
046f172c-1574-488b-bbb8-6415a9adb96d.bin 840B
e93d3fa9-8c21-4375-8a21-14ba84066c77.bin 140B
game.fire 34KB
game.fire 34KB
font.fnt 4KB
.gitignore 1KB
6074a6ad53cbcc2e6ca55b2d34bec468.gltf 19KB
game.js 33KB
game.js 8KB
84b0ebad-8f19-415c-a4f7-d38f18af4842.js 8KB
game.js 8KB
monster.js 6KB
__quick_compile__.js 5KB
star.js 4KB
rank.js 2KB
__qc_index__.js 1KB
monster.js 1KB
0db4ad0f-b3cd-4644-93b8-764dd1d14a96.js 1KB
monster.js 1KB
4640d123-79da-4047-a3c8-89e212016e48.js 582B
star.js 582B
star.js 538B
9506d0d7-9d54-46ad-8e9a-5c8c0e733ae2.js 273B
rank.js 273B
rank.js 191B
__qc_index__.js 136B
829a282c-b049-4019-bd38-5ace8d8a6417.json 87KB
e2f00085-c597-422d-9759-52c360279106.json 51KB
abc2cb62-7852-4525-a90d-d474487b88f2.json 51KB
70bbeb73-6dc2-4ee4-8faf-76b3a0e34ec4.json 35KB
ef1c55e7-04b3-4b15-a26f-1e9b99663564.json 34KB
uuid-to-mtime.json 30KB
2a7c0036-e0b3-4fe1-8998-89a54b8a2bec.json 27KB
d1b8be49-b0a0-435c-83b7-552bed4bbe35.json 20KB
bf0a434c-84dd-4a8e-a08a-7a36f180cc75.json 20KB
6d91e591-4ce0-465c-809f-610ec95019c6.json 19KB
ab2fdde9-10c2-44e4-bfe1-fcfcc1a86aa9.json 15KB
ca8401fe-ad6e-41a8-bd46-8e3e4e9945be.json 14KB
115286d1-2e10-49ee-aab4-341583f607e8.json 14KB
32044bd2-481f-4cf1-a656-e2b2fb1594eb.json 12KB
61aeb05b-3b32-452b-8eed-2b76deeed554.json 9KB
ed88f13d-fcad-4848-aa35-65a2cb973584.json 9KB
9fec6172-af39-432e-be65-2553710f84d9.json 8KB
972b9a4d-47ee-4c74-b5c3-61d8a69bc29f.json 7KB
59b2edff-cb3f-44d3-b6d5-51a4a1631ee5.json 7KB
430eccbf-bf2c-4e6e-8c0c-884bbb487f32.json 7KB
0004d1cf-a0ad-47d8-ab17-34d3db9d35a3.json 7KB
0d784963-d024-4ea6-a7db-03be0ad63010.json 6KB
0e93aeaa-0b53-4e40-b8e0-6268b4e07bd7.json 6KB
2874f8dd-416c-4440-81b7-555975426e93.json 5KB
5965ffac-69da-4b55-bcde-9225d0613c28.json 4KB
6c5cf6e1-b044-4eac-9431-835644d57381.json 3KB
b3780f4b-31fc-40cc-b43c-eb9ebe5e8e23.json 3KB
cd33edea-55f5-46c2-958d-357a01384a36.json 3KB
144c3297-af63-49e8-b8ef-1cfa29b3be28.json 3KB
954fec8b-cd16-4bb9-a3b7-7719660e7558.json 3KB
785a442c-3ceb-45be-a46e-7317f625f3b9.json 3KB
layout.editor.json 3KB
2c937608-2562-40ea-b264-7395df6f0cea.json 2KB
897ef7a1-4860-4f64-968d-f5924b18668a.json 2KB
70d7cdb0-04cd-41bb-9480-c06a4785f386.json 2KB
ddb99b39-7004-47cd-9705-751905c43c46.json 2KB
61906da3-7003-4bda-9abc-5769c76faee4.json 2KB
0cf30284-9073-46bc-9eba-e62b69dbbff3.json 2KB
f5331fd2-bf42-4ee3-a3fd-3e1657600eff.json 2KB
1f55e3be-b89b-4b79-88de-47fd31018044.json 2KB
96083d03-c332-4a3f-9386-d03e2d19e8ee.json 2KB
b5fc2cf2-7942-483d-be1f-bbeadc4714ad.json 2KB
232d2782-c4bd-4bb4-9e01-909f03d6d3b9.json 2KB
1c5e4038-953a-44c2-b620-0bbfc6170477.json 2KB
fe1417b6-fe6b-46a4-ae7c-9fd331f33a2a.json 2KB
2d9a4b85-b0ab-4c46-84c5-18f393ab2058.json 2KB
3f376125-a699-40ca-ad05-04d662eaa1f2.json 2KB
de510076-056b-484f-b94c-83bef217d0e1.json 2KB
6c9ef10d-b479-420b-bfe6-39cdda6a8ae0.json 2KB
a87cc147-01b2-43f8-8e42-a7ca90b0c757.json 2KB
4a37dd57-78cd-4cec-aad4-f11a73d12b63.json 2KB
27756ebb-3d33-44b0-9b96-e858fadd4dd4.json 2KB
8c5001fd-07ee-4a4b-a8a0-63e15195e94d.json 2KB
0e42ba95-1fa1-46aa-b2cf-143cd1bcee2c.json 2KB
7de03a80-4457-438d-95a7-3e7cdffd6086.json 2KB
14c74869-bdb4-4f57-86d8-a7875de2be30.json 1KB
7a17de6e-227a-46b1-8009-e7157d4d3acf.json 1KB
3bbdb0f6-c5f6-45de-9f33-8b5cbafb4d6d.json 1KB
83f5eff8-3385-4f95-9b76-8da0aa1d96cd.json 1KB
046f172c-1574-488b-bbb8-6415a9adb96d.json 1KB
b430cea3-6ab3-4106-b073-26c698918edd.json 1KB
e93d3fa9-8c21-4375-8a21-14ba84066c77.json 1KB
a1ef2fc9-9c57-418a-8f69-6bed9a7a0e7f.json 1KB
c0040c95-c57f-49cd-9cbc-12316b73d0d4.json 1KB
settings.json 1KB
432fa09c-cf03-4cff-a186-982604408a07.json 864B
共 617 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
Brightess
- 粉丝: 1298
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功