117 lines
3.6 KiB
TypeScript
117 lines
3.6 KiB
TypeScript
/*
|
|
* @Author: dgflash
|
|
* @Date: 2021-11-18 17:42:59
|
|
* @LastEditors: dgflash
|
|
* @LastEditTime: 2022-08-17 12:36:18
|
|
*/
|
|
|
|
import { Vec3, v3,_decorator ,Collider2D,Contact2DType,IPhysics2DContact,Material,Sprite,ProgressBar} from "cc";
|
|
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
|
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
|
import { RoleSpine } from "./RoleSpine";
|
|
import {BoxSet} from "../common/config/BoxSet"
|
|
import { smc } from "../common/SingletonModuleComp";
|
|
import { SkillCom } from "../skills/SkillCom";
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/** 角色显示组件 */
|
|
@ccclass('RoleViewComp') // 定义为 Cocos Creator 组件
|
|
@ecs.register('RoleView', false) // 定义为 ECS 组件
|
|
export class RoleViewComp extends CCComp {
|
|
@property(Material)
|
|
hitFlashMaterial: Material;
|
|
orginalFlashMaterial: Material;
|
|
sprite: Sprite;
|
|
/** 角色动画 */
|
|
as: RoleSpine = null!;
|
|
/** 角色属性 */
|
|
hp: number = 1000;
|
|
hp_max:number = 1000;
|
|
power: number = 0;
|
|
stop_cd:number = 0;
|
|
atk_cd:number = 0;
|
|
atk:number = 2;
|
|
|
|
onLoad() {
|
|
this.as = this.getComponent(RoleSpine);
|
|
|
|
}
|
|
start () {
|
|
this.sprite = this.node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite);
|
|
this.orginalFlashMaterial = this.sprite.getRenderMaterial(0);
|
|
|
|
console.log("Role view start")
|
|
|
|
let collider = this.getComponent(Collider2D);
|
|
if (collider) {
|
|
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
|
|
}
|
|
|
|
}
|
|
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
|
if(otherCollider.tag==BoxSet.SKILL_TAG){
|
|
if(selfCollider.group != otherCollider.group){
|
|
let skill = otherCollider.node.getComponent(SkillCom)!;
|
|
// console.log('onPostSolve',skill);
|
|
this.in_atked();
|
|
if(this.hp <= 0 ){
|
|
return
|
|
}
|
|
this.hp_change(skill.atk);
|
|
}
|
|
}
|
|
}
|
|
onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
|
|
|
|
|
}
|
|
onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
|
if(selfCollider.group != otherCollider.group&&otherCollider.tag != BoxSet.ATK_RANGE){
|
|
|
|
}
|
|
|
|
}
|
|
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
|
|
|
|
|
if(selfCollider.group == otherCollider.group){
|
|
// console.log('monster view group 相同');
|
|
|
|
}else{
|
|
// console.log('monster onPostSolve'+selfCollider.group+"|"+otherCollider.group);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
update(dt: number){
|
|
|
|
|
|
|
|
}
|
|
|
|
reset() {
|
|
this.node.destroy();
|
|
}
|
|
|
|
|
|
|
|
in_atked() {
|
|
this.sprite.setSharedMaterial(this.hitFlashMaterial, 0);
|
|
this.scheduleOnce(() => {
|
|
this.sprite.setSharedMaterial(this.orginalFlashMaterial, 0);
|
|
}, 0.1);
|
|
}
|
|
hp_change(hp: number){
|
|
this.hp -= hp;
|
|
if(this.hp > this.hp_max){
|
|
this.hp = this.hp_max;
|
|
}
|
|
let hp_progress= this.hp/this.hp_max;
|
|
this.node.getChildByName("hp").getComponent(ProgressBar)!.progress = hp_progress;
|
|
if(this.hp <= 0){
|
|
console.log("dead");
|
|
}
|
|
}
|
|
|
|
} |