Commit a090e283 authored by 智慧's avatar 智慧

feat:子弹碰撞敌人,销毁敌人并且销毁自己

parent 33d31985
import EnemyControl from "./enemyControl";
const {ccclass, property} = cc._decorator;
@ccclass
export default class BulletControl extends cc.Component {
@property
speed: number = 648;
start () {
}
update (dt) {
// 移动
this.node.y += this.speed * dt;
// 出屏幕销毁
if (this.node.y > 660) {
this.node.destroy();
}
}
onCollisionEnter(other) {
//如果碰到敌人,销毁自己让自己死亡
if (other.tag == 1) {
//销毁敌人
other.getComponent(EnemyControl).die();
//销毁自己
this.node.destroy();
}
}
}
{
"ver": "1.0.8",
"uuid": "156fd4d1-30e5-4c4f-9d40-c1ba4f151d91",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
......@@ -21,6 +21,12 @@
},
{
"__id__": 12
},
{
"__id__": 15
},
{
"__id__": 20
}
],
"_active": false,
......@@ -619,6 +625,285 @@
"__id__": 12
},
"_enabled": true,
"bulletPre": {
"__uuid__": "a196535c-ed2e-49d6-a7d9-de56a41c1fbb"
},
"_id": "7cp3iohZBBer32Lh+4Acro"
},
{
"__type__": "cc.Node",
"_name": "bullet1",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 16
},
{
"__id__": 17
},
{
"__id__": 18
}
],
"_prefab": {
"__id__": 19
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 5,
"height": 11
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
239.329,
163.178,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "23i/SUn/RFg7G8z62wgd2I"
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 15
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": {
"__uuid__": "4137bde6-07d6-4e31-80e5-760d55460f1b"
},
"_type": 0,
"_sizeMode": 1,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_atlas": null,
"_id": "07+EJLpNZDJrau6Gqnj2mY"
},
{
"__type__": "cc.BoxCollider",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 15
},
"_enabled": true,
"tag": 0,
"_offset": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_size": {
"__type__": "cc.Size",
"width": 5,
"height": 11
},
"_id": "c3ZeNVy+tGi5t+1KHC7Hxz"
},
{
"__type__": "156fdTRMOVMT51AwbpPFR2R",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 15
},
"_enabled": true,
"speed": 800,
"_id": "95uRQ23ptKyIEmjR5CiEWv"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 15
},
"asset": {
"__uuid__": "a196535c-ed2e-49d6-a7d9-de56a41c1fbb"
},
"fileId": "",
"sync": false
},
{
"__type__": "cc.Node",
"_name": "enemy",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 21
},
{
"__id__": 22
},
{
"__id__": 23
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 51,
"height": 38
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
154.476,
509.117,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "5cdVHfYv9H8IDA7WFeGcrZ"
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 20
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": {
"__uuid__": "5c693fcc-43f6-4f16-b3b7-55672662654a"
},
"_type": 0,
"_sizeMode": 1,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_atlas": null,
"_id": "572uE6ztZLIYUz2tX5toAL"
},
{
"__type__": "cc.BoxCollider",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 20
},
"_enabled": true,
"tag": 1,
"_offset": {
"__type__": "cc.Vec2",
"x": 0,
"y": 1.9
},
"_size": {
"__type__": "cc.Size",
"width": 43.4,
"height": 32.3
},
"_id": "240JwdjLVGvLFBHWtOcYww"
},
{
"__type__": "e4cffTABZpCL58N/un/x4eE",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 20
},
"_enabled": true,
"_id": "4aLf5u87xPfJogtnzuJXnP"
}
]
\ No newline at end of file
const {ccclass, property} = cc._decorator;
@ccclass
export default class EnemyControl extends cc.Component {
start () {
}
update (dt) {}
//死亡
die() {
this.node.destroy();
}
}
{
"ver": "1.0.8",
"uuid": "e4cff4c0-059a-422f-9f0d-fee9ffc78784",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
......@@ -2,13 +2,30 @@
const {ccclass, property} = cc._decorator;
@ccclass
export default class NewClass extends cc.Component {
export default class PlayerControl extends cc.Component {
@property(cc.Prefab)
bulletPre: cc.Prefab = null;
start () {
this.node.on(cc.Node.EventType.TOUCH_MOVE, (event) => {
this.node.setPosition(event.getLocation());
});
//攻击 计时器
this.schedule(() => {
//创建子弹 需要预设体
let bullet = cc.instantiate(this.bulletPre);
//设置父物体
bullet.setParent(cc.director.getScene());
//设置子弹的坐标
bullet.x = this.node.x;
bullet.y = this.node.y + 60;
}, 0.5);
//开启碰撞
cc.director.getCollisionManager().enabled = true;
}
// update (dt) {}
}
{
"ver": "2.3.5",
"uuid": "001710c1-f849-4d01-b6be-d939df7c7534",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 5,
"height": 11,
"platformSettings": {},
"subMetas": {
"bullet1": {
"ver": "1.0.4",
"uuid": "4137bde6-07d6-4e31-80e5-760d55460f1b",
"rawTextureUuid": "001710c1-f849-4d01-b6be-d939df7c7534",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 5,
"height": 11,
"rawWidth": 5,
"rawHeight": 11,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
[
{
"__type__": "cc.Prefab",
"_name": "",
"_objFlags": 0,
"_native": "",
"data": {
"__id__": 1
},
"optimizationPolicy": 0,
"asyncLoadAssets": false,
"readonly": false
},
{
"__type__": "cc.Node",
"_name": "bullet1",
"_objFlags": 0,
"_parent": null,
"_children": [],
"_active": true,
"_components": [
{
"__id__": 2
},
{
"__id__": 3
},
{
"__id__": 4
}
],
"_prefab": {
"__id__": 5
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 5,
"height": 11
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
239.329,
163.178,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": ""
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": {
"__uuid__": "4137bde6-07d6-4e31-80e5-760d55460f1b"
},
"_type": 0,
"_sizeMode": 1,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_atlas": null,
"_id": ""
},
{
"__type__": "cc.BoxCollider",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"tag": 0,
"_offset": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_size": {
"__type__": "cc.Size",
"width": 5,
"height": 11
},
"_id": ""
},
{
"__type__": "156fdTRMOVMT51AwbpPFR2R",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "",
"sync": false
}
]
\ No newline at end of file
{
"ver": "1.2.9",
"uuid": "a196535c-ed2e-49d6-a7d9-de56a41c1fbb",
"optimizationPolicy": "AUTO",
"asyncLoadAssets": false,
"readonly": false,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "3ca14dfd-28f8-4b8a-9496-c7fc74de1ecc",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 57,
"height": 43,
"platformSettings": {},
"subMetas": {
"enemy1": {
"ver": "1.0.4",
"uuid": "5c693fcc-43f6-4f16-b3b7-55672662654a",
"rawTextureUuid": "3ca14dfd-28f8-4b8a-9496-c7fc74de1ecc",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": -1.5,
"trimX": 3,
"trimY": 4,
"width": 51,
"height": 38,
"rawWidth": 57,
"rawHeight": 43,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment