假期修改
This commit is contained in:
@@ -55,7 +55,7 @@ export class Role extends ecs.Entity {
|
||||
var rv = node.getComponent(RoleViewComp)!;
|
||||
let role=smc.vm_data.role;
|
||||
rv.hero_uuid=uuid;
|
||||
rv.speed =rv.ospeed = 0;
|
||||
rv.speed =rv.ospeed = role.speed;
|
||||
rv.hero_name= "role";
|
||||
rv.hp= rv.hp_max = role.hp;
|
||||
rv.level = role.lv;
|
||||
|
||||
83
assets/script/game/Role/RoleAnm.ts
Normal file
83
assets/script/game/Role/RoleAnm.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* @Author: dgflash
|
||||
* @Date: 2022-08-04 15:08:35
|
||||
* @LastEditors: dgflash
|
||||
* @LastEditTime: 2022-08-04 15:26:26
|
||||
*/
|
||||
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";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/**
|
||||
* RPG SPINE角色模型
|
||||
*/
|
||||
@ccclass('RoleSpine')
|
||||
export class RoleSpine extends Component {
|
||||
@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() {
|
||||
// 角色控制组件
|
||||
|
||||
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.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() {
|
||||
if(!this.animator.getState(this.atk_clip.name).isPlaying){
|
||||
this.animator.play(this.atk_clip.name);
|
||||
}
|
||||
}
|
||||
|
||||
magic() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
checkTouch(event: EventTouch): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
this.node.destroy();
|
||||
}
|
||||
|
||||
walk() {
|
||||
|
||||
}
|
||||
|
||||
idle() {
|
||||
if(!this.animator.getState(this.idle_clip.name).isPlaying){
|
||||
this.animator.play(this.idle_clip.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
9
assets/script/game/Role/RoleAnm.ts.meta
Normal file
9
assets/script/game/Role/RoleAnm.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "d1d8d0c9-9cff-4d85-a359-628a29fd5191",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -16,68 +16,43 @@ const { ccclass, property } = _decorator;
|
||||
*/
|
||||
@ccclass('RoleSpine')
|
||||
export class RoleSpine extends Component {
|
||||
@property({ type: Animation, tooltip: '动画控制器' })
|
||||
animator: Animation = null!;
|
||||
atk_clip: AnimationClip = null!;
|
||||
idle_clip: AnimationClip = null!;
|
||||
move_clip: AnimationClip = null!;
|
||||
dead_clip: AnimationClip = null!;
|
||||
private loop: boolean = true;
|
||||
private spine!: sp.Skeleton;
|
||||
private default:string = "move";
|
||||
private atk_name: string = "atk";
|
||||
private move_name: string = "move";
|
||||
private max_name: string = "max";
|
||||
private idel_name: string = "idle";
|
||||
start() {
|
||||
this.spine.setAnimation(0, this.default, true);
|
||||
}
|
||||
mixTime:number= 0.2;
|
||||
|
||||
onLoad() {
|
||||
// 角色控制组件
|
||||
|
||||
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)
|
||||
this.spine = this.node.getChildByName("anm")!.getComponent(sp.Skeleton);
|
||||
this.spine.setEndListener(trackEntry => {
|
||||
var animationName = trackEntry.animation ? trackEntry.animation.name : "";
|
||||
console.log("[track %s][animation %s] end.", trackEntry.trackIndex, animationName);
|
||||
// if (animationName == "atk" || animationName== "max" ) {
|
||||
// this.spine.setAnimation(0, this.default, true);
|
||||
// }
|
||||
});
|
||||
}
|
||||
|
||||
/** 初始化动画 */
|
||||
protected initAnimator() {
|
||||
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() {
|
||||
if(!this.animator.getState(this.atk_clip.name).isPlaying){
|
||||
this.animator.play(this.atk_clip.name);
|
||||
}
|
||||
}
|
||||
|
||||
magic() {
|
||||
protected play(animName: string, loop: boolean) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
checkTouch(event: EventTouch): boolean {
|
||||
return false;
|
||||
atk(){
|
||||
|
||||
this.spine.setAnimation(0, this.atk_name, false);
|
||||
}
|
||||
idle(){
|
||||
this.spine.setAnimation(0, this.idel_name, true);
|
||||
}
|
||||
move(){
|
||||
this.spine.setAnimation(0, this.move_name, true);
|
||||
}
|
||||
max(){
|
||||
this.spine.setAnimation(0, this.max_name, false);
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
this.node.destroy();
|
||||
}
|
||||
|
||||
walk() {
|
||||
|
||||
}
|
||||
|
||||
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,Label,Node,Prefab,instantiate,ProgressBar, Component, Material, Sprite,Animation, director} from "cc";
|
||||
import { Vec3, v3,_decorator ,Collider2D,Contact2DType,Label,Node,Prefab,instantiate,ProgressBar, Component, Material, Sprite,Animation, director, Vertex} 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";
|
||||
@@ -30,6 +30,8 @@ export class RoleViewComp extends CCComp {
|
||||
@property(Material)
|
||||
hitFlashMaterial: Material;
|
||||
orginalFlashMaterial: Material;
|
||||
@property(Material)
|
||||
atkMaterial: Material;
|
||||
sprite: Sprite;
|
||||
/** 角色动画 */
|
||||
@property(Node)
|
||||
@@ -61,7 +63,11 @@ export class RoleViewComp extends CCComp {
|
||||
4:{uuid:8001,cd:2,alive:false},
|
||||
5:{uuid:8001,cd:2,alive:false},
|
||||
}
|
||||
buff_atks:any = [];
|
||||
buff_atk:number = 0;
|
||||
|
||||
atk: number = 10; /**攻击力 */
|
||||
mission_atk:number = 0;//局内攻击
|
||||
// atk_speed: number = 1;
|
||||
atk_cd: number = 1.3; /**攻击速度 攻击间隔 */
|
||||
atk_dis: number = 800;
|
||||
@@ -89,7 +95,7 @@ export class RoleViewComp extends CCComp {
|
||||
|
||||
}
|
||||
start () {
|
||||
this.sprite = this.node.getChildByName("hero").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();
|
||||
@@ -97,7 +103,9 @@ export class RoleViewComp extends CCComp {
|
||||
// this.node.getChildByName("hp_max").getComponent(Label).string=this.hp_max.toString();
|
||||
|
||||
|
||||
this.orginalFlashMaterial = this.sprite.getRenderMaterial(0);
|
||||
// this.orginalFlashMaterial = this.sprite.getRenderMaterial(0);
|
||||
|
||||
|
||||
|
||||
this.BoxRang.getComponent(RoleRangComp).box_group = this.box_group;
|
||||
this.BoxRang.getComponent(RoleRangComp).atk_range = this.atk_range
|
||||
@@ -129,30 +137,37 @@ export class RoleViewComp extends CCComp {
|
||||
}
|
||||
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;
|
||||
if(selfCollider.group == otherCollider.group&&selfCollider.tag==otherCollider.tag){
|
||||
|
||||
if(selfCollider.node.position.y < otherCollider.node.position.y){
|
||||
if(selfCollider.node.getSiblingIndex() < otherCollider.node.getSiblingIndex()){
|
||||
|
||||
selfCollider.node.setSiblingIndex(otherCollider.node.getSiblingIndex()+1)
|
||||
// console.log("onPreSolve b:"+selfCollider.node.uuid+":"+selfCollider.node.getSiblingIndex()+"/"+otherCollider.node.uuid+":"+otherCollider.node.getSiblingIndex());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
// 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
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@@ -161,27 +176,40 @@ export class RoleViewComp extends CCComp {
|
||||
|
||||
}
|
||||
this.in_destroy();
|
||||
this.in_shield();
|
||||
this.check_buff_atks(dt)
|
||||
this.in_shield(dt);
|
||||
this.in_stop(dt);
|
||||
this.in_atk(dt);
|
||||
this.move(dt);
|
||||
this.move();
|
||||
|
||||
}
|
||||
|
||||
move(dt: number){
|
||||
move(){
|
||||
if(this.stop_cd > 0){
|
||||
return
|
||||
}
|
||||
if (this.scale === 1 && this.node.position.x >= 120) {
|
||||
return;
|
||||
if(this.enemy){
|
||||
this.move_to(this.enemy.position)
|
||||
}else{
|
||||
this.move_to(v3(0,0));
|
||||
}
|
||||
}
|
||||
move_to(enemy:Vec3){
|
||||
// console.log("move to ",enemy);
|
||||
var move = this.ent.get(MoveToComp) || this.ent.add(MoveToComp);
|
||||
move.target = v3(enemy.x-100,enemy.y);
|
||||
move.node = this.node;
|
||||
move.speed = this.ospeed;
|
||||
if(enemy.x < this.node.position.x){
|
||||
this.node.setScale(-1,1);
|
||||
}else{
|
||||
this.node.setScale(1,1);
|
||||
}
|
||||
this.node.setPosition(this.node.position.x+dt*this.speed*this.scale, this.node.position.y, this.node.position.z);
|
||||
}
|
||||
|
||||
shoot(skill_uuid:number,y:number=0,x:number=0){
|
||||
// console.log("mon shoot");
|
||||
let skill = ecs.getEntity<Skill>(Skill);
|
||||
let atk = smc.skills[skill_uuid].atk+this.atk;
|
||||
let atk = smc.skills[skill_uuid].atk+this.atk+this.buff_atk+this.mission_atk;
|
||||
let {pos,t_pos}=this.get_enemy_pos()
|
||||
pos.y=pos.y + y
|
||||
pos.x=pos.x + x
|
||||
@@ -227,9 +255,6 @@ export class RoleViewComp extends CCComp {
|
||||
}else{
|
||||
this.atk_time += dt;
|
||||
}
|
||||
}
|
||||
in_shield(){
|
||||
|
||||
}
|
||||
hp_change(hp: number){
|
||||
if(this.is_dead){
|
||||
@@ -249,18 +274,67 @@ export class RoleViewComp extends CCComp {
|
||||
if(this.hp <= 0){
|
||||
this.dead();
|
||||
this.is_dead = true;
|
||||
this.ent.remove(MoveToComp)
|
||||
smc.vm_data.game_over = true;
|
||||
setTimeout(() => {
|
||||
this.ent.destroy();
|
||||
}, 15);
|
||||
}
|
||||
}
|
||||
heathed(){
|
||||
this.node.getChildByName("heathed").active=true
|
||||
}
|
||||
add_hp(hp: number=0){
|
||||
console.log("hero 加血动画");
|
||||
this.heathed();
|
||||
this.tooltip(2,hp.toString());
|
||||
let hp_progress= this.hp/this.hp_max;
|
||||
this.node.getChildByName("top").getChildByName("hp").getComponent(ProgressBar)!.progress = hp_progress;
|
||||
}
|
||||
add_atk(atk: number,time:number=0){
|
||||
if(time > 0){
|
||||
this.buff_atk=0
|
||||
let buff={atk:atk,time:time}
|
||||
this.buff_atks.push(buff);
|
||||
this.buff_atks.forEach((element: { atk: number; }) => {
|
||||
this.buff_atk += element.atk
|
||||
});
|
||||
}else{
|
||||
this.mission_atk += atk;
|
||||
}
|
||||
// this.sprite.setSharedMaterial(this.atkMaterial, 0);
|
||||
// this.scheduleOnce(() => {
|
||||
// this.sprite.setSharedMaterial(this.orginalFlashMaterial, 0);
|
||||
// }, 0.3);
|
||||
}
|
||||
|
||||
check_buff_atks(dt: number){
|
||||
for(let i=0;i<this.buff_atks.length;i++){
|
||||
let buff=this.buff_atks[i];
|
||||
buff.time -= dt;
|
||||
if(buff.time <= 0){
|
||||
this.buff_atk -= buff.atk
|
||||
this.buff_atks.splice(i,1);
|
||||
}
|
||||
}
|
||||
if(this.buff_atks.length <= 0){
|
||||
this.buff_atk = 0
|
||||
this.buff_icon_change("atk",false)
|
||||
}else{
|
||||
this.buff_icon_change("atk",true)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
buff_icon_change(icon:string,value:boolean){
|
||||
this.node.getChildByName("top").getChildByName("buff").getChildByName(icon).active=value
|
||||
}
|
||||
|
||||
|
||||
|
||||
add_shield(shield: number,time:number=0){
|
||||
this.shield =this.shield_max=shield
|
||||
this.shield_time = time;
|
||||
}
|
||||
shield_change(hp: number){
|
||||
let ls=this.shield - hp;
|
||||
if(ls <= 0){
|
||||
@@ -271,6 +345,29 @@ export class RoleViewComp extends CCComp {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
in_shield(dt: number){
|
||||
if(this.shield <= 0){
|
||||
this.shield_time=0
|
||||
this.node.getChildByName("shielded").active=false
|
||||
}else{
|
||||
this.node.getChildByName("shielded").active=true
|
||||
}
|
||||
if(this.shield_time <= 0){
|
||||
this.shield = this.shield_max=0;
|
||||
this.node.getChildByName("shielded").active=false
|
||||
return
|
||||
}
|
||||
if(this.shield_time > 0){
|
||||
this.shield_time -= dt;
|
||||
if(this.shield_time <= 0){
|
||||
this.shield_time = 0;
|
||||
this.shield = this.shield_max=0;
|
||||
// this.node.getChildByName("top").getChildByName("shield").active=false
|
||||
}
|
||||
// let shield_progress= this.shield/this.shield_max;
|
||||
// this.node.getChildByName("top").getChildByName("shield").getComponent(ProgressBar)!.progress = shield_progress;
|
||||
}
|
||||
}
|
||||
tooltip(type:number=1,value:string="",s_uuid:number=1001){
|
||||
// console.log("tooltip",type);
|
||||
let tip =ecs.getEntity<Tooltip>(Tooltip);
|
||||
@@ -309,18 +406,18 @@ export class RoleViewComp extends CCComp {
|
||||
|
||||
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;
|
||||
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);
|
||||
// this.sprite.setSharedMaterial(this.hitFlashMaterial, 0);
|
||||
// this.scheduleOnce(() => {
|
||||
// this.sprite.setSharedMaterial(this.orginalFlashMaterial, 0);
|
||||
// }, 0.1);
|
||||
|
||||
|
||||
|
||||
@@ -331,9 +428,6 @@ export class RoleViewComp extends CCComp {
|
||||
var node = instantiate(prefab);
|
||||
node.setPosition(this.node.position.x,this.node.position.y+30,this.node.position.z);
|
||||
node.parent = this.node.parent;
|
||||
}
|
||||
heathed(){
|
||||
|
||||
}
|
||||
toDestroy(){
|
||||
|
||||
|
||||
Reference in New Issue
Block a user