This commit is contained in:
2024-08-18 23:38:55 +08:00
parent e8dbb9bab3
commit 8f57f57c1d
1004 changed files with 234067 additions and 16087 deletions

View File

@@ -37,7 +37,12 @@ export class RoleSpine extends Component {
atk() {
this.spine.setAnimation(0, "atk", false);
}
magic(){
this.spine.setAnimation(0, "magic", false);
}
setSkin(value: string): void {
console.log("RoleSpine setSkin", value);
@@ -52,13 +57,8 @@ export class RoleSpine extends Component {
this.spine.color = color;
}
setPos(value: Vec3): void {
this.node.position = value;
}
checkTouch(event: EventTouch): boolean {
return false;
}
onDestroy() {
this.node.destroy();

View File

@@ -16,23 +16,30 @@ const { ccclass, property, requireComponent, disallowMultiple } = _decorator;
@disallowMultiple
@requireComponent(sp.Skeleton)
export default class RoleSpineAnimator extends Component {
private animName: string = "idle";
private animName: string = "move";
private loop: boolean = true;
private spine!: sp.Skeleton;
mixTime:number= 0.2;
protected onLoad(): void {
this.spine = this.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 == "magic") {
this.spine.setAnimation(0, "move", true);
}
});
}
start() {
this.spine = this.getComponent(sp.Skeleton)!;
console.log("RoleSpineAnimator start smc.heros",smc.heros);
this.playAnimation(this.animName, this.loop);
}
lateUpdate(dt: number) {
}
getRandomInt(min: number, max: number): number {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
play(animName: string, loop: boolean) {
if (animName) {

View File

@@ -5,28 +5,108 @@
* @LastEditTime: 2022-08-17 12:36:18
*/
import { Vec3, _decorator } from "cc";
import { Vec3, _decorator ,v3,Collider2D,Contact2DType,IPhysics2DContact,Prefab,instantiate} 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 { oops } from "../../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { Timer } from "../../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
import { SkillCom } from "../../skills/SkillCom";
import { Skill } from "../../skills/Skill";
const { ccclass, property } = _decorator;
/** 角色显示组件 */
@ccclass('RoleViewComp') // 定义为 Cocos Creator 组件
@ecs.register('RoleView', false) // 定义为 ECS 组件
export class RoleViewComp extends CCComp {
/** 角色动画 */
as: RoleSpine = null!;
/** 角色控制器 */
hero_uuid:string = 'h001';
hero_name : string = "hero";
level:number =1;
state: number = 1; /** 状态 1move ,2: act 3: stop */
/** 视图层逻辑代码分离演示 */
hp: number = 100; /** 血量 */
hp_max: number = 100; /** 最大血量 */
hp_speed: number = 0; //回复速度
power: number = 0; /**能量**/
power_max: number = 100; /** 能量最大值 */
power_speed: number = 1; //能量回复速度每0.1秒回复量
skill_name: string = "base"; //技能名称
max_skill_name: string = "base"; //大技能名称
atk: number = 10; /**攻击力 */
// atk_speed: number = 1;
atk_cd: number = 2; /**攻击速度 攻击间隔 */
atk_time: number = 0; /** 冷却时间 */
stop_cd: number = 0; /*停止倒计时*/
is_dead:boolean = false; //是否摧毁
shield:number = 0; //护盾量
shield_time:number = 0; //护盾持续时间
private timer:Timer = new Timer(0.1); //计时器
onLoad() {
this.as = this.getComponent(RoleSpine);
}
protected start(): void {
let collider = this.getComponent(Collider2D);
if (collider) {
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
collider.on(Contact2DType.END_CONTACT, this.onEndContact, this);
collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
}
}
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
}
onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
// 只在两个碰撞体结束接触时被调用一次
}
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
if(otherCollider.group== BoxSet.HERO_SKILL || otherCollider.group== BoxSet.MONSTER_SKILL){
let skill = otherCollider.node.getComponent(SkillCom)!;
// console.log('onPostSolve',skill);
this.in_atked();
// this.hp_change(skill.atk);
}
}
update(dt: number){
if (this.timer.update(dt)) {
}
this.in_act(dt);
}
in_act(dt: number) {
if(this.atk_time >= this.atk_cd){
this.atk_time = 0;
// console.log("atk_cd:"+this.atk_cd);
this.as.atk();
this.load_skill(this.skill_name);
}
this.atk_time += dt;
}
load_skill(skill_name:string){
let skill = ecs.getEntity<Skill>(Skill);
let pos = v3(30,30)
let speed =400
let scale = 1
let range = 720
skill.load(pos,speed,range,scale,this.node,skill_name,this.atk);
}
in_atked() {
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;
}
reset() {
this.node.destroy();
}