dd
This commit is contained in:
9
assets/script/game/monster/niu.meta
Normal file
9
assets/script/game/monster/niu.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "4cafacf8-51ca-4bd3-a5fb-c3b3147443d2",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
59
assets/script/game/monster/niu/Niu.ts
Normal file
59
assets/script/game/monster/niu/Niu.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
|
||||
/*
|
||||
* @Author: dgflash
|
||||
* @Date: 2021-11-18 17:47:56
|
||||
* @LastEditors: dgflash
|
||||
* @LastEditTime: 2022-08-04 15:43:04
|
||||
*/
|
||||
import { instantiate, Node, Prefab, Vec3 ,tween, v3,Collider2D,Contact2DType,PhysicsSystem2D,IPhysics2DContact} from "cc";
|
||||
import { UICallbacks } from "../../../../../extensions/oops-plugin-framework/assets/core/gui/layer/Defines";
|
||||
import { oops } from "../../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
||||
import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { UIID } from "../../common/config/GameUIConfig";
|
||||
import { smc } from "../../common/SingletonModuleComp";
|
||||
import { MonsterSpine } from "./../MonsterSpine";
|
||||
import { NiuViewComp } from "./NiuViewComp";
|
||||
|
||||
/** 角色实体 */
|
||||
@ecs.register(`Niu`)
|
||||
export class Niu extends ecs.Entity {
|
||||
// 数据层
|
||||
// 视图层
|
||||
NiuView!: NiuViewComp;
|
||||
// 移动
|
||||
|
||||
protected init() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
destroy(): void {
|
||||
this.remove(NiuViewComp);
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
/** 加载角色 */
|
||||
load(pos: Vec3 = Vec3.ZERO,speed:number = 100) {
|
||||
var path = "game/monster/niu";
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
var scene = smc.map.MapView.scene;
|
||||
node.parent = scene.entityLayer!.node!;
|
||||
var as = node.getComponent(MonsterSpine);
|
||||
node.setPosition(pos)
|
||||
|
||||
var mv = node.getComponent(NiuViewComp)!;
|
||||
mv.speed = speed;
|
||||
mv.ospeed = speed;
|
||||
mv.Tpos = v3(0,0,0);
|
||||
this.add(mv);
|
||||
smc.monsters_in.push({name:mv.ent.name,eid:mv.ent.eid,pos_x:0}),
|
||||
// node.setScale(-1, 1, 1);
|
||||
oops.message.dispatchEvent("monster_load",this)
|
||||
}
|
||||
|
||||
/** 移动(ECS System处理逻辑,分享功能独立的业务代码) */
|
||||
|
||||
|
||||
|
||||
}
|
||||
9
assets/script/game/monster/niu/Niu.ts.meta
Normal file
9
assets/script/game/monster/niu/Niu.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "56b8cdfc-ab72-4b6c-a182-7a06097cb4a8",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
76
assets/script/game/monster/niu/NiuViewComp.ts
Normal file
76
assets/script/game/monster/niu/NiuViewComp.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* @Author: dgflash
|
||||
* @Date: 2021-11-18 17:42:59
|
||||
* @LastEditors: dgflash
|
||||
* @LastEditTime: 2022-08-17 12:36:18
|
||||
*/
|
||||
|
||||
import { Vec3, _decorator ,tween, v3,Collider2D,Contact2DType,PhysicsSystem2D,IPhysics2DContact} 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 { MonsterSpine } from "./../MonsterSpine";
|
||||
import { Niu } from "./Niu";
|
||||
import { MonsterModelComp } from "./../MonsterModelComp";
|
||||
import { BoxSet } from "../../common/config/BoxSet";
|
||||
import { smc } from "../../common/SingletonModuleComp";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 角色显示组件 */
|
||||
@ccclass('NiuViewComp') // 定义为 Cocos Creator 组件
|
||||
@ecs.register('NiuView', false) // 定义为 ECS 组件
|
||||
export class NiuViewComp extends CCComp {
|
||||
/** 角色动画 */
|
||||
as: MonsterSpine = null!;
|
||||
speed: number = 100;
|
||||
ospeed: number = 100;
|
||||
Tpos: Vec3 = v3(0,-60,0);
|
||||
timer: number = 0;
|
||||
/** 视图层逻辑代码分离演示 */
|
||||
start () {
|
||||
|
||||
}
|
||||
|
||||
|
||||
onLoad() {
|
||||
this.as = this.getComponent(MonsterSpine);
|
||||
console.log('this.ent:',this);
|
||||
}
|
||||
|
||||
update(dt: number){
|
||||
if(this.timer > 0){
|
||||
this.timer -= dt;
|
||||
if(this.timer <= 0){
|
||||
this.speed = this.ospeed;
|
||||
this.timer = 0;
|
||||
}
|
||||
}
|
||||
if(this.node.position.x > -360){
|
||||
this.move(dt);
|
||||
}
|
||||
if(this.node.position.x < -300){
|
||||
console.log(this.node,this.ent)
|
||||
smc.monsters_in = smc.monsters_in.filter(element => element.eid !== this.ent.eid);
|
||||
this.node.destroy();
|
||||
}
|
||||
this.update_pos();
|
||||
|
||||
}
|
||||
move(dt: number){
|
||||
this.node.setPosition(this.node.position.x-dt*this.speed, this.node.position.y, this.node.position.z);
|
||||
}
|
||||
update_pos(){
|
||||
smc.monsters_in.forEach((element,index) => {
|
||||
|
||||
if(element.eid == this.ent.eid){
|
||||
console.log("index:"+index)
|
||||
element.pos_x = this.node.position.x;
|
||||
}
|
||||
});
|
||||
// console.log('smc.monsters_in',smc.monsters_in);
|
||||
}
|
||||
reset() {
|
||||
this.node.destroy();
|
||||
}
|
||||
|
||||
}
|
||||
9
assets/script/game/monster/niu/NiuViewComp.ts.meta
Normal file
9
assets/script/game/monster/niu/NiuViewComp.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "ab8e4649-6162-4e0b-80cc-baffecdf9733",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user