mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
update
This commit is contained in:
@@ -6,8 +6,14 @@ import GFSMBattle from "../fsm/base/GFSMBattle/GFSMBattle";
|
||||
import { GFSMBattleAmin } from "../fsm/base/GFSMBattle/GFSMBattleAmin";
|
||||
import { Vec2 } from "cc";
|
||||
import { v2 } from "cc";
|
||||
import { v3 } from "cc";
|
||||
import { GTactical } from "../../entity/GTactical";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
export enum GRoleAnimEvent{
|
||||
Attack = "attack", //普通攻击
|
||||
}
|
||||
|
||||
//角色基类
|
||||
export default abstract class GRoleBase<T> extends GObject<T>{
|
||||
|
||||
@@ -24,7 +30,23 @@ export default abstract class GRoleBase<T> extends GObject<T>{
|
||||
_isMirror:boolean = false;
|
||||
|
||||
//玩家攻击范围
|
||||
range:number = 10;
|
||||
range:number = 100;
|
||||
|
||||
//移动速度
|
||||
moveSpeed:number = 80;
|
||||
|
||||
//在阵容中的下标
|
||||
tacticalIndex:number;
|
||||
//阵容
|
||||
tactical:GTactical;
|
||||
//阵容位置
|
||||
_tacticalPos:Vec2;
|
||||
get tacticalPos(){ return this._tacticalPos}
|
||||
set tacticalPos(value:Vec2){ this._tacticalPos = value}
|
||||
|
||||
//血量
|
||||
blood:number = 100;
|
||||
fullBlood:number = 100;
|
||||
|
||||
get isMirror(){
|
||||
return this._isMirror;
|
||||
@@ -51,9 +73,24 @@ export default abstract class GRoleBase<T> extends GObject<T>{
|
||||
this.fsm = this.fsmCreate();
|
||||
//创建角色动画状态机
|
||||
this.fsmAnim = this.fsmAnimCreate();
|
||||
|
||||
//监听攻击
|
||||
this.fsmAnim.addEventListener(GRoleAnimEvent.Attack,this.onAttack.bind(this));
|
||||
|
||||
}
|
||||
|
||||
//攻击
|
||||
onAttack(){
|
||||
//敌人扣血
|
||||
this.fsm.enemy.onHit();
|
||||
}
|
||||
|
||||
//受击
|
||||
onHit(){
|
||||
this.blood--;
|
||||
}
|
||||
|
||||
|
||||
//创建一个状态机
|
||||
protected abstract fsmCreate():GFSMBattle;
|
||||
//创建一个动画状态机
|
||||
@@ -61,14 +98,26 @@ export default abstract class GRoleBase<T> extends GObject<T>{
|
||||
|
||||
onSyncUpdate(dt: number,frame:JNFrameInfo, input?: T){
|
||||
//更新状态机
|
||||
this.fsm && this.fsm.onUpdate(dt);
|
||||
this.fsmAnim && this.fsmAnim.onUpdate(dt);
|
||||
this.fsm && this.fsm.onUpdate(dt / 1000);
|
||||
this.fsmAnim && this.fsmAnim.onUpdate(dt / 1000);
|
||||
}
|
||||
|
||||
//普攻更新
|
||||
onAttackUpdate(dt:number){
|
||||
|
||||
this.fsmAnim.isAttack = true;
|
||||
//向目标点移动
|
||||
onMoveTarget(target:Vec2,dt:number){
|
||||
|
||||
//获取两个坐标差值向量
|
||||
let mins = this.v2World.subtract(target);
|
||||
let normal = this.v2World.subtract(target).normalize();
|
||||
|
||||
if(Vec2.len(normal) >= Vec2.len(mins)){
|
||||
this.node.setWorldPosition(Object.assign(v3(),target.clone()));
|
||||
return true;
|
||||
}else{
|
||||
//移动
|
||||
this.node.worldPosition = this.node.worldPosition.subtract(v3(normal.x*dt*this.moveSpeed,normal.y*dt*this.moveSpeed,0))
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -6,6 +6,9 @@ import GPVPMode, { GPVPModePlayerEnum } from "../../../PVP/GPVPMode";
|
||||
import { GTactical } from "../../../entity/GTactical";
|
||||
import { GFSMBattleAmin } from "../../fsm/base/GFSMBattle/GFSMBattleAmin";
|
||||
import { JNFrameInfo } from "../../../../../../extensions/ngame/assets/ngame/sync/frame/JNSyncFrame";
|
||||
import { Vec2 } from "cc";
|
||||
import { v2 } from "cc";
|
||||
import { ProgressBar } from "cc";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
export interface GDemoMessage{
|
||||
@@ -19,7 +22,6 @@ export default class GRolePVPEntity extends GRoleBase<GDemoMessage>{
|
||||
|
||||
//所属阵容
|
||||
_ones:GPVPModePlayerEnum;
|
||||
|
||||
get ones():GPVPModePlayerEnum{
|
||||
return this._ones;
|
||||
}
|
||||
@@ -33,11 +35,12 @@ export default class GRolePVPEntity extends GRoleBase<GDemoMessage>{
|
||||
this._ones = value;
|
||||
}
|
||||
|
||||
//攻击距离
|
||||
@property(ProgressBar)
|
||||
bloodVolume:ProgressBar;
|
||||
|
||||
//在阵容中的下标
|
||||
tacticalIndex:number;
|
||||
tactical:GTactical;
|
||||
onSyncLoad(){
|
||||
super.onSyncLoad();
|
||||
}
|
||||
|
||||
getClassName():string{return "GDemoMessage"}
|
||||
onSyncUpdate(dt: number,frame:JNFrameInfo, input?: GDemoMessage) {
|
||||
@@ -50,6 +53,9 @@ export default class GRolePVPEntity extends GRoleBase<GDemoMessage>{
|
||||
this.fsmAnim.isMove = input.isRun;
|
||||
}
|
||||
}
|
||||
|
||||
//更新血量显示
|
||||
this.bloodVolume.progress = this.blood / this.fullBlood;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +67,7 @@ export default class GRolePVPEntity extends GRoleBase<GDemoMessage>{
|
||||
}
|
||||
|
||||
protected fsmCreate(): GFSMPVP {
|
||||
return null;
|
||||
// return null;
|
||||
return new GFSMPVP(this);
|
||||
}
|
||||
protected fsmAnimCreate(): GFSMBattleAmin {
|
||||
|
Reference in New Issue
Block a user