diff --git a/assets/resources/game/heros/hero.prefab b/assets/resources/game/heros/hero.prefab index 1787828e..bb9c08e2 100644 --- a/assets/resources/game/heros/hero.prefab +++ b/assets/resources/game/heros/hero.prefab @@ -569,7 +569,7 @@ "__expectedType__": "sp.SkeletonData" }, "defaultSkin": "default", - "defaultAnimation": "", + "defaultAnimation": "", "_premultipliedAlpha": false, "_timeScale": 1, "_preCacheMode": 1, @@ -1918,7 +1918,7 @@ "fileId": "88a6VdbQBB7YwXovYCN2Sy" }, { - "__type__": "cc.BoxCollider2D", + "__type__": "cc.RigidBody2D", "_name": "", "_objFlags": 0, "__editorExtras__": {}, @@ -1929,45 +1929,11 @@ "__prefab": { "__id__": 88 }, - "tag": 0, - "_group": 2, - "_density": 1, - "_sensor": false, - "_friction": 1, - "_restitution": 0, - "_offset": { - "__type__": "cc.Vec2", - "x": 2.6, - "y": 32.5 - }, - "_size": { - "__type__": "cc.Size", - "width": 24.5, - "height": 75.8 - }, - "_id": "" - }, - { - "__type__": "cc.CompPrefabInfo", - "fileId": "b2Dt9lJI9FyJCDezkDBPBl" - }, - { - "__type__": "cc.RigidBody2D", - "_name": "", - "_objFlags": 0, - "__editorExtras__": {}, - "node": { - "__id__": 1 - }, - "_enabled": true, - "__prefab": { - "__id__": 90 - }, "enabledContactListener": true, "bullet": true, "awakeOnLoad": true, "_group": 2, - "_type": 2, + "_type": 1, "_allowSleep": false, "_gravityScale": 1, "_linearDamping": 0, @@ -1985,6 +1951,40 @@ "__type__": "cc.CompPrefabInfo", "fileId": "d8rVs6intBQ7lRU8Dw4zXV" }, + { + "__type__": "cc.BoxCollider2D", + "_name": "", + "_objFlags": 0, + "__editorExtras__": {}, + "node": { + "__id__": 1 + }, + "_enabled": true, + "__prefab": { + "__id__": 90 + }, + "tag": 0, + "_group": 2, + "_density": 1, + "_sensor": false, + "_friction": 1, + "_restitution": 0, + "_offset": { + "__type__": "cc.Vec2", + "x": 2.6, + "y": 34.5 + }, + "_size": { + "__type__": "cc.Size", + "width": 81.9, + "height": 73.4 + }, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "b2Dt9lJI9FyJCDezkDBPBl" + }, { "__type__": "cc.PrefabInfo", "root": { diff --git a/assets/resources/game/map/map_rpg.prefab b/assets/resources/game/map/map_rpg.prefab index bb7b49c0..43f53c24 100644 --- a/assets/resources/game/map/map_rpg.prefab +++ b/assets/resources/game/map/map_rpg.prefab @@ -28,17 +28,17 @@ "_active": true, "_components": [ { - "__id__": 74 + "__id__": 66 }, { - "__id__": 76 + "__id__": 68 }, { - "__id__": 78 + "__id__": 70 } ], "_prefab": { - "__id__": 80 + "__id__": 72 }, "_lpos": { "__type__": "cc.Vec3", @@ -197,17 +197,17 @@ "_active": true, "_components": [ { - "__id__": 67 + "__id__": 59 }, { - "__id__": 69 + "__id__": 61 }, { - "__id__": 71 + "__id__": 63 } ], "_prefab": { - "__id__": 73 + "__id__": 65 }, "_lpos": { "__type__": "cc.Vec3", @@ -251,23 +251,23 @@ "__id__": 8 }, { - "__id__": 38 + "__id__": 30 }, { - "__id__": 42 + "__id__": 34 }, { - "__id__": 48 + "__id__": 40 } ], "_active": true, "_components": [ { - "__id__": 64 + "__id__": 56 } ], "_prefab": { - "__id__": 66 + "__id__": 58 }, "_lpos": { "__type__": "cc.Vec3", @@ -314,20 +314,20 @@ "_active": true, "_components": [ { - "__id__": 29 + "__id__": 21 }, { - "__id__": 31 + "__id__": 23 }, { - "__id__": 33 + "__id__": 25 }, { - "__id__": 35 + "__id__": 27 } ], "_prefab": { - "__id__": 37 + "__id__": 29 }, "_lpos": { "__type__": "cc.Vec3", @@ -374,14 +374,14 @@ "_active": true, "_components": [ { - "__id__": 24 + "__id__": 16 }, { - "__id__": 26 + "__id__": 18 } ], "_prefab": { - "__id__": 28 + "__id__": 20 }, "_lpos": { "__type__": "cc.Vec3", @@ -428,22 +428,10 @@ }, { "__id__": 13 - }, - { - "__id__": 15 - }, - { - "__id__": 17 - }, - { - "__id__": 19 - }, - { - "__id__": 21 } ], "_prefab": { - "__id__": 23 + "__id__": 15 }, "_lpos": { "__type__": "cc.Vec3", @@ -547,142 +535,6 @@ "__type__": "cc.CompPrefabInfo", "fileId": "66D90QlYtEvKkAU6KcReVW" }, - { - "__type__": "cc.RigidBody2D", - "_name": "", - "_objFlags": 0, - "__editorExtras__": {}, - "node": { - "__id__": 10 - }, - "_enabled": true, - "__prefab": { - "__id__": 16 - }, - "enabledContactListener": false, - "bullet": true, - "awakeOnLoad": true, - "_group": 1, - "_type": 0, - "_allowSleep": false, - "_gravityScale": 0, - "_linearDamping": 0, - "_angularDamping": 0, - "_linearVelocity": { - "__type__": "cc.Vec2", - "x": 0, - "y": 0 - }, - "_angularVelocity": 0, - "_fixedRotation": false, - "_id": "" - }, - { - "__type__": "cc.CompPrefabInfo", - "fileId": "fa0hN7/dVNJp+ZtcBdqwHp" - }, - { - "__type__": "cc.BoxCollider2D", - "_name": "", - "_objFlags": 0, - "__editorExtras__": {}, - "node": { - "__id__": 10 - }, - "_enabled": true, - "__prefab": { - "__id__": 18 - }, - "tag": 0, - "_group": 1, - "_density": 1, - "_sensor": false, - "_friction": 1, - "_restitution": 0, - "_offset": { - "__type__": "cc.Vec2", - "x": -119.1, - "y": -459.8 - }, - "_size": { - "__type__": "cc.Size", - "width": 4118.9, - "height": 981.7 - }, - "_id": "" - }, - { - "__type__": "cc.CompPrefabInfo", - "fileId": "fexeczFgpEObyOHYY30dp9" - }, - { - "__type__": "cc.BoxCollider2D", - "_name": "", - "_objFlags": 0, - "__editorExtras__": {}, - "node": { - "__id__": 10 - }, - "_enabled": false, - "__prefab": { - "__id__": 20 - }, - "tag": 0, - "_group": 1, - "_density": 1, - "_sensor": false, - "_friction": 0.2, - "_restitution": 0, - "_offset": { - "__type__": "cc.Vec2", - "x": 983.4, - "y": -22.4 - }, - "_size": { - "__type__": "cc.Size", - "width": 826.9, - "height": 1473.1 - }, - "_id": "" - }, - { - "__type__": "cc.CompPrefabInfo", - "fileId": "9fhhEkjyRAg7KBWa7BQ8y2" - }, - { - "__type__": "cc.BoxCollider2D", - "_name": "", - "_objFlags": 0, - "__editorExtras__": {}, - "node": { - "__id__": 10 - }, - "_enabled": false, - "__prefab": { - "__id__": 22 - }, - "tag": 0, - "_group": 1, - "_density": 1, - "_sensor": false, - "_friction": 0.2, - "_restitution": 0, - "_offset": { - "__type__": "cc.Vec2", - "x": -883.7, - "y": -16.2 - }, - "_size": { - "__type__": "cc.Size", - "width": 659.8, - "height": 1471.5 - }, - "_id": "" - }, - { - "__type__": "cc.CompPrefabInfo", - "fileId": "dclJIfE5FF96M6AV1wbuKr" - }, { "__type__": "cc.PrefabInfo", "root": { @@ -706,7 +558,7 @@ }, "_enabled": true, "__prefab": { - "__id__": 25 + "__id__": 17 }, "_contentSize": { "__type__": "cc.Size", @@ -734,7 +586,7 @@ }, "_enabled": true, "__prefab": { - "__id__": 27 + "__id__": 19 }, "_customMaterial": null, "_srcBlendFactor": 2, @@ -792,7 +644,7 @@ }, "_enabled": true, "__prefab": { - "__id__": 30 + "__id__": 22 }, "_contentSize": { "__type__": "cc.Size", @@ -820,10 +672,10 @@ }, "_enabled": true, "__prefab": { - "__id__": 32 + "__id__": 24 }, "bgImg": { - "__id__": 26 + "__id__": 18 }, "_id": "" }, @@ -841,7 +693,7 @@ }, "_enabled": true, "__prefab": { - "__id__": 34 + "__id__": 26 }, "light": { "__uuid__": "319c7eb8-9826-48b6-81e4-82559dbf82a8", @@ -863,7 +715,7 @@ }, "_enabled": true, "__prefab": { - "__id__": 36 + "__id__": 28 }, "_id": "" }, @@ -896,11 +748,11 @@ "_active": true, "_components": [ { - "__id__": 39 + "__id__": 31 } ], "_prefab": { - "__id__": 41 + "__id__": 33 }, "_lpos": { "__type__": "cc.Vec3", @@ -937,11 +789,11 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 38 + "__id__": 30 }, "_enabled": true, "__prefab": { - "__id__": 40 + "__id__": 32 }, "_contentSize": { "__type__": "cc.Size", @@ -984,14 +836,14 @@ "_active": true, "_components": [ { - "__id__": 43 + "__id__": 35 }, { - "__id__": 45 + "__id__": 37 } ], "_prefab": { - "__id__": 47 + "__id__": 39 }, "_lpos": { "__type__": "cc.Vec3", @@ -1028,11 +880,11 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 42 + "__id__": 34 }, "_enabled": true, "__prefab": { - "__id__": 44 + "__id__": 36 }, "_contentSize": { "__type__": "cc.Size", @@ -1056,11 +908,11 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 42 + "__id__": 34 }, "_enabled": true, "__prefab": { - "__id__": 46 + "__id__": 38 }, "_id": "" }, @@ -1091,20 +943,20 @@ }, "_children": [ { - "__id__": 49 + "__id__": 41 } ], "_active": true, "_components": [ { - "__id__": 59 + "__id__": 51 }, { - "__id__": 61 + "__id__": 53 } ], "_prefab": { - "__id__": 63 + "__id__": 55 }, "_lpos": { "__type__": "cc.Vec3", @@ -1139,17 +991,17 @@ "__type__": "cc.Node", "_objFlags": 0, "_parent": { - "__id__": 48 + "__id__": 40 }, "_prefab": { - "__id__": 50 + "__id__": 42 }, "__editorExtras__": {} }, { "__type__": "cc.PrefabInfo", "root": { - "__id__": 49 + "__id__": 41 }, "asset": { "__uuid__": "63c02880-bda6-4370-bb22-46bf4f49bbfe", @@ -1157,7 +1009,7 @@ }, "fileId": "fdklpBwCBM/qJ4WFlQF3kT", "instance": { - "__id__": 51 + "__id__": 43 }, "targetOverrides": null }, @@ -1171,22 +1023,22 @@ "mountedComponents": [], "propertyOverrides": [ { - "__id__": 52 + "__id__": 44 }, { - "__id__": 54 + "__id__": 46 }, { - "__id__": 55 + "__id__": 47 }, { - "__id__": 56 + "__id__": 48 }, { - "__id__": 57 + "__id__": 49 }, { - "__id__": 58 + "__id__": 50 } ], "removedComponents": [] @@ -1194,7 +1046,7 @@ { "__type__": "CCPropertyOverrideInfo", "targetInfo": { - "__id__": 53 + "__id__": 45 }, "propertyPath": [ "_name" @@ -1210,7 +1062,7 @@ { "__type__": "CCPropertyOverrideInfo", "targetInfo": { - "__id__": 53 + "__id__": 45 }, "propertyPath": [ "_lpos" @@ -1225,7 +1077,7 @@ { "__type__": "CCPropertyOverrideInfo", "targetInfo": { - "__id__": 53 + "__id__": 45 }, "propertyPath": [ "_lrot" @@ -1241,7 +1093,7 @@ { "__type__": "CCPropertyOverrideInfo", "targetInfo": { - "__id__": 53 + "__id__": 45 }, "propertyPath": [ "_euler" @@ -1256,7 +1108,7 @@ { "__type__": "CCPropertyOverrideInfo", "targetInfo": { - "__id__": 53 + "__id__": 45 }, "propertyPath": [ "_active" @@ -1266,7 +1118,7 @@ { "__type__": "CCPropertyOverrideInfo", "targetInfo": { - "__id__": 53 + "__id__": 45 }, "propertyPath": [ "_lscale" @@ -1284,11 +1136,11 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 48 + "__id__": 40 }, "_enabled": true, "__prefab": { - "__id__": 60 + "__id__": 52 }, "_contentSize": { "__type__": "cc.Size", @@ -1312,11 +1164,11 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 48 + "__id__": 40 }, "_enabled": true, "__prefab": { - "__id__": 62 + "__id__": 54 }, "light": { "__uuid__": "319c7eb8-9826-48b6-81e4-82559dbf82a8", @@ -1351,7 +1203,7 @@ }, "_enabled": true, "__prefab": { - "__id__": 65 + "__id__": 57 }, "_contentSize": { "__type__": "cc.Size", @@ -1392,7 +1244,7 @@ }, "_enabled": true, "__prefab": { - "__id__": 68 + "__id__": 60 }, "_contentSize": { "__type__": "cc.Size", @@ -1420,7 +1272,7 @@ }, "_enabled": true, "__prefab": { - "__id__": 70 + "__id__": 62 }, "camera": { "__id__": 3 @@ -1429,16 +1281,16 @@ "__id__": 7 }, "mapLayer": { - "__id__": 31 + "__id__": 23 }, "floorLayer": { - "__id__": 38 + "__id__": 30 }, "entityLayer": { - "__id__": 45 + "__id__": 37 }, "SkillLayer": { - "__id__": 61 + "__id__": 53 }, "isFollowPlayer": true, "_id": "" @@ -1457,7 +1309,7 @@ }, "_enabled": true, "__prefab": { - "__id__": 72 + "__id__": 64 }, "_id": "" }, @@ -1488,7 +1340,7 @@ }, "_enabled": true, "__prefab": { - "__id__": 75 + "__id__": 67 }, "_contentSize": { "__type__": "cc.Size", @@ -1516,7 +1368,7 @@ }, "_enabled": true, "__prefab": { - "__id__": 77 + "__id__": 69 }, "_cameraComponent": { "__id__": 3 @@ -1538,7 +1390,7 @@ }, "_enabled": true, "__prefab": { - "__id__": 79 + "__id__": 71 }, "_alignFlags": 45, "_target": null, @@ -1577,7 +1429,7 @@ "targetOverrides": null, "nestedPrefabInstanceRoots": [ { - "__id__": 49 + "__id__": 41 } ] } diff --git a/assets/script/game/common/config/BoxSet.ts b/assets/script/game/common/config/BoxSet.ts index 67a1a59e..7ed6c1dd 100644 --- a/assets/script/game/common/config/BoxSet.ts +++ b/assets/script/game/common/config/BoxSet.ts @@ -25,7 +25,7 @@ export enum BoxSet { MONSTER_START = 300, END_POINT = 360, //游戏地平线 - GAME_LINE = 0, + GAME_LINE = 10, CSKILL_X = 280, CSKILL_Y = 420, } \ No newline at end of file diff --git a/assets/script/game/monster/MonsterViewComp.ts b/assets/script/game/monster/MonsterViewComp.ts index 0f345dce..6e2a152f 100644 --- a/assets/script/game/monster/MonsterViewComp.ts +++ b/assets/script/game/monster/MonsterViewComp.ts @@ -66,44 +66,7 @@ export class MonsterViewComp extends CCComp { private timer:Timer = new Timer(0.1); //计时器 is_dead:boolean = false; //是否摧毁 - - /** 视图层逻辑代码分离演示 */ - start () { - this.sprite = this.node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite); - this.orginalFlashMaterial = this.sprite.getRenderMaterial(0); - // 注册单个碰撞体的回调函数 - let collider = this.getComponent(Collider2D); - if (collider) { - collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this); - collider.on(Contact2DType.END_CONTACT, this.onEndContact, this); - // collider.on(Contact2DType.PRE_SOLVE, this.onPreSolve, this); - collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this); - } - // this.node.getChildByName("level").getChildByName("level").getComponent(Label).string = this.level.toString(); - - - } - onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) { - - - } - onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) { - // 只在两个碰撞体结束接触时被调用一次 - // console.log('onEndContact'); - } - // onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) { - // // 每次将要处理碰撞体接触逻辑时被调用 - // console.log('onPreSolve'); - // } - onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) { - if(otherCollider.group== BoxSet.HERO_SKILL || otherCollider.group== BoxSet.MONSTER_SKILL){ - let skill = otherCollider.node.getComponent(SkillCom)!; - // console.log('onPostSolve',skill); - this.in_atked(); - this.hp_change(skill.atk); - } - } - + is_stop:boolean = false; onLoad() { this.as = this.getComponent(MonsterSpine); @@ -112,7 +75,68 @@ export class MonsterViewComp extends CCComp { // EPhysics2DDrawFlags.CenterOfMass | // EPhysics2DDrawFlags.Joint | // EPhysics2DDrawFlags.Shape; + } /** 视图层逻辑代码分离演示 */ + start () { + this.sprite = this.node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite); + this.orginalFlashMaterial = this.sprite.getRenderMaterial(0); + // 注册单个碰撞体的回调函数 + let collider = this.getComponent(Collider2D); + console.log(collider); + if (collider) { + collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this); + collider.on(Contact2DType.END_CONTACT, this.onEndContact, this); + collider.on(Contact2DType.PRE_SOLVE, this.onPreSolve, this); + collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this); + } + // this.node.getChildByName("level").getChildByName("level").getComponent(Label).string = this.level.toString(); + + } + onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) { + } + onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) { + // 只在两个碰撞体结束接触时被调用一次 + // console.log('onEndContact'); + } + onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) { + if(selfCollider.group != otherCollider.group){ + if(otherCollider.tag != 8){ + this.stop_cd = 0.5; + } + } + } + onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) { + if(otherCollider.group== BoxSet.HERO_SKILL || otherCollider.group== BoxSet.MONSTER_SKILL){ + let skill = otherCollider.node.getComponent(SkillCom)!; + // console.log('onPostSolve',skill); + this.in_atked(); + this.hp_change(skill.atk); + } + + if(selfCollider.group == otherCollider.group){ + console.log('group 相同'); + if(otherCollider.tag != 8){ + let self_pos=selfCollider.node.getPosition(); + let other_pos=otherCollider.node.getPosition(); + if(selfCollider.group == BoxSet.HERO){ + if(self_pos.x < other_pos.x&&Math.abs(self_pos.x-other_pos.x) <= 20){ + this.stop_cd=0.1 + } + } + if(selfCollider.group == BoxSet.MONSTER){ + if(self_pos.x > other_pos.x&&Math.abs(self_pos.x-other_pos.x) <= 20){ + this.stop_cd=0.1 + } + } + + } + } + + + } + + + change_name(hero_name:string='hero',scale:number=1){ this.name=hero_name; let label:any =this.node.getChildByName("lab_name") @@ -235,7 +259,7 @@ export class MonsterViewComp extends CCComp { }); } load_skill(skill_name:string){ - // console.log("load_skill"); + console.log("load_skill"); let skill = ecs.getEntity(Skill); let x=30 if(this.scale==1){ diff --git a/assets/script/game/skills/Skill.ts b/assets/script/game/skills/Skill.ts index 0cceb5d1..a87addad 100644 --- a/assets/script/game/skills/Skill.ts +++ b/assets/script/game/skills/Skill.ts @@ -45,9 +45,9 @@ export class Skill extends ecs.Entity { sv.angle = angle; sv.t_pos = t_pos; if(scale == 1){ - sv.change_collider_group(BoxSet.HERO_SKILL) + sv.box_group=BoxSet.HERO_SKILL }else{ - sv.change_collider_group(BoxSet.MONSTER_SKILL) + sv.box_group=BoxSet.MONSTER_SKILL } this.add(sv); } diff --git a/assets/script/game/skills/SkillCom.ts b/assets/script/game/skills/SkillCom.ts index fc9e1494..cd415bb1 100644 --- a/assets/script/game/skills/SkillCom.ts +++ b/assets/script/game/skills/SkillCom.ts @@ -24,15 +24,13 @@ export class SkillCom extends CCComp { angle:number = 0; t_pos:Vec3 = null; is_destroy:boolean = false; + box_group:number = 0; start() { this.node.active=true this.node.angle = this.angle; - //根据目标坐标、欧拉角、预设距离增量speed 来计算新的x增量,y增量 - // this.x_speed = Math.cos(this.angle * Math.PI / 180) * this.speed; - // this.y_speed = Math.sin(this.angle * Math.PI / 180) * this.speed; - let collider = this.getComponent(Collider2D); + collider.group = this.box_group; if (collider) { // collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this); collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this); @@ -86,11 +84,7 @@ export class SkillCom extends CCComp { } - change_collider_group(group:number){ - let collider = this.getComponent(Collider2D); - collider.group = group; - } - update(deltaTime: number) { + update(deltaTime: number) { // this.node.setScale(v3(this.scale,this.node.scale.y,this.node.scale.z)) this.move(deltaTime) // if(Math.abs(this.node.position.x) > this.dis) diff --git a/assets/script/game/skills/baseCom.ts b/assets/script/game/skills/baseCom.ts index 419c5eb6..cdea1fff 100644 --- a/assets/script/game/skills/baseCom.ts +++ b/assets/script/game/skills/baseCom.ts @@ -41,10 +41,7 @@ export class baseCom extends Component { reset() { this.node.destroy(); } - change_collider_group(group:number){ - let collider = this.getComponent(Collider2D); - collider.group = group; - } + update(deltaTime: number) { this.node.setScale(v3(this.scale,this.node.scale.y,this.node.scale.z)) this.node.setPosition(v3(this.node.position.x+deltaTime*this.speed*this.scale,this.node.position.y,this.node.position.z))