dd
This commit is contained in:
@@ -13,11 +13,10 @@ import { UIID } from "../common/config/GameUIConfig";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
import { RoleModelComp } from "./RoleModelComp";
|
||||
import { RoleSpine } from "./RoleSpine";
|
||||
import { RoleViewComp } from "./RoleViewComp";
|
||||
import { RoleSet } from "../common/config/RoleSet";
|
||||
import { MoveToComp } from "../common/ecs/position/MoveTo";
|
||||
import { MonsterViewComp } from "../monster/MonsterViewComp";
|
||||
import { MonsterBuffComp } from "../monster/MonsterBuffComp";
|
||||
import { RoleViewComp } from "./RoleViewComp";
|
||||
import { RoleBuffComp } from "./RoleBuffComp";
|
||||
import { BoxSet } from "../common/config/BoxSet";
|
||||
/** 角色实体 */
|
||||
@ecs.register(`Role`)
|
||||
@@ -27,7 +26,7 @@ export class Role extends ecs.Entity {
|
||||
RoleMoveTo!: MoveToComp; // 移动
|
||||
|
||||
// 视图层
|
||||
MonsterView!: MonsterViewComp;
|
||||
RoleView!: RoleViewComp;
|
||||
|
||||
protected init() {
|
||||
this.addComponents<ecs.Comp>(
|
||||
@@ -35,7 +34,7 @@ export class Role extends ecs.Entity {
|
||||
}
|
||||
|
||||
destroy(): void {
|
||||
this.remove(MonsterViewComp);
|
||||
this.remove(RoleViewComp);
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
@@ -57,14 +56,14 @@ export class Role extends ecs.Entity {
|
||||
|
||||
// sprite.spriteFrame = atlas.getSpriteFrame(RoleSet[uuid].path);
|
||||
// });
|
||||
// var rv = node.getComponent(MonsterViewComp)!;
|
||||
// var rv = node.getComponent(RoleViewComp)!;
|
||||
// this.add(rv);
|
||||
this.hero_init(uuid,node)
|
||||
|
||||
}
|
||||
hero_init(uuid:number=1001,node:Node,pos:Vec3=v3(0,0,0)){
|
||||
var mv = node.getComponent(MonsterViewComp)!;
|
||||
var buff =node.getComponent(MonsterBuffComp)!;
|
||||
var mv = node.getComponent(RoleViewComp)!;
|
||||
var buff =node.getComponent(RoleBuffComp)!;
|
||||
mv.is_role=true;
|
||||
mv.hero_uuid=uuid;
|
||||
mv.speed =mv.ospeed = 0;
|
||||
@@ -88,7 +87,7 @@ export class Role extends ecs.Entity {
|
||||
move(target: Vec3) {
|
||||
var move = this.get(MoveToComp) || this.add(MoveToComp);
|
||||
move.target = target;
|
||||
move.node = this.MonsterView.node;
|
||||
move.node = this.RoleView.node;
|
||||
move.speed = 300;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ const { ccclass, property } = _decorator;
|
||||
@ccclass('RoleBuffComp')
|
||||
@ecs.register('RoleBuff', false)
|
||||
export class RoleBuffComp extends CCComp {
|
||||
as: RoleSpine = null!;
|
||||
// as: RoleSpine = null!;
|
||||
mv!: RoleViewComp
|
||||
|
||||
timer:Timer = new Timer(0.1);
|
||||
@@ -28,7 +28,7 @@ export class RoleBuffComp extends CCComp {
|
||||
|
||||
|
||||
onLoad() {
|
||||
this.as = this.node.getComponent(RoleSpine);
|
||||
// this.as = this.node.getComponent(RoleSpine);
|
||||
this.mv= this.getComponent(RoleViewComp);
|
||||
} /** 视图层逻辑代码分离演示 */
|
||||
start () {
|
||||
@@ -73,7 +73,7 @@ export class RoleBuffComp extends CCComp {
|
||||
b.time=buff.time;
|
||||
if(buff.atk>0){
|
||||
this.node.getChildByName("avatar").setScale(1.2,1.2)
|
||||
// this.node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite).color= new Color().fromHEX("#F16F6F");
|
||||
this.node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite).color= new Color().fromHEX("#F16F6F");
|
||||
this.mv.atk+=(buff.atk+buff.args.atk-b.atk);
|
||||
}
|
||||
if(buff.hp>0){
|
||||
@@ -95,7 +95,7 @@ export class RoleBuffComp extends CCComp {
|
||||
if(buff.atk>0){
|
||||
this.mv.atk+=(buff.atk+buff.args.atk);
|
||||
this.node.getChildByName("avatar").setScale(1.2,1.2)
|
||||
// this.node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite).color= new Color().fromHEX("#F16F6F");
|
||||
this.node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite).color= new Color().fromHEX("#F16F6F");
|
||||
}
|
||||
if(buff.hp>0){
|
||||
this.mv.hp+=(buff.hp+buff.args.hp);
|
||||
|
||||
82
assets/script/game/Role/RoleRangComp.ts
Normal file
82
assets/script/game/Role/RoleRangComp.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
import { _decorator,Contact2DType,Collider2D ,IPhysics2DContact,v3, v2,Vec3} 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 { BoxSet } from "../common/config/BoxSet";
|
||||
import { RoleViewComp } from "./RoleViewComp";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 视图层对象 */
|
||||
@ccclass('RoleRangComp')
|
||||
@ecs.register('RoleRang', false)
|
||||
export class RoleRangComp extends CCComp {
|
||||
Hero_node: any=null!;
|
||||
RoleViewComp:RoleViewComp = null!;
|
||||
box_group:number = BoxSet.DEFAULT;
|
||||
box_tag:number = BoxSet.ATK_RANGE;
|
||||
offset_x:number = 0;
|
||||
atk_range:number = 150;
|
||||
/** 视图层逻辑代码分离演示 */
|
||||
start() {
|
||||
let collider = this.getComponent(Collider2D);
|
||||
collider.group = this.box_group;
|
||||
collider.tag = this.box_tag;
|
||||
this.Hero_node = this.node.parent;
|
||||
this.RoleViewComp=this.Hero_node.getComponent(RoleViewComp);
|
||||
// console.log("range box",this.RoleViewComp);
|
||||
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);
|
||||
}
|
||||
}
|
||||
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
|
||||
// if(selfCollider.group != otherCollider.group&&otherCollider.tag == 0){
|
||||
// console.log(this.node.name+"onBeginContact: seft:"+selfCollider.group+"|other:"+otherCollider.group+"| tag: seft:"+selfCollider.tag+"|other:"+otherCollider.tag);
|
||||
// this.RoleViewComp.is_atking = true;
|
||||
// if(Math.abs(otherCollider.node.position.x-selfCollider.node.position.x) < 120){
|
||||
// this.RoleViewComp.stop_cd = 0.1
|
||||
// }
|
||||
// }
|
||||
}
|
||||
onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
|
||||
if(selfCollider.group != otherCollider.group&&otherCollider.tag == 0 ){
|
||||
// console.log(this.node.name+"onEndContact: seft:"+selfCollider.group+"|other:"+otherCollider.group+"| tag: seft:"+selfCollider.tag+"|other:"+otherCollider.tag);
|
||||
this.RoleViewComp.is_atking = false;
|
||||
this.RoleViewComp.enemy = null;
|
||||
}
|
||||
}
|
||||
onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
if(selfCollider.group != otherCollider.group&&otherCollider.tag == 0){
|
||||
let scene =smc.map.MapView.scene.mapLayer!.node!
|
||||
let other_pos = otherCollider.node.getWorldPosition() ;
|
||||
let self_pos = this.node.getWorldPosition();
|
||||
// console.log("onPreSolve:",self_pos,other_pos);
|
||||
if(this.RoleViewComp.enemy==null){
|
||||
this.RoleViewComp.enemy = otherCollider.node;
|
||||
}else{
|
||||
if(this.RoleViewComp.enemy.isValid==false){
|
||||
this.RoleViewComp.enemy = otherCollider.node;
|
||||
}
|
||||
}
|
||||
if(Math.abs(other_pos.x-self_pos.x) < this.atk_range){
|
||||
this.RoleViewComp.is_atking = true;
|
||||
this.RoleViewComp.stop_cd = 0.1
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
|
||||
|
||||
|
||||
}
|
||||
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
||||
reset() {
|
||||
this.node.destroy();
|
||||
}
|
||||
}
|
||||
9
assets/script/game/Role/RoleRangComp.ts.meta
Normal file
9
assets/script/game/Role/RoleRangComp.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "d67dc462-2b08-4fe2-922c-502509f68ff4",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
* @LastEditors: dgflash
|
||||
* @LastEditTime: 2022-08-04 15:26:26
|
||||
*/
|
||||
import { Color, Component, EventTouch, sp, Vec3, _decorator } from "cc";
|
||||
import { Color, Component, EventTouch, sp, Vec3, _decorator ,Animation, AnimationClip, AnimationState} from "cc";
|
||||
import { LayerUtil } from "../../../../extensions/oops-plugin-framework/assets/core/utils/LayerUtil";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
import RoleSpineAnimator from "./RoleSpineAnimator";
|
||||
@@ -16,9 +16,12 @@ const { ccclass, property } = _decorator;
|
||||
*/
|
||||
@ccclass('RoleSpine')
|
||||
export class RoleSpine extends Component {
|
||||
@property({ type: RoleSpineAnimator, tooltip: '动画控制器' })
|
||||
animator: RoleSpineAnimator = null!;
|
||||
|
||||
@property({ type: Animation, tooltip: '动画控制器' })
|
||||
animator: Animation = null!;
|
||||
atk_clip: AnimationClip = null!;
|
||||
idle_clip: AnimationClip = null!;
|
||||
move_clip: AnimationClip = null!;
|
||||
dead_clip: AnimationClip = null!;
|
||||
private spine!: sp.Skeleton;
|
||||
|
||||
onLoad() {
|
||||
@@ -26,35 +29,39 @@ export class RoleSpine extends Component {
|
||||
|
||||
this.initAnimator();
|
||||
LayerUtil.setNodeLayer(LayerUtil.MAP, this.node);
|
||||
this.atk_clip = this.animator.clips[1];
|
||||
this.idle_clip = this.animator.clips[0];
|
||||
this.move_clip = this.animator.clips[2];
|
||||
this.dead_clip = this.animator.clips[3];
|
||||
let animation = this.animator.getComponent(Animation);
|
||||
animation.on(Animation.EventType.FINISHED, this.onAnimationEvent, this)
|
||||
}
|
||||
|
||||
/** 初始化动画 */
|
||||
protected initAnimator() {
|
||||
this.spine = this.animator.getComponent(sp.Skeleton)!;
|
||||
this.animator=this.node.getChildByName("hero").getComponent(Animation);
|
||||
console.log("role view comp init",this.animator);
|
||||
|
||||
}
|
||||
onAnimationEvent(type: Animation.EventType, state: AnimationState){
|
||||
// console.log("onAnimationEvent",type,state);
|
||||
if(type==Animation.EventType.FINISHED){
|
||||
if(state.name==this.atk_clip.name){
|
||||
this.idle();
|
||||
}
|
||||
}
|
||||
}
|
||||
atk() {
|
||||
this.spine.setAnimation(0, "atk2", false);
|
||||
if(!this.animator.getState(this.atk_clip.name).isPlaying){
|
||||
this.animator.play(this.atk_clip.name);
|
||||
}
|
||||
}
|
||||
|
||||
magic() {
|
||||
this.spine.setAnimation(0, "max", false);
|
||||
}
|
||||
setSkin(value: string): void {
|
||||
console.log("RoleSpine setSkin", value);
|
||||
this.spine.setSkin(value);
|
||||
}
|
||||
play(animName: string, loop: boolean): void {
|
||||
this.spine.setAnimation(0, animName, loop);
|
||||
}
|
||||
setAlpha(value: number): void {
|
||||
var color: Color = this.spine.color;
|
||||
color.a = 255 * (value / 1);
|
||||
this.spine.color = color;
|
||||
|
||||
}
|
||||
|
||||
setPos(value: Vec3): void {
|
||||
this.node.position = value;
|
||||
}
|
||||
|
||||
|
||||
checkTouch(event: EventTouch): boolean {
|
||||
return false;
|
||||
@@ -69,6 +76,8 @@ export class RoleSpine extends Component {
|
||||
}
|
||||
|
||||
idle() {
|
||||
|
||||
if(!this.animator.getState(this.idle_clip.name).isPlaying){
|
||||
this.animator.play(this.idle_clip.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* @LastEditTime: 2022-08-17 12:36:18
|
||||
*/
|
||||
|
||||
import { Vec3, v3,_decorator ,Collider2D,Contact2DType,IPhysics2DContact,Material,Sprite,ProgressBar, Prefab, instantiate} from "cc";
|
||||
import { Vec3, v3,_decorator ,Collider2D,Contact2DType,Label,Node,Prefab,instantiate,ProgressBar, Component, Material, Sprite,Animation, director} 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";
|
||||
@@ -18,6 +18,9 @@ import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/
|
||||
import { RandomManager } from "../../../../extensions/oops-plugin-framework/assets/core/common/random/RandomManager";
|
||||
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
||||
import { MoveToComp } from "../common/ecs/position/MoveTo";
|
||||
import { RoleBuffComp } from "./RoleBuffComp";
|
||||
import { RoleRangComp } from "./RoleRangComp";
|
||||
import { Tooltip } from "../skills/Tooltip";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 角色显示组件 */
|
||||
@@ -29,38 +32,90 @@ export class RoleViewComp extends CCComp {
|
||||
orginalFlashMaterial: Material;
|
||||
sprite: Sprite;
|
||||
/** 角色动画 */
|
||||
as: RoleSpine = null!;
|
||||
/** 角色属性 */
|
||||
hp: number = 1000;
|
||||
hp_max:number = 1000;
|
||||
power: number = 0;
|
||||
stop_cd:number = 0;
|
||||
atk_cd:number = 5;
|
||||
atk:number = 10;
|
||||
skill_uuid:number = 9003;
|
||||
@property(Node)
|
||||
BoxRang:Node =null!
|
||||
|
||||
as:RoleSpine =null!;
|
||||
buff:RoleBuffComp =null!
|
||||
is_role:boolean = false;
|
||||
enemy_pos:Vec3=null!;
|
||||
enemy:any=null!;
|
||||
/** 角色动画 */
|
||||
hero_uuid:number = 1001;
|
||||
hero_name : string = "hero";
|
||||
level:number =1;
|
||||
scale: number = 1; /** 角色阵营 1:hero -1 :monster */
|
||||
type: number = 1; /**角色类型 1:前排 2 后排 */
|
||||
state: number = 1; /** 状态 1:move ,2: act 3: stop */
|
||||
|
||||
hp: number = 100; /** 血量 */
|
||||
hp_max: number = 100; /** 最大血量 */
|
||||
hp_speed: number = 0; //每秒回复量
|
||||
|
||||
power: number = 0; /**能量**/
|
||||
power_max: number = 1200; /** 能量最大值 */
|
||||
power_speed: number = 1; //能量回复速度每0.1秒回复量
|
||||
|
||||
skill_name: string = "base"; //技能名称
|
||||
max_skill_name: string = "base"; //大技能名称
|
||||
skill_uuid:number = 9001;
|
||||
max_skill_uuid:number = 1001;
|
||||
shield:number = 0;
|
||||
atk: number = 10; /**攻击力 */
|
||||
// atk_speed: number = 1;
|
||||
atk_cd: number = 1.3; /**攻击速度 攻击间隔 */
|
||||
atk_time: number = 0; /** 冷却时间 */
|
||||
|
||||
speed: number = 100; /** 角色移动速度 */
|
||||
ospeed: number = 100; /** 角色初始速度 */
|
||||
Tpos: Vec3 = v3(0,-60,0);
|
||||
stop_cd: number = 0.5; /*停止倒计时*/
|
||||
|
||||
shield:number = 0; //护盾量
|
||||
shield_max:number = 200;
|
||||
skin="Character01";
|
||||
private atk_time:Timer = new Timer(1);
|
||||
shield_time:number = 0; //护盾持续时间
|
||||
|
||||
box_group:number = 2;
|
||||
atk_range:number = 150;
|
||||
private timer:Timer = new Timer(0.1); //计时器
|
||||
is_dead:boolean = false; //是否摧毁
|
||||
is_stop:boolean = false;
|
||||
is_atking:boolean = false;
|
||||
|
||||
onLoad() {
|
||||
this.as = this.getComponent(RoleSpine);
|
||||
this.buff=this.node.getComponent(RoleBuffComp);
|
||||
this.BoxRang = this.node.getChildByName("range_box");
|
||||
this.as = this.node.getComponent(RoleSpine);
|
||||
|
||||
}
|
||||
start () {
|
||||
// let x = RandomManager.instance.getRandomInt(1,9,2)
|
||||
// this.as.setSkin("Character0"+x);
|
||||
this.atk_time = new Timer(this.atk_cd);
|
||||
this.sprite = this.node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite);
|
||||
this.sprite = this.node.getChildByName("hero").getComponent(Sprite);
|
||||
this.node.getChildByName("top").setScale(this.scale,1);
|
||||
// this.node.getChildByName("atk").setScale(this.scale,1);
|
||||
// this.node.getChildByName("atk").getComponent(Label).string = this.atk.toString();
|
||||
// this.node.getChildByName("hp_max").setScale(this.scale,1);
|
||||
// this.node.getChildByName("hp_max").getComponent(Label).string=this.hp_max.toString();
|
||||
|
||||
|
||||
this.orginalFlashMaterial = this.sprite.getRenderMaterial(0);
|
||||
console.log("Role view start")
|
||||
|
||||
this.BoxRang.getComponent(RoleRangComp).box_group = this.box_group;
|
||||
this.BoxRang.getComponent(RoleRangComp).atk_range = this.atk_range
|
||||
// this.BoxRang.getComponent(RoleRangComp).offset_x = this.scale*smc.skills[this.skill_uuid].dis/3;
|
||||
// console.log("monseter ",this.BoxRang);
|
||||
|
||||
this.buff.group=this.box_group
|
||||
// 注册单个碰撞体的回调函数
|
||||
let collider = this.getComponent(Collider2D);
|
||||
collider.group = this.box_group;
|
||||
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);
|
||||
}
|
||||
}
|
||||
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
if(otherCollider.tag==BoxSet.SKILL_TAG){
|
||||
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D) {
|
||||
if(otherCollider.tag==BoxSet.SKILL_TAG &&selfCollider.tag!=BoxSet.SKILL_TAG){
|
||||
if(selfCollider.group != otherCollider.group){
|
||||
let skill = otherCollider.node.getComponent(SkillCom)!;
|
||||
// console.log('onPostSolve',skill);
|
||||
@@ -72,68 +127,235 @@ export class RoleViewComp extends CCComp {
|
||||
}
|
||||
}
|
||||
}
|
||||
// onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {}
|
||||
// onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {}
|
||||
// onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {}
|
||||
onEndContact (selfCollider: Collider2D, otherCollider: Collider2D) { }
|
||||
onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D) {
|
||||
if(selfCollider.group != otherCollider.group&&otherCollider.tag == 0){
|
||||
this.is_atking = true;
|
||||
this.stop_cd = 0.1;
|
||||
}
|
||||
|
||||
}
|
||||
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D) {
|
||||
if(selfCollider.group == otherCollider.group&&otherCollider.tag == 0&&selfCollider.tag == 0){
|
||||
let self_pos=selfCollider.node.getPosition();
|
||||
let other_pos=otherCollider.node.getPosition();
|
||||
// console.log('monster view group 相同');
|
||||
switch (selfCollider.group) {
|
||||
case BoxSet.HERO:
|
||||
if(self_pos.x < other_pos.x){
|
||||
this.stop_cd=0.1
|
||||
}
|
||||
break;
|
||||
case BoxSet.MONSTER:
|
||||
if(self_pos.x > other_pos.x){
|
||||
this.stop_cd=0.1
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
update(dt: number){
|
||||
if (this.atk_time.update(dt)) {
|
||||
this.toAtk(this.skill_uuid);
|
||||
if (this.timer.update(dt)) {
|
||||
this.power_change(this.power_speed)
|
||||
}
|
||||
|
||||
this.in_destroy();
|
||||
this.in_shield();
|
||||
this.in_stop(dt);
|
||||
this.in_atk(dt);
|
||||
this.move(dt);
|
||||
|
||||
}
|
||||
|
||||
add_hp(hp:number){
|
||||
console.log("role add hp",hp);
|
||||
move(dt: number){
|
||||
if(this.stop_cd > 0){
|
||||
return
|
||||
}
|
||||
if (this.scale === 1 && this.node.position.x >= 120) {
|
||||
return;
|
||||
}
|
||||
this.node.setPosition(this.node.position.x+dt*this.speed*this.scale, this.node.position.y, this.node.position.z);
|
||||
}
|
||||
setSkin(){
|
||||
this.as.setSkin(this.skin);
|
||||
power_change(power: number){
|
||||
this.power += power;
|
||||
if(this.power >= this.power_max){
|
||||
// this.as.maxSkill()
|
||||
this.scheduleOnce(()=>{
|
||||
this.do_max_skill();
|
||||
},0.5)
|
||||
this.power = 0
|
||||
}
|
||||
let power_progress= this.power/this.power_max;
|
||||
this.node.getChildByName("top").getChildByName("power").getComponent(ProgressBar)!.progress = power_progress;
|
||||
}
|
||||
reset() {
|
||||
this.node.destroy();
|
||||
}
|
||||
toAtk(uuid) {
|
||||
this.as.atk();
|
||||
this.scheduleOnce(()=>{
|
||||
this.shoot(this.skill_uuid);
|
||||
},1)
|
||||
}
|
||||
|
||||
shoot(skill_uuid:number){
|
||||
// console.log("monster shoot");
|
||||
let skill = ecs.getEntity<Skill>(Skill);
|
||||
let pos = v3(35,55)
|
||||
let scale = 1
|
||||
let x=32
|
||||
let pos = v3(35*this.scale,50)
|
||||
let scale = this.scale
|
||||
let speed =smc.skills[skill_uuid].speed;
|
||||
let dis = smc.skills[skill_uuid].dis;
|
||||
let atk = smc.skills[skill_uuid].atk+this.atk;
|
||||
let uuid = skill_uuid;
|
||||
skill.load(pos,speed,dis,scale,this.node,uuid,atk,2);
|
||||
let angle=0
|
||||
let t_pos:Vec3 = v3(0,0)
|
||||
if(this.enemy){
|
||||
t_pos = v3(this.enemy.position.x-this.node.position.x,this.enemy.position.y-this.node.position.y)
|
||||
angle = Math.atan2(t_pos.y,t_pos.x) * 180 / Math.PI;
|
||||
if(this.scale == -1){
|
||||
angle = angle +180
|
||||
}
|
||||
}else{
|
||||
t_pos=null
|
||||
}
|
||||
skill.load(pos,speed,dis,scale,this.node,skill_uuid,atk,angle,t_pos);
|
||||
// this.tooltip(3,smc.skills[skill_uuid].name,this.skill_uuid);
|
||||
}
|
||||
|
||||
in_atked() {
|
||||
this.sprite.setSharedMaterial(this.hitFlashMaterial, 0);
|
||||
this.scheduleOnce(() => {
|
||||
this.sprite.setSharedMaterial(this.orginalFlashMaterial, 0);
|
||||
}, 0.1);
|
||||
// var path = "game/skills/atked";
|
||||
// var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
// var node = instantiate(prefab);
|
||||
// let pos = v3(0,30)
|
||||
// node.setPosition(pos)
|
||||
// node.parent = this.node;
|
||||
//使用max_skill
|
||||
do_max_skill(){
|
||||
let skill = ecs.getEntity<Skill>(Skill);
|
||||
let x=32
|
||||
let pos = v3(-40*this.scale,BoxSet.MAX_SKILL_SY)
|
||||
let scale = this.scale
|
||||
let speed =smc.skills[this.max_skill_uuid].speed;
|
||||
let dis = smc.skills[this.max_skill_uuid].dis;
|
||||
let atk = smc.skills[this.max_skill_uuid].atk+this.atk;
|
||||
skill.load(pos,speed,dis,scale,this.node,this.max_skill_uuid,atk);
|
||||
this.tooltip(3,smc.skills[this.max_skill_uuid].name,this.max_skill_uuid);
|
||||
}
|
||||
in_atk(dt: number) {
|
||||
|
||||
if(this.atk_time >= this.atk_cd){
|
||||
if(this.is_atking){
|
||||
this.atk_time = 0;
|
||||
// console.log("atk_cd:",this.as);
|
||||
this.as.atk();
|
||||
this.scheduleOnce(()=>{
|
||||
this.shoot(this.skill_uuid);
|
||||
},0.4)
|
||||
}
|
||||
}else{
|
||||
this.atk_time += dt;
|
||||
}
|
||||
}
|
||||
in_shield(){
|
||||
let shield_progress= this.shield/this.shield_max;
|
||||
this.node.getChildByName("top").getChildByName("shield").getComponent(ProgressBar)!.progress = shield_progress;
|
||||
// if(this.shield <= 0){
|
||||
// this.node.getChildByName("shield").active=false
|
||||
// }else{
|
||||
// this.node.getChildByName("shield").active=true
|
||||
|
||||
// }
|
||||
}
|
||||
hp_change(hp: number){
|
||||
this.hp -= hp;
|
||||
if(this.is_dead){
|
||||
return;
|
||||
}
|
||||
let lhp=this.shield_change(hp);
|
||||
if(lhp == 0){
|
||||
return;
|
||||
}
|
||||
this.hp += lhp;
|
||||
this.tooltip(1,hp.toString());
|
||||
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;
|
||||
this.node.getChildByName("top").getChildByName("hp").getComponent(ProgressBar)!.progress = hp_progress;
|
||||
if(this.hp <= 0){
|
||||
console.log("dead");
|
||||
this.dead();
|
||||
this.is_dead = true;
|
||||
setTimeout(() => {
|
||||
this.ent.destroy();
|
||||
}, 15);
|
||||
}
|
||||
}
|
||||
add_hp(hp: number=0){
|
||||
console.log("hero 加血动画");
|
||||
this.tooltip(2,hp.toString());
|
||||
let hp_progress= this.hp/this.hp_max;
|
||||
this.node.getChildByName("top").getChildByName("hp").getComponent(ProgressBar)!.progress = hp_progress;
|
||||
}
|
||||
shield_change(hp: number){
|
||||
let ls=this.shield - hp;
|
||||
if(ls <= 0){
|
||||
this.shield = 0;
|
||||
return ls;
|
||||
}else{
|
||||
this.shield = ls;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
tooltip(type:number=1,value:string="",s_uuid:number=1001){
|
||||
// console.log("tooltip",type);
|
||||
let tip =ecs.getEntity<Tooltip>(Tooltip);
|
||||
let pos = this.node.getPosition();
|
||||
let node =this.node.parent
|
||||
pos.y=pos.y+60;
|
||||
tip.load(pos,type,value,s_uuid,node);
|
||||
}
|
||||
get_monster_pos(){
|
||||
return this.node.getPosition()
|
||||
}
|
||||
/** 静止时间 */
|
||||
in_stop (dt: number) {
|
||||
if(this.stop_cd > 0){
|
||||
this.stop_cd -= dt;
|
||||
if(this.stop_cd <= 0){
|
||||
this.stop_cd = 0;
|
||||
this.is_atking = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
in_destroy(){
|
||||
// switch (this.scale) {
|
||||
// case -1:
|
||||
// if(this.node.position.x < BoxSet.LETF_END){
|
||||
// this.toDestroy();
|
||||
// }
|
||||
// break;
|
||||
// case 1:
|
||||
// if(this.node.position.x > BoxSet.RIGHT_END){
|
||||
// this.toDestroy();
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
|
||||
in_atked() {
|
||||
|
||||
// var path = "game/skills/atked";
|
||||
// var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
// var node = instantiate(prefab);
|
||||
// let pos = v3(0,60)
|
||||
// node.setPosition(pos)
|
||||
// node.parent = this.node;
|
||||
|
||||
|
||||
this.sprite.setSharedMaterial(this.hitFlashMaterial, 0);
|
||||
this.scheduleOnce(() => {
|
||||
this.sprite.setSharedMaterial(this.orginalFlashMaterial, 0);
|
||||
}, 0.1);
|
||||
|
||||
|
||||
|
||||
}
|
||||
dead(){
|
||||
var path = "game/skills/dead";
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
node.setPosition(this.node.position.x,this.node.position.y+30,this.node.position.z);
|
||||
node.parent = this.node.parent;
|
||||
}
|
||||
toDestroy(){
|
||||
|
||||
}
|
||||
reset() {
|
||||
this.is_dead = false;
|
||||
// director.pause();
|
||||
this.node.destroy();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user