This commit is contained in:
2024-08-11 16:50:42 +08:00
parent 37bc93aa1c
commit 6355d80a2c
70 changed files with 1696 additions and 2535 deletions

View File

@@ -27,23 +27,23 @@ export class Skill extends ecs.Entity {
this.remove(SkillCom);
super.destroy();
}
load(pos: Vec3 = Vec3.ZERO,speed:number = 100,range:number = 50,scale:number = 1,parent:Node) {
// var path = "game/monster/"+prefab_path;
var path = "game/skills/base";
load(pos: Vec3 = Vec3.ZERO,speed:number = 100,range:number = 50,scale:number = 1,parent:Node,skill_name:string = "base",atk:number =10) {
var path = "game/skills/"+skill_name;
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
node.parent = parent;
node.setPosition(pos)
var mv = node.getComponent(SkillCom)!;
mv.speed = speed;
mv.range = range;
mv.scale = scale;
var sv = node.getComponent(SkillCom)!;
sv.speed = speed;
sv.range = range;
sv.scale = scale;
sv.atk = atk;
if(scale == 1){
mv.change_collider_group(BoxSet.HERO_SKILL)
sv.change_collider_group(BoxSet.HERO_SKILL)
}else{
mv.change_collider_group(BoxSet.MONSTER_SKILL)
sv.change_collider_group(BoxSet.MONSTER_SKILL)
}
this.add(mv);
this.add(sv);
}
}

View File

@@ -17,20 +17,29 @@ export class SkillCom extends CCComp {
speed:number = 600;
range:number = 80;
scale:number = 1;
atk:number = 10;
is_destroy:boolean = false;
start() {
let collider = this.getComponent(Collider2D);
if (collider) {
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
// collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
}
}
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
switch (selfCollider.group) {
case BoxSet.HERO_SKILL:
switch (otherCollider.group){
case BoxSet.MONSTER:
// this.reset()
console.log('hero skill',selfCollider);
if(this.is_destroy){
return
}else{
this.is_destroy = true;
this.toDestroy();
}
// this.speed = 0;
// this.timer = 1;
// console.log("speed:"+this.speed+" | timer:"+this.timer);
@@ -40,6 +49,12 @@ export class SkillCom extends CCComp {
case BoxSet.MONSTER_SKILL:
switch (otherCollider.group){
case BoxSet.HERO:
if(this.is_destroy){
return
}else{
this.is_destroy = true;
this.toDestroy();
}
// console.log('monster skill',selfCollider,otherCollider);
// this.reset()
break;
@@ -57,7 +72,13 @@ export class SkillCom extends CCComp {
this.node.setPosition(v3(this.node.position.x+deltaTime*this.speed*this.scale,this.node.position.y,this.node.position.z))
if(Math.abs(this.node.position.x) > this.range)
{
this.reset()
if(this.is_destroy){
return
}else{
this.is_destroy = true;
this.toDestroy()
}
}
}
@@ -68,9 +89,14 @@ export class SkillCom extends CCComp {
// break;
// }
// }
toDestroy() {
setTimeout(() => {
this.ent.destroy()
}, 15);
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.is_destroy=false
this.node.destroy();
}
}

View File

@@ -0,0 +1,20 @@
import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;
@ccclass('atked')
export class atked extends Component {
time = 0.3;
start() {
}
update(deltaTime: number) {
this.time = this.time - deltaTime;
if(this.time <= 0)
{
this.node.destroy()
}
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "65d6266f-bba6-4b98-8343-2a67642ec7eb",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,18 @@
import { _decorator, Component, Node ,Animation} from 'cc';
const { ccclass, property } = _decorator;
@ccclass('dead')
export class dead extends Component {
start() {
let anim = this.node.getComponent(Animation);
anim.on(Animation.EventType.FINISHED, this.onAnimationFinished, this);
}
onAnimationFinished(){
this.node.destroy();
}
update(deltaTime: number) {
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "0f3c4261-15b1-4eda-b105-a81249ee116f",
"files": [],
"subMetas": {},
"userData": {}
}