(function() {"use strict";var __module = CC_EDITOR ? module : {exports:{}};var __filename = 'preview-scripts/assets/script/enemy_js.js';var __require = CC_EDITOR ? function (request) {return cc.require(request, require);} : function (request) {return cc.require(request, __filename);};function __define (exports, require, module) {"use strict";
cc._RF.push(module, 'd5fc9bLf8JI+pJ/KTelJL7+', 'enemy_js', __filename);
// script/enemy_js.js
"use strict";
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_skin: {
default: [],
type: cc.SpriteFrame
},
enemy_bullet_prefab: {
default: null,
type: cc.Prefab
},
player_path: "Canvas/player"
},
// use this for initialization
onLoad: function onLoad() {
this.speed_x = 0;
this.speed_y = -200;
this.anim = this.node.getChildByName("anim");
this.root = cc.find("Canvas");
this.game_scene = cc.find("Canvas").getComponent("game_scene_js");
this.flag = 0;
},
start: function start() {
this._set_enemy_idle();
this.schedule(this.shoot_enemy_bullet.bind(this), 1);
},
_set_enemy_idle: function _set_enemy_idle() {
var skin_type = Math.random() * 9 + 1;
skin_type = Math.floor(skin_type);
if (skin_type >= 10) {
skin_type = 9;
}
this.anim.getComponent(cc.Sprite).spriteFrame = this.enemy_skin[skin_type - 1];
},
shoot_enemy_bullet: function shoot_enemy_bullet() {
//this.node.parent.addChild(bullet);
var enemy_bullet = cc.instantiate(this.enemy_bullet_prefab);
//this.root.addChild(enemy_bullet);
//console.log(this.node.x, this.node.y);
//var w_pos = this.node.convertToWorldSpaceAR(cc.p(0, 0));
//console.log(w_pos.x, w_pos.y, " ------------------- ");
//enemy_bullet.x = w_pos.x;
//enemy_bullet.y = w_pos.y;
this.node.parent.addChild(enemy_bullet);
enemy_bullet.x = this.node.x;
enemy_bullet.y = this.node.y;
},
shoot_enemy_more_bullet: function shoot_enemy_more_bullet() {
if (Math.random() > 0.4) {
return;
}
var enemy_bullets = [];
enemy_bullets[0] = cc.instantiate(this.enemy_bullet_prefab);
enemy_bullets[1] = cc.instantiate(this.enemy_bullet_prefab);
this.node.parent.addChild(enemy_bullets[0]);
this.node.parent.addChild(enemy_bullets[1]);
enemy_bullets[0].x = this.node.x + 15;
enemy_bullets[0].y = this.node.y;
enemy_bullets[0].getComponent("enemy_bullet_js").speed_x = 100;
enemy_bullets[1].x = this.node.x - 15;
enemy_bullets[1].y = this.node.y;
enemy_bullets[1].getComponent("enemy_bullet_js").speed_x = -100;
},
shoot_forever: function shoot_forever() {
this.schedule(this.shoot_enemy_bullet.bind(this), 0.5);
},
onCollisionEnter: function onCollisionEnter(other, self) {
//console.log("other.name = ", other.node.name, other.node.group, other.node.groupIndex);
this.anim.getComponent(cc.Animation).play();
this.scheduleOnce(function () {
this.node.removeFromParent();
}, 0.2);
this.game_scene.add_score();
},
// called every frame, uncomment this function to activate update callback
update: function update(dt) {
var sx = this.speed_x * dt;
var sy = this.speed_y * dt;
this.node.x += sx;
this.node.y += sy;
if (this.flag == 0) {
if (this.game_scene.game_level >= 5) {
this.flag = 1;
this.schedule(this.shoot_enemy_more_bullet.bind(this), 1);
}
}
//console.log(this.node.x, this.node.y);
if (this.node.y < -1000) {
this.node.removeFromParent();
}
}
});
cc._RF.pop();
}
if (CC_EDITOR) {
__define(__module.exports, __require, __module);
}
else {
cc.registerModuleFunc(__filename, function () {
__define(__module.exports, __require, __module);
});
}
})();
//# sourceMappingURL=enemy_js.js.map
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论






收起资源包目录





































































































共 330 条
- 1
- 2
- 3
- 4

嘿呀好气
- 粉丝: 47
- 资源: 2
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


安全验证
文档复制为VIP权益,开通VIP直接复制

- 1
- 2
- 3
前往页