var sound_manager = require("sound_manager");
var ugame = require("ugame");
cc.Class({
extends: cc.Component,
properties: {
// foo: {
// default: null, // The default value will be used only when the component attaching
// to a node for the first time
// url: cc.Texture2D, // optional, default is typeof default
// serializable: true, // optional, default is true
// visible: true, // optional, default is true
// displayName: 'Foo', // optional
// readonly: false, // optional, default is false
// },
// ...
enemy_prefabs: {
default: [],
type: cc.Prefab,
},
game_map_set: {
default: [],
type: cc.Prefab,
},
},
// use this for initialization
onLoad: function () {
// 以后随机播放背景音乐;
sound_manager.play_music("resources/sounds/music/game_bg1.mp3", true);
// end
this.door = cc.find("UI_ROOT/loading_door").getComponent("loading_door");
this.go_back = false;
this.pause_root = cc.find("UI_ROOT/anchor-center/pause_root");
this.pause_root.active = false;
this.setting_root = cc.find("UI_ROOT/anchor-center/setting_root");
this.setting_root.active = false;
this.blood_label = cc.find("UI_ROOT/anchor-lt/ugame_root/blood_label").getComponent(cc.Label);
this.uchip_label = cc.find("UI_ROOT/anchor-lt/ugame_root/uchip_label").getComponent(cc.Label);
this.round_label = cc.find("UI_ROOT/anchor-lt/ugame_root/round_label").getComponent(cc.Label);
this.blood = 0;
this.game_started = false;
ugame.is_game_paused = false;
this.map_root = cc.find("UI_ROOT/map_root");
this.checkout = cc.find("UI_ROOT/checkout").getComponent("checkout");
// this.game_map = cc.find("UI_ROOT/level1_map");
var map_level = ugame.get_cur_level();
// this.game_map = cc.find("UI_ROOT/level1_map");
if (map_level >= this.game_map_set.length) {
map_level = this.game_map_set.length - 1;
}
this.game_map = cc.instantiate(this.game_map_set[map_level]);
this.node.addChild(this.game_map);
// this.game_map.setLocalZOrder(-100);
this.game_map.zIndex = -100;
this.map_tag_root = this.game_map.getChildByName("tag_root");
},
start_game: function() {
if (this.game_started === true) {
return;
}
this.all_enemy_gen = false;
// 删除掉集合里面所有的敌人
ugame.clear_ememy_set();
// end
// 取消掉所有的定时器
this.unscheduleAllCallbacks();
// end
// 取消掉所有的塔
for(var i = 0; i < this.map_tag_root.children.length; i ++) {
var tower_builder = this.map_tag_root.children[i].getComponent("tower_builder");
tower_builder.remove_builder_tower();
}
// end
// map_root
this.map_root.removeAllChildren();
// end
this.game_started = true;
ugame.is_game_started = true;
this.checkout.node.active = false;
var cur_user = ugame.get_cur_user();
this.blood = cur_user.blood;
// this.blood = 1;
// 同步我们的金币和血,当前第几波敌人
this.blood_label.string = "" + this.blood;
this.uchip_label.string = "" + ugame.get_uchip();
this.round_label.string = "round 0 / 7";
// end
// 生成我们的第一个波怪物
this.map_level = ugame.get_cur_level();
var map_level = this.map_level;
if (map_level >= this.game_map_set.length) {
map_level = this.game_map_set.length - 1;
}
console.log("map_level #####", map_level, this.map_level);
this.level_data = require("level" + (map_level + 1));
// this.level_data = require("level1");
this.round_label.string = "round 0 / " + this.level_data.length;
this.cur_round = 0; // 当前要产生的是第几波敌人
this.cur_road_index = 0; // 在非随机模式下,当前的选择路径的索引
this.cur_gen_total = 0; // 当前这波产生的总数
this.cur_gen_now = 0; // 当前已经放出的怪物数量
this.gen_round_enemy();
// end
},
show_game_uchip: function() {
this.uchip_label.string = "" + ugame.get_uchip();
},
// 打开这个门;
start: function() {
this.start_game();
this.door.open_the_door(null);
},
// 显示失败的画面
show_game_failed: function() {
this.checkout.show_failed();
},
on_player_attacked: function(hurt) {
if (this.game_started === false) {
return;
}
this.blood -= hurt;
if (this.blood <= 0) {
this.blood = 0;
// 游戏失败结束
this.game_started = false;
ugame.is_game_started = false;
this.show_game_failed();
}
this.blood_label.string = "" + this.blood; // 更新当前的血量
},
gen_one_enemy: function() {
if (this.game_started === false) {
return;
}
if (ugame.is_game_paused) {
this.scheduleOnce(this.gen_one_enemy.bind(this), this.cur_schedule_time);
return;
}
var cur_round_params = this.level_data[this.cur_round];
var type = cur_round_params.type[this.cur_gen_now];
var road_set = cur_round_params.road_set;
var map_road_set = ugame.get_map_road_set();
var enemy = cc.instantiate(this.enemy_prefabs[type]);
enemy.active = true;
this.map_root.addChild(enemy);
ugame.add_ememy(enemy);
var actor = enemy.getComponent("actor");
var index = 0; // 跑的地图路径的索引
if (cur_round_params.random_road) {
var random_index = Math.random() * road_set.length; // [0, road_set.length]
random_index = Math.floor(random_index);
if (random_index >= road_set.length) {
random_index = road_set.length - 1;
}
index = road_set[random_index];
}
else {
index = this.cur_road_index;
this.cur_road_index ++;
if (this.cur_road_index > road_set.length) {
this.cur_road_index = 0;
}
index = road_set[index];
}
if (index >= map_road_set.length) {
index = 0;
}
var road_data = map_road_set[index];
actor.set_actor_params(cur_round_params.actor_params);
actor.gen_at_road(road_data);
if (this.cur_gen_now === 0) {
this.round_label.string = "round " + (this.cur_round + 1) + " / " + this.level_data.length;
}
this.cur_gen_now ++;
if (this.cur_gen_now == this.cur_gen_total) { // 放下一波敌人
this.cur_round ++;
this.gen_round_enemy();
}
else {
var time = cur_round_params.gen_time_set[this.cur_gen_now];
this.cur_schedule_time = time;
this.scheduleOnce(this.gen_one_enemy.bind(this), time);
}
},
think_level_pass: function() {
if (this.game_started === false ||
this.all_enemy_gen === false ||
ugame.ememy_se
没有合适的资源?快使用搜索试试~ 我知道了~
王国保卫战.zip源码cocos creator项目源码下载
共1932个文件
meta:1015个
png:825个
js:40个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 5 下载量 194 浏览量
2022-03-18
10:55:42
上传
评论 2
收藏 6.59MB ZIP 举报
温馨提示
王国保卫战.zip源码cocos creator项目源码下载王国保卫战.zip源码cocos creator项目源码下载 1.上线产品适合个人学习技术做项目参考 2.开发脚本为javsScropt或者typeScript 3.上线产品适合小公司开发游戏项目参考
资源推荐
资源详情
资源评论
收起资源包目录
王国保卫战.zip源码cocos creator项目源码下载 (1932个子文件)
map_level2.anim 9KB
map_level1.anim 5KB
map_level3.anim 4KB
home_scene_start_anim.anim 3KB
reserve_start_button_click_anim.anim 2KB
start_button_click_anim.anim 2KB
reserve_road_skill_upgrade_config.anim 1KB
road_skill_upgrade_config.anim 1KB
reserve_uinfo_enter_anim.anim 752B
uinfo_enter_anim.anim 743B
home_scene.fire 1.32MB
roadmap_scene.fire 435KB
game_scene.fire 299KB
abount_scene.fire 12KB
game_scene.js 11KB
actor.js 10KB
arrow_tower.js 7KB
upgrade_config.js 7KB
warlock_tower.js 7KB
cannon_tower.js 7KB
tower_builder.js 6KB
gen_map_path.js 6KB
roadmap_scene.js 6KB
home_scene.js 6KB
ugame.js 6KB
level2.js 5KB
level1.js 5KB
level3.js 5KB
cannon_bullet.js 5KB
arrow_bullet.js 5KB
infantry_actor.js 5KB
frame_anim.js 4KB
warlock_bullet.js 4KB
infantry_tower.js 4KB
loading_door.js 3KB
sound_manager.js 3KB
checkout.js 3KB
audio_swich.js 3KB
gui_tower_builder.js 3KB
abount_scene.js 2KB
websocket.js 2KB
level_entry_info.js 2KB
zsort_node.js 1KB
httpc.js 629B
cannon_bullet_params.js 576B
infantry_actor_params.js 458B
cannon_tower_params.js 438B
arrow_tower_params.js 436B
warlock_bullet_params.js 401B
arrow_bullet_params.js 401B
infantry_tower_params.js 342B
warlock_tower_params.js 340B
utils.js 325B
Enemy.js 155B
services.json 12KB
project.json 1KB
builder.json 877B
jsconfig.json 219B
project.json 60B
options_overlay_buttons_0004.png.meta 729B
options_overlay_buttons_0003.png.meta 728B
options_overlay_buttons_0002.png.meta 726B
options_overlay_buttons_0001.png.meta 726B
encyclopedia_over.png.meta 721B
actor0_attack_1.png.meta 721B
encyclopedia_down.png.meta 720B
encyclopedia_up.png.meta 720B
actor0_attack_9.png.meta 720B
passed_entry_icon.png.meta 719B
actor0_attack_0.png.meta 719B
actor0_attack_2.png.meta 719B
actor0_dead_9.png.meta 719B
a3_attack_09.png.meta 719B
a3_attack_12.png.meta 719B
a3_attack_11.png.meta 719B
tower_builder.png.meta 719B
actor0_attack_10.png.meta 718B
actor0_attack_8.png.meta 718B
actor0_attack_4.png.meta 718B
a3_dead_13.png.meta 718B
a5_attack_00.png.meta 718B
a5_attack_07.png.meta 718B
a5_attack_01.png.meta 718B
actor_attack_1_04.png.meta 718B
actor_attack_1_05.png.meta 718B
actor_attack_1_06.png.meta 718B
arrow_idle_down.png.meta 718B
chengjiu_over.png.meta 717B
actor0_attack_6.png.meta 717B
actor0_attack_3.png.meta 717B
actor0_dead_1.png.meta 717B
actor0_dead_0.png.meta 717B
actor0_dead_5.png.meta 717B
actor0_dead_7.png.meta 717B
actor0_dead_8.png.meta 717B
actor0_dead_6.png.meta 717B
a3_attack_00.png.meta 717B
a3_attack_01.png.meta 717B
a5_attack_08.png.meta 717B
actor1_dead_01.png.meta 717B
共 1932 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
- weixin_354388812023-08-10发现一个宝藏资源,资源有很高的参考价值,赶紧学起来~
- MajorChen6382022-05-29用户下载后在一定时间内未进行评价,系统默认好评。
- qq_312885432022-11-23资源很好用,有较大的参考价值,资源不错,支持一下。
- qiangzi1152023-02-24感谢资源主的分享,这个资源对我来说很有用,内容描述详尽,值得借鉴。
- 2201_758864862023-03-22这个资源内容超赞,对我来说很有价值,很实用,感谢大佬分享~
yxkfw
- 粉丝: 76
- 资源: 2万+
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功