dd
This commit is contained in:
@@ -25,18 +25,17 @@ export class Main extends Root {
|
||||
protected async run() {
|
||||
smc.initialize = ecs.getEntity<Initialize>(Initialize);
|
||||
smc.monsters = [
|
||||
{prefab_path:'lang',name:'迅狼',speed:40},
|
||||
// {prefab_path:'hero',name:'火猴',speed:40},
|
||||
// {prefab_path:'lang',name:'m3',speed:40},
|
||||
// {prefab_path:'lang',name:'m4',speed:40},
|
||||
// {prefab_path:'lang',name:'m3',speed:40},
|
||||
// {prefab_path:'lang',name:'m4',speed:40},
|
||||
{prefab_path:'lang',name:'迅狼',speed:100},
|
||||
{prefab_path:'hero',name:'火猴',speed:45},
|
||||
{prefab_path:'lang',name:'m3',speed:40},
|
||||
{prefab_path:'lang',name:'m4',speed:40},
|
||||
{prefab_path:'lang',name:'m3',speed:40},
|
||||
{prefab_path:'lang',name:'m4',speed:40},
|
||||
]
|
||||
smc.heros = [
|
||||
// {prefab_path:'lang',name:'迅狼',speed:110},
|
||||
{prefab_path:'liubang',name:'刘邦',speed:40},
|
||||
// {prefab_path:'mulan',name:'花木兰',speed:40},
|
||||
// {prefab_path:'yinzheng',name:'嬴政',speed:40},
|
||||
{prefab_path:'lang',name:'迅狼',speed:110},
|
||||
{prefab_path:'liubang',name:'刘邦',speed:110},
|
||||
{prefab_path:'yinzheng',name:'嬴政',speed:110},
|
||||
]
|
||||
console.log("Game start");
|
||||
smc.vmAdd()
|
||||
|
||||
@@ -19,8 +19,8 @@ export enum BoxSet {
|
||||
//地图边界
|
||||
LETF_END = -400,
|
||||
RIGHT_END = 400,
|
||||
HERO_START = -309,
|
||||
MONSTER_START = 309,
|
||||
HERO_START = -500,
|
||||
MONSTER_START = 500,
|
||||
//游戏地平线
|
||||
GAME_LINE = 30,
|
||||
}
|
||||
20
assets/script/game/common/config/CardSet.ts
Normal file
20
assets/script/game/common/config/CardSet.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* @Author: dgflash
|
||||
* @Date: 2021-11-23 15:28:39
|
||||
* @LastEditors: dgflash
|
||||
* @LastEditTime: 2022-01-26 16:42:00
|
||||
*/
|
||||
|
||||
export const CardSet = {
|
||||
1001:{
|
||||
uuid:1001,
|
||||
name:'嬴政',
|
||||
level:1,
|
||||
prefab_path:'yinzheng',
|
||||
hp:100,
|
||||
power:100,
|
||||
speed:100,
|
||||
skill:{ }
|
||||
},
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "977105e0-d01b-402a-b649-080e33733218",
|
||||
"uuid": "ffda71d7-624d-40de-8c09-712edd44bfdc",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
@@ -7,7 +7,6 @@
|
||||
import { Color, Component, EventTouch, sp, Vec3, _decorator } from "cc";
|
||||
import { LayerUtil } from "../../../../extensions/oops-plugin-framework/assets/core/utils/LayerUtil";
|
||||
import { smc } from "../../../script/game/common/SingletonModuleComp";
|
||||
// import Charactor, { CharactorDirection, CharactorState } from "../../map/view/map/charactor/Charactor";
|
||||
import HeroSpineAnimator from "./HeroSpineAnimator";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
@@ -21,15 +20,11 @@ export class HeroSpine extends Component {
|
||||
animator: HeroSpineAnimator = null!;
|
||||
|
||||
private spine!: sp.Skeleton;
|
||||
// private charactor!: Charactor;
|
||||
|
||||
onLoad() {
|
||||
// 角色控制组件
|
||||
// this.charactor = this.addComponent(Charactor)!;
|
||||
|
||||
this.initAnimator();
|
||||
// this.setSkin("magic");
|
||||
// this.animator.play("idle", true);
|
||||
LayerUtil.setNodeLayer(LayerUtil.MAP, this.node);
|
||||
}
|
||||
|
||||
@@ -38,21 +33,6 @@ export class HeroSpine extends Component {
|
||||
this.spine = this.animator.getComponent(sp.Skeleton)!;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// setState(value: CharactorState): void {
|
||||
// switch (value) {
|
||||
// case CharactorState.Idle:
|
||||
// this.idle();
|
||||
// break;
|
||||
// case CharactorState.Run:
|
||||
// this.walk();
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
setSkin(value: string): void {
|
||||
console.log("HeroSpine setSkin", value);
|
||||
this.spine.setSkin(value);
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { _decorator } from "cc";
|
||||
import { _decorator,v3 } 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 { smc } from "../common/SingletonModuleComp";
|
||||
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
||||
|
||||
import { HeroCard } from "../monster/HeroCard";
|
||||
import { HeroCardViewComp } from "../monster/HeroCardViewComp";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 视图层对象 */
|
||||
@@ -12,6 +13,7 @@ const { ccclass, property } = _decorator;
|
||||
export class ControllerComp extends CCComp {
|
||||
/** 视图层逻辑代码分离演示 */
|
||||
start() {
|
||||
this.load_cards()
|
||||
// var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
|
||||
// this.on(ModuleEvent.Cmd, this.onHandler, this);
|
||||
}
|
||||
@@ -27,11 +29,30 @@ export class ControllerComp extends CCComp {
|
||||
smc.vm_data.shuaxin.min += smc.vm_data.shuaxin.speed*dt;
|
||||
if (smc.vm_data.shuaxin.min >= smc.vm_data.shuaxin.max) {
|
||||
smc.vm_data.shuaxin.min = 0;
|
||||
oops.message.dispatchEvent("do_add_hero",this)
|
||||
// oops.message.dispatchEvent("do_add_hero",this)
|
||||
this.load_cards()
|
||||
}
|
||||
}
|
||||
load_cards() {
|
||||
let old_cards = ecs.query(ecs.allOf(HeroCardViewComp))
|
||||
if (old_cards.length > 0) {
|
||||
old_cards.forEach(element => {
|
||||
element.destroy();
|
||||
});
|
||||
}
|
||||
// console.log(old_cards)
|
||||
let cards_node= this.node.getChildByName("cards")
|
||||
let x=0
|
||||
let y=0
|
||||
for (let i = 0; i < 5; i++) {
|
||||
let card = ecs.getEntity<HeroCard>(HeroCard);
|
||||
let pos = v3(x,y)
|
||||
card.load(pos,1001,cards_node);
|
||||
x=x+120
|
||||
}
|
||||
}
|
||||
/** 转场 */
|
||||
protected update(dt: number): void {
|
||||
protected update(dt: number): void {
|
||||
this.shuaxin(dt)
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import { Monster } from "../../monster/Monster";
|
||||
import { MapViewScene } from "./MapViewScene";
|
||||
import { Timer } from "../../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
|
||||
import { oops } from "../../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
||||
import { CardSet } from "../../common/config/CardSet";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('MapViewComp')
|
||||
@@ -34,7 +35,8 @@ export class MapViewComp extends CCComp {
|
||||
this.addMonster()
|
||||
}
|
||||
private on_do_add_hero(event: string, args: any) {
|
||||
this.addHero()
|
||||
console.log("do_add_hero",args.HeroCardView)
|
||||
this.addHero(args.HeroCardView.card_uid)
|
||||
this.addMonster()
|
||||
|
||||
}
|
||||
@@ -74,18 +76,15 @@ export class MapViewComp extends CCComp {
|
||||
}
|
||||
}
|
||||
/** 添加玩家 */
|
||||
private addHero() {
|
||||
private addHero(uuid:number=1001) {
|
||||
this.scene.node.active = true
|
||||
if(smc.heros.length>0) {
|
||||
let hero = ecs.getEntity<Hero>(Hero);
|
||||
let pos = v3(BoxSet.HERO_START,BoxSet.GAME_LINE)
|
||||
let speed =smc.heros[0].speed
|
||||
let camp = 1
|
||||
let prefab_path = smc.heros[0].prefab_path
|
||||
let name = smc.heros[0].name
|
||||
hero.load(pos,speed,camp,prefab_path,name);
|
||||
smc.heros.splice(0,1)
|
||||
}
|
||||
let hero = ecs.getEntity<Hero>(Hero);
|
||||
let pos = v3(BoxSet.HERO_START,BoxSet.GAME_LINE)
|
||||
let speed =CardSet[uuid].speed
|
||||
let camp = 1
|
||||
let prefab_path = CardSet[uuid].prefab_path
|
||||
let name = CardSet[uuid].name
|
||||
hero.load(pos,speed,camp,prefab_path,name);
|
||||
}
|
||||
private addMonster() {
|
||||
this.scene.node.active = true
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "f58752f0-7320-4a2f-b7a3-d4d59e42c1f6",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
@@ -1,146 +0,0 @@
|
||||
import { Component, game, Vec3, _decorator } from 'cc';
|
||||
import { MapViewScene } from '../../MapViewScene';
|
||||
import RoadNode from '../road/RoadNode';
|
||||
import { RoadType } from '../road/RoadType';
|
||||
import { ICharactorClip } from './ICharactorClip';
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
export enum CharactorState {
|
||||
Idle = 0,
|
||||
Run = 1
|
||||
}
|
||||
|
||||
export enum CharactorDirection {
|
||||
none = -1,
|
||||
bottom = 0,
|
||||
left_bottom = 1,
|
||||
left = 2,
|
||||
left_up = 3,
|
||||
up = 4,
|
||||
right_up = 5,
|
||||
right = 6,
|
||||
right_bottom = 7
|
||||
}
|
||||
|
||||
/**
|
||||
* 场景角色
|
||||
*/
|
||||
@ccclass('Charactor')
|
||||
export default class Charactor extends Component {
|
||||
/** 优化后的路点移动 */
|
||||
static WalkRoadNode: string = "WalkRoadNode";
|
||||
/** 移动到新的一个格子路点 */
|
||||
static NextRoadNode: string = "NextRoadNode";
|
||||
|
||||
private _direction: CharactorDirection = CharactorDirection.bottom;
|
||||
public get direction(): CharactorDirection {
|
||||
return this._direction;
|
||||
}
|
||||
public set direction(value: CharactorDirection) {
|
||||
this._direction = value;
|
||||
// this.clip.setDirection(value);
|
||||
}
|
||||
|
||||
private _state: CharactorState = 0;
|
||||
public get state(): CharactorState {
|
||||
return this._state;
|
||||
}
|
||||
public set state(value: CharactorState) {
|
||||
this._state = value;
|
||||
// this.clip.setState(value);
|
||||
}
|
||||
|
||||
private _alpha: number = 1;
|
||||
public get alpha(): number {
|
||||
return this._alpha;
|
||||
}
|
||||
public set alpha(value: number) {
|
||||
this._alpha = value;
|
||||
// this.clip.setAlpha(value);
|
||||
}
|
||||
|
||||
private _zIndex: number = 0;
|
||||
/** 深度排序 */
|
||||
public get zIndex(): number {
|
||||
return this._zIndex;
|
||||
}
|
||||
|
||||
private _pos!: Vec3;
|
||||
/** 玩家地图上的位置 */
|
||||
public get pos(): Vec3 {
|
||||
return this._pos;
|
||||
}
|
||||
public set pos(value: Vec3) {
|
||||
this._pos = value;
|
||||
// this.clip.setPos(value);
|
||||
}
|
||||
|
||||
public sceneMap: MapViewScene = null!;
|
||||
public clip!: ICharactorClip;
|
||||
public moving: boolean = false;
|
||||
public joystic: boolean = false;
|
||||
public joystic_dir: Vec3 = new Vec3();
|
||||
public moveSpeed: number = 200;
|
||||
|
||||
/**
|
||||
* 玩家当前所站在的地图节点
|
||||
*/
|
||||
private _currentNode!: RoadNode;
|
||||
private _moveAngle: number = 0;
|
||||
private _roadNodeArr: RoadNode[] = [];
|
||||
private _nodeIndex: number = 0;
|
||||
|
||||
start() {
|
||||
this.direction = CharactorDirection.bottom;
|
||||
this.state = CharactorState.Idle;
|
||||
}
|
||||
|
||||
update(dt: number) {
|
||||
|
||||
}
|
||||
|
||||
joystick(dir: Vec3) {
|
||||
if (this.moving) {
|
||||
this.moving = false;
|
||||
this._roadNodeArr.splice(0, this._roadNodeArr.length);
|
||||
}
|
||||
|
||||
if (dir.strictEquals(Vec3.ZERO)) {
|
||||
this.joystic = false;
|
||||
this.state = CharactorState.Idle;
|
||||
}
|
||||
else {
|
||||
this.joystic = true;
|
||||
this.state = CharactorState.Run;
|
||||
}
|
||||
this.joystic_dir.set(dir);
|
||||
}
|
||||
|
||||
public updateZIndex() {
|
||||
this._zIndex = this.sceneMap.mapLayer!.height - this._pos.y;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private walk() {
|
||||
if (this._nodeIndex < this._roadNodeArr.length - 1) {
|
||||
this._nodeIndex++;
|
||||
|
||||
// 移动一个路点事件
|
||||
this.node.emit(Charactor.WalkRoadNode, this._roadNodeArr[this._nodeIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
public move() {
|
||||
this.joystic = false;
|
||||
|
||||
this.moving = true;
|
||||
this.state = CharactorState.Run;
|
||||
}
|
||||
|
||||
public stop() {
|
||||
this.moving = false;
|
||||
this.state = CharactorState.Idle;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
import { EventTouch, Vec3 } from "cc";
|
||||
import { CharactorDirection, CharactorState } from "./Charactor";
|
||||
|
||||
export interface ICharactorClip {
|
||||
setDirection(value: CharactorDirection): void;
|
||||
setState(value: CharactorState): void;
|
||||
setAlpha(value: number): void;
|
||||
setPos(value: Vec3): void;
|
||||
checkTouch(event: EventTouch): boolean;
|
||||
}
|
||||
@@ -1,230 +0,0 @@
|
||||
import { CCBoolean, CCFloat, CCInteger, Component, Rect, Size, Sprite, SpriteFrame, Texture2D, UITransform, Vec2, _decorator } from 'cc';
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/**
|
||||
* 动画播放器
|
||||
* @author 落日故人 QQ 583051842
|
||||
*
|
||||
*/
|
||||
@ccclass('MovieClip')
|
||||
export default class MovieClip extends Component {
|
||||
/** Sprite渲染器 */
|
||||
protected m_sprite: Sprite | null = null;;
|
||||
|
||||
/** 动画计时间隔 每隔0.1s更新一帧 */
|
||||
protected timer: number = 0.1;
|
||||
|
||||
/** 播放 时间 间隔 */
|
||||
@property({ type: CCFloat })
|
||||
public interval: number = 0.1;
|
||||
|
||||
/** 贴图文件名 */
|
||||
@property({ type: Texture2D })
|
||||
public texture: Texture2D | null = null;
|
||||
|
||||
/** 播放次数 */
|
||||
@property({ type: CCInteger })
|
||||
public playTimes: number = 0;
|
||||
|
||||
@property({ type: CCInteger })
|
||||
public row: number = 4;
|
||||
|
||||
/** 图片切割成几列 */
|
||||
@property({ type: CCInteger })
|
||||
public col: number = 4;
|
||||
|
||||
@property({ type: CCInteger })
|
||||
public rowIndex: number = 0;
|
||||
|
||||
@property(CCBoolean)
|
||||
public isAll: boolean = false;
|
||||
|
||||
@property(CCBoolean)
|
||||
public autoPlayOnLoad: boolean = true;
|
||||
|
||||
/** 播放完自动销毁 */
|
||||
@property(CCBoolean)
|
||||
public autoDestroy: boolean = false;
|
||||
|
||||
@property(CCFloat)
|
||||
public begin: number = 0;
|
||||
|
||||
@property(CCFloat)
|
||||
public end: number = 0;
|
||||
|
||||
/** 动画帧数 */
|
||||
public totalFrame: number = 8;
|
||||
|
||||
/** 当前帧数 */
|
||||
public currentFrame: number = 0;
|
||||
|
||||
/** 当前播放了第几次 */
|
||||
private currentTimes: number = 0;
|
||||
|
||||
/** 影片是否在跑动中 */
|
||||
public running: boolean = true;
|
||||
|
||||
//private _direction:number = 1;
|
||||
|
||||
private _playIndex: number = 0;
|
||||
private _pieceWidth: number = 0;
|
||||
private _pieceHeight: number = 0;
|
||||
private _bitmapArr: SpriteFrame[][] = [];
|
||||
|
||||
onLoad() {
|
||||
//this. m_clips = new SpriteFrame[this.row][this.col];
|
||||
//Texture2D tex = Resources.Load<Texture2D>("Image/Avatar/" + m_sprite_name);
|
||||
|
||||
//this.begin = 0;
|
||||
|
||||
if (this.end == 0) {
|
||||
this.end = this.col;
|
||||
}
|
||||
|
||||
this.rowIndex = this.clamp(this.rowIndex, 0, this.row - 1);
|
||||
|
||||
this._pieceWidth = this.texture!.width / this.col;
|
||||
this._pieceHeight = this.texture!.height / this.row;
|
||||
|
||||
this.m_sprite = this.getComponent(Sprite);
|
||||
|
||||
if (!this.m_sprite) {
|
||||
this.m_sprite = this.addComponent(Sprite);
|
||||
}
|
||||
|
||||
for (var i = 0; i < this.row; i++) {
|
||||
this._bitmapArr[i] = [];
|
||||
|
||||
for (var j = 0; j < this.col; j++) {
|
||||
var spriteFrame: SpriteFrame = new SpriteFrame();
|
||||
spriteFrame.texture = this.texture!;
|
||||
spriteFrame.rect = new Rect(j * this._pieceWidth, i * this._pieceHeight, this._pieceWidth, this._pieceHeight);
|
||||
spriteFrame.rotated = false;
|
||||
spriteFrame.offset = new Vec2(0, 0);
|
||||
spriteFrame.originalSize = new Size(this._pieceWidth, this._pieceHeight);
|
||||
this._bitmapArr[i][j] = spriteFrame;
|
||||
}
|
||||
}
|
||||
|
||||
this.m_sprite!.spriteFrame = this._bitmapArr[this.rowIndex][0];
|
||||
this.m_sprite!.spriteFrame.width
|
||||
|
||||
var uiTransform = this.getComponent(UITransform);
|
||||
|
||||
if (uiTransform) {
|
||||
uiTransform.width = this._pieceWidth;
|
||||
uiTransform.height = this._pieceHeight;
|
||||
}
|
||||
|
||||
this.timer = 0;
|
||||
this.running = this.autoPlayOnLoad;
|
||||
}
|
||||
|
||||
update(dt: number) {
|
||||
if (!this.running)
|
||||
return;
|
||||
|
||||
if (this.playTimes != 0 && this.currentTimes == this.playTimes) {
|
||||
this.running = false;
|
||||
return;
|
||||
}
|
||||
|
||||
this.timer -= dt;
|
||||
|
||||
if (this.timer <= 0) {
|
||||
this.timer = this.interval;
|
||||
this.currentFrame = this.currentFrame % this.col;
|
||||
|
||||
this.playAction();
|
||||
|
||||
this.currentFrame++;
|
||||
if (this.currentFrame == this.col) {
|
||||
|
||||
if (this.isAll) {
|
||||
this.rowIndex++;
|
||||
if (this.rowIndex == this.row) {
|
||||
this.currentTimes++;
|
||||
this.node.emit("completeTimes");
|
||||
|
||||
if (this.playTimes != 0 && this.currentTimes == this.playTimes) {
|
||||
this.node.emit("complete");
|
||||
|
||||
if (this.autoDestroy) {
|
||||
this.node.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.rowIndex %= this.row;
|
||||
}
|
||||
else {
|
||||
this.currentTimes++;
|
||||
this.node.emit("completeTimes");
|
||||
|
||||
if (this.playTimes != 0 && this.currentTimes == this.playTimes) {
|
||||
this.node.emit("complete");
|
||||
|
||||
if (this.autoDestroy) {
|
||||
this.node.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private playAction() {
|
||||
this.rowIndex = this.clamp(this.rowIndex, 0, this.row - 1);
|
||||
this._playIndex = this._playIndex % (this.end - this.begin) + this.begin;
|
||||
this.m_sprite!.spriteFrame = this._bitmapArr[this.rowIndex][this._playIndex];
|
||||
//this.m_sprite.spriteFrame.setRect(this.rect);
|
||||
|
||||
this._playIndex++;
|
||||
}
|
||||
|
||||
/** 播放影片 */
|
||||
public play() {
|
||||
this.running = true;
|
||||
}
|
||||
|
||||
/** 停止播放影片 */
|
||||
public stop() {
|
||||
this.running = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳帧播放
|
||||
* @param frame 帧
|
||||
*/
|
||||
public gotoAndPlay(frame: number) {
|
||||
this.running = true;
|
||||
this._playIndex = frame;
|
||||
this._playIndex = this.clamp(this._playIndex, 0, this.col - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳帧停止
|
||||
* @param frame 帧
|
||||
*/
|
||||
public gotoAndStop(frame: number) {
|
||||
this.running = false;
|
||||
|
||||
this._playIndex = frame;
|
||||
this._playIndex = this.clamp(this._playIndex, 0, this.col - 1);
|
||||
|
||||
this.m_sprite!.spriteFrame = this._bitmapArr[this.rowIndex][this._playIndex];
|
||||
}
|
||||
|
||||
public clamp(value: number, minLimit: number, maxLimit: number) {
|
||||
if (value < minLimit) {
|
||||
return minLimit;
|
||||
}
|
||||
|
||||
if (value > maxLimit) {
|
||||
return maxLimit;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -25,11 +25,7 @@ export default class EntityLayer extends Component {
|
||||
// this.node.children.sort(this.zIndexSort);
|
||||
}
|
||||
|
||||
// private zIndexSort(a: Node, b: Node) {
|
||||
// let a_zIndex = a.getComponent(Charactor)!.zIndex;
|
||||
// let b_zIndex = b.getComponent(Charactor)!.zIndex;
|
||||
// return a_zIndex - b_zIndex;
|
||||
// }
|
||||
|
||||
|
||||
public clear() {
|
||||
this.node.children.forEach(n => {
|
||||
|
||||
@@ -14,102 +14,19 @@ const { ccclass, property } = _decorator;
|
||||
*/
|
||||
@ccclass('MapLayer')
|
||||
export default class MapLayer extends Component {
|
||||
/** 切割小图片集 */
|
||||
private _sliceImgDic: { [key: string]: Sprite | null } = {};
|
||||
private _mapParams: MapParams | null = null;
|
||||
|
||||
|
||||
@property(Sprite)
|
||||
private bgImg: Sprite | null = null;
|
||||
|
||||
public init(mapParams: MapParams): void {
|
||||
this._mapParams = mapParams;
|
||||
|
||||
if (!this.bgImg) {
|
||||
var bgNode: Node = new Node();
|
||||
this.node.addChild(bgNode);
|
||||
bgNode.layer = Layers.Enum.UI_2D;
|
||||
|
||||
this.bgImg = bgNode.addComponent(Sprite);
|
||||
this.bgImg.sizeMode = Sprite.SizeMode.RAW;
|
||||
bgNode.getComponent(UITransform)!.anchorX = 0;
|
||||
bgNode.getComponent(UITransform)!.anchorY = 0;
|
||||
}
|
||||
|
||||
var spriteFrame: SpriteFrame = new SpriteFrame();
|
||||
spriteFrame.texture = this._mapParams.bgTex!;
|
||||
|
||||
this.bgImg.spriteFrame = spriteFrame;
|
||||
|
||||
//如果是马赛克小地图,则需要把小地图缩放成原始地图一样大小
|
||||
if (mapParams.mapLoadModel == MapLoadModel.slices) {
|
||||
this.bgImg.getComponent(UITransform)!.width = mapParams.mapWidth;
|
||||
this.bgImg.getComponent(UITransform)!.height = mapParams.mapHeight;
|
||||
}
|
||||
|
||||
this.getComponent(UITransform)!.width = this.width;
|
||||
this.getComponent(UITransform)!.height = this.height;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据视图区域加载小地图
|
||||
* @param px 滚动视图左上角的x坐标
|
||||
* @param py 滚动视图左上角的y坐标
|
||||
*
|
||||
*/
|
||||
public loadSliceImage(px: number, py: number): void {
|
||||
// var iy1: number = Math.floor(py / this._mapParams!.sliceHeight);
|
||||
// var iy2: number = Math.floor((py + this._mapParams!.viewHeight) / this._mapParams!.sliceHeight);
|
||||
|
||||
// var jx1: number = Math.floor(px / this._mapParams!.sliceWidth);
|
||||
// var jx2: number = Math.floor((px + this._mapParams!.viewWidth) / this._mapParams!.sliceWidth);
|
||||
|
||||
// var key: string;
|
||||
|
||||
// for (var i: number = iy1; i <= iy2; i++) {
|
||||
// for (var j: number = jx1; j <= jx2; j++) {
|
||||
// key = (i + 1) + "_" + (j + 1); // 图片的索引是从1开始的,所以要加1
|
||||
|
||||
// if (!this._sliceImgDic[key]) {
|
||||
// let bitmap: Sprite = this.getSliceSprite(key)
|
||||
// this._sliceImgDic[key] = bitmap;
|
||||
// this.node.addChild(bitmap.node);
|
||||
// bitmap.node.position = new Vec3(j * this._mapParams!.sliceWidth, i * this._mapParams!.sliceHeight, 0)
|
||||
|
||||
// // var path: string = `maps/${this._mapParams!.bgName}/${this._mapParams!.bgName}/slices/${key}/texture`;
|
||||
// // oops.res.load("remote", path, Texture2D, (error: Error | null, tex: Texture2D) => {
|
||||
// var path: string = smc.map.MapModel.getResContentSlices(this._mapParams!.bgName, key);
|
||||
// oops.res.load(path, Texture2D, (error: Error | null, tex: Texture2D) => {
|
||||
// if (error) {
|
||||
// console.error(error);
|
||||
// }
|
||||
// var spriteFrame: SpriteFrame = new SpriteFrame();
|
||||
// spriteFrame.texture = tex;
|
||||
// bitmap.spriteFrame = spriteFrame;
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
private getSliceSprite(name: string) {
|
||||
var node: Node = new Node(name);
|
||||
node.layer = LayerUtil.MAP.mask; // Layers.Enum.UI_2D;
|
||||
var sprite: Sprite = node.addComponent(Sprite);
|
||||
sprite.sizeMode = Sprite.SizeMode.RAW;
|
||||
node.getComponent(UITransform)!.anchorX = 0;
|
||||
node.getComponent(UITransform)!.anchorY = 0;
|
||||
return sprite;
|
||||
}
|
||||
|
||||
public clear(): void {
|
||||
this.bgImg!.spriteFrame = null;
|
||||
|
||||
for (var key in this._sliceImgDic) {
|
||||
var sprite: Sprite | null = this._sliceImgDic[key];
|
||||
sprite && sprite.node.destroy();
|
||||
this._sliceImgDic[key] = null;
|
||||
delete this._sliceImgDic[key];
|
||||
}
|
||||
}
|
||||
|
||||
public get bgImage(): Sprite {
|
||||
@@ -121,7 +38,6 @@ export default class MapLayer extends Component {
|
||||
return this.bgImg.getComponent(UITransform)!.width;
|
||||
}
|
||||
|
||||
return this._mapParams!.viewWidth;
|
||||
}
|
||||
|
||||
public get height(): number {
|
||||
@@ -129,6 +45,5 @@ export default class MapLayer extends Component {
|
||||
return this.bgImg.getComponent(UITransform)!.height;
|
||||
}
|
||||
|
||||
return this._mapParams!.viewHeight;
|
||||
}
|
||||
}
|
||||
@@ -42,11 +42,7 @@ export default class SkillLayer extends Component {
|
||||
// this.node.children.sort(this.zIndexSort);
|
||||
}
|
||||
|
||||
// private zIndexSort(a: Node, b: Node) {
|
||||
// let a_zIndex = a.getComponent(Charactor)!.zIndex;
|
||||
// let b_zIndex = b.getComponent(Charactor)!.zIndex;
|
||||
// return a_zIndex - b_zIndex;
|
||||
// }
|
||||
|
||||
|
||||
public clear() {
|
||||
this.node.children.forEach(n => {
|
||||
|
||||
@@ -36,7 +36,7 @@ export class Hero extends ecs.Entity {
|
||||
/** 加载角色 */
|
||||
load(pos: Vec3 = Vec3.ZERO,speed:number = 100,camp:number = 1,prefab_path:string = "monster",name:string="hero") {
|
||||
// var path = "game/monster/"+prefab_path;
|
||||
var path = "game/monster/hero";
|
||||
var path = "game/heros/hero";
|
||||
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
|
||||
@@ -11,7 +11,8 @@ import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/O
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { UIID } from "../common/config/GameUIConfig";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
|
||||
import{HeroCardViewComp} from "./HeroCardViewComp";
|
||||
import { CardSet } from "../common/config/CardSet";
|
||||
/** 角色实体 */
|
||||
@ecs.register(`HeroCard`)
|
||||
export class HeroCard extends ecs.Entity {
|
||||
@@ -27,28 +28,31 @@ export class HeroCard extends ecs.Entity {
|
||||
}
|
||||
|
||||
destroy(): void {
|
||||
// this.remove(MonsterViewComp);
|
||||
this.remove(HeroCardViewComp);
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
/** 加载角色 */
|
||||
load(pos: Vec3 = Vec3.ZERO,speed:number = 100,camp:number = 1,prefab_path:string = "monster",name:string="hero") {
|
||||
load(pos: Vec3 = Vec3.ZERO,uuid:number=1001,parent:Node) {
|
||||
// var path = "game/monster/"+prefab_path;
|
||||
var path = "game/monster/hero";
|
||||
|
||||
var path = "game/heros/cards/hero_card";
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
var scene = smc.map.MapView.scene;
|
||||
node.parent = scene.entityLayer!.node!;
|
||||
node.getChildByName("avatar").setScale(node.getChildByName("avatar").scale.x*camp, node.getChildByName("avatar").scale.y, node.getChildByName("avatar").scale.z);
|
||||
node.parent = parent;
|
||||
// node.getChildByName("avatar").setScale(node.getChildByName("avatar").scale.x*camp, node.getChildByName("avatar").scale.y, node.getChildByName("avatar").scale.z);
|
||||
node.setPosition(pos)
|
||||
// console.log(node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite))
|
||||
const url = 'game/heros/hero/'+prefab_path+'/spriteFrame';
|
||||
resources.load(url, SpriteFrame, (err: any, spriteFrame) => {
|
||||
const sprite = node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite);
|
||||
|
||||
var hcv = node.getComponent(HeroCardViewComp)!;
|
||||
hcv.card_name=CardSet[uuid].name
|
||||
hcv.card_uid=uuid
|
||||
this.add(hcv);
|
||||
// // console.log(node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite))
|
||||
// const url = 'game/heros/hero/'+prefab_path+'/spriteFrame';
|
||||
// resources.load(url, SpriteFrame, (err: any, spriteFrame) => {
|
||||
// const sprite = node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite);
|
||||
|
||||
sprite.spriteFrame = spriteFrame;
|
||||
});
|
||||
// sprite.spriteFrame = spriteFrame;
|
||||
// });
|
||||
}
|
||||
|
||||
|
||||
|
||||
77
assets/script/game/monster/HeroCardViewComp.ts
Normal file
77
assets/script/game/monster/HeroCardViewComp.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import { _decorator ,Vec2,NodeEventType,EventTouch} 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 { data } from "../data/data";
|
||||
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 视图层对象 */
|
||||
@ccclass('HeroCardViewComp')
|
||||
@ecs.register('HeroCardView', false)
|
||||
export class HeroCardViewComp extends CCComp {
|
||||
card_name:string = "hero_card";
|
||||
card_type:string = "hero";
|
||||
card_uid:number = 1000;
|
||||
/** 方向 */
|
||||
private _dir: Vec2 = new Vec2(0, 0);
|
||||
public get dir(): Vec2 {
|
||||
return this._dir;
|
||||
}
|
||||
public set dir(value: Vec2) {
|
||||
this._dir = value;
|
||||
}
|
||||
pos_x=0;
|
||||
pos_y=0;
|
||||
protected onLoad(): void {
|
||||
this.node.on(NodeEventType.TOUCH_START, this.onTouchMove, this);
|
||||
this.node.on(NodeEventType.TOUCH_MOVE, this.onTouchMove, this);
|
||||
this.node.on(NodeEventType.TOUCH_END, this.onTouchEnd, this);
|
||||
this.node.on(NodeEventType.TOUCH_CANCEL, this.onTouchEnd, this);
|
||||
oops.message.on("destroy hero_card", this.on_destroy_node, this);
|
||||
}
|
||||
|
||||
|
||||
private on_destroy_node(event: string, args: any) {
|
||||
// if(this.ent.eid == args){
|
||||
// this.reset();
|
||||
// }
|
||||
}
|
||||
|
||||
onTouchMove(event: EventTouch) {
|
||||
console.log("onTouchMove");
|
||||
let delta = event.getDelta();
|
||||
this.node.setPosition(this.node.position.x+delta.x,this.node.position.y+delta.y);
|
||||
}
|
||||
onTouchEnd(){
|
||||
if(this.node.position.y-this.pos_y > 50){
|
||||
this.use_card()
|
||||
}else{
|
||||
this.node.setPosition(this.pos_x,this.pos_y);
|
||||
}
|
||||
console.log(ecs.query(ecs.allOf(HeroCardViewComp)))
|
||||
|
||||
}
|
||||
use_card(){
|
||||
oops.message.dispatchEvent("do_add_hero",this.ent)
|
||||
this.ent.destroy();
|
||||
}
|
||||
/** 视图层逻辑代码分离演示 */
|
||||
start() {
|
||||
this.pos_x=this.node.position.x;
|
||||
this.pos_y=this.node.position.y;
|
||||
}
|
||||
|
||||
/** 全局消息逻辑处理 */
|
||||
// private onHandler(event: string, args: any) {
|
||||
// switch (event) {
|
||||
// case ModuleEvent.Cmd:
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
||||
reset() {
|
||||
this.node.destroy();
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,8 @@
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "cbc1684f-2e32-4088-a784-3c147c9b6f31",
|
||||
"uuid": "ad422ad0-14e7-4547-8703-1bb4d5b10d01",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
"userData": {}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ export class Monster extends ecs.Entity {
|
||||
/** 加载角色 */
|
||||
load(pos: Vec3 = Vec3.ZERO,speed:number = 100,camp:number = 1,prefab_path:string = "monster",name:string="hero") {
|
||||
// var path = "game/monster/"+prefab_path;
|
||||
var path = "game/monster/hero";
|
||||
var path = "game/heros/hero";
|
||||
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
@@ -70,7 +70,7 @@ export class Monster extends ecs.Entity {
|
||||
oops.message.dispatchEvent("monster_load",this)
|
||||
}
|
||||
|
||||
console.log(smc.heros_in,smc.monsters_in)
|
||||
// console.log(smc.heros_in,smc.monsters_in)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
import { Color, Component, EventTouch, sp, Vec3, _decorator } from "cc";
|
||||
import { LayerUtil } from "../../../../extensions/oops-plugin-framework/assets/core/utils/LayerUtil";
|
||||
import { smc } from "../../../script/game/common/SingletonModuleComp";
|
||||
// import Charactor, { CharactorDirection, CharactorState } from "../../map/view/map/charactor/Charactor";
|
||||
import MonsterSpineAnimator from "./MonsterSpineAnimator";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
@@ -21,11 +20,9 @@ export class MonsterSpine extends Component {
|
||||
animator: MonsterSpineAnimator = null!;
|
||||
|
||||
private spine!: sp.Skeleton;
|
||||
// private charactor!: Charactor;
|
||||
|
||||
onLoad() {
|
||||
// 角色控制组件
|
||||
// this.charactor = this.addComponent(Charactor)!;
|
||||
|
||||
this.initAnimator();
|
||||
// this.setSkin("magic");
|
||||
@@ -43,16 +40,7 @@ export class MonsterSpine extends Component {
|
||||
|
||||
|
||||
|
||||
// setState(value: CharactorState): void {
|
||||
// switch (value) {
|
||||
// case CharactorState.Idle:
|
||||
// this.idle();
|
||||
// break;
|
||||
// case CharactorState.Run:
|
||||
// this.walk();
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
setSkin(value: string): void {
|
||||
console.log("MonsterSpine setSkin", value);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* @LastEditTime: 2022-08-17 12:36:18
|
||||
*/
|
||||
|
||||
import { Vec3, _decorator , v3,Collider2D,Contact2DType,IPhysics2DContact,EPhysics2DDrawFlags,Label,Node,Prefab,instantiate} from "cc";
|
||||
import { Vec3, _decorator , v3,Collider2D,Contact2DType,IPhysics2DContact,EPhysics2DDrawFlags,Label,Node,Prefab,instantiate,ProgressBar} 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";
|
||||
@@ -17,6 +17,7 @@ import { smc } from "../common/SingletonModuleComp";
|
||||
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
||||
import { baseCom } from "../skills/baseCom";
|
||||
import { Skill } from "../skills/Skill";
|
||||
import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 角色显示组件 */
|
||||
@@ -30,23 +31,37 @@ export class MonsterViewComp extends CCComp {
|
||||
camp: number = 1;
|
||||
/**角色类型 1:近战 2 远程 */
|
||||
type: number = 1;
|
||||
/** 状态 1:move ,2: act 3: stop */
|
||||
state: number = 1;
|
||||
/** 血量 */
|
||||
hp: number = 100;
|
||||
hp_max: number = 100;
|
||||
hp_speed: number = 0; //回复速度
|
||||
/**能量**/
|
||||
power: number = 0;
|
||||
power_max: number = 100;
|
||||
power_speed: number = 1; //回复速度
|
||||
skill_name: string = "base";
|
||||
max_skill_name: string = "base";
|
||||
/**攻击力 */
|
||||
atk: number = 10;
|
||||
/**攻击速度 */
|
||||
// atk_speed: number = 1;
|
||||
atk_cd: number = 1.3;
|
||||
atk_time: number = 0;
|
||||
/** 角色移动速度 */
|
||||
speed: number = 100;
|
||||
/** 角色初始速度 */
|
||||
ospeed: number = 100;
|
||||
/**攻击速度 */
|
||||
atk_speed: number = 1;
|
||||
atk_cd: number = 0;
|
||||
/** 状态 1:move ,2: act 3: stop */
|
||||
state: number = 1;
|
||||
|
||||
Tpos: Vec3 = v3(0,-60,0);
|
||||
timer: number = 0;
|
||||
stop_cd: number = 0;
|
||||
private timer:Timer = new Timer(0.1);
|
||||
is_dead:boolean = false;
|
||||
|
||||
/** 视图层逻辑代码分离演示 */
|
||||
start () {
|
||||
// 注册单个碰撞体的回调函数
|
||||
let collider = this.getComponent(Collider2D);
|
||||
|
||||
if (collider) {
|
||||
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
|
||||
collider.on(Contact2DType.END_CONTACT, this.onEndContact, this);
|
||||
@@ -54,37 +69,10 @@ export class MonsterViewComp extends CCComp {
|
||||
collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
switch (selfCollider.group) {
|
||||
case BoxSet.MONSTER:
|
||||
switch (otherCollider.group){
|
||||
case BoxSet.HERO:
|
||||
this.state = 2;
|
||||
// console.log('onBeginContact',selfCollider,otherCollider);
|
||||
// this.speed = 0;
|
||||
// this.timer = 1;
|
||||
// console.log("speed:"+this.speed+" | timer:"+this.timer);
|
||||
break;
|
||||
case BoxSet.HERO_SKILL:
|
||||
|
||||
break;
|
||||
case BoxSet.MONSTER_SKILL:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case BoxSet.HERO:
|
||||
switch (otherCollider.group){
|
||||
case BoxSet.MONSTER:
|
||||
this.state = 2;
|
||||
break;
|
||||
case BoxSet.HERO_SKILL:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
@@ -96,17 +84,47 @@ export class MonsterViewComp extends CCComp {
|
||||
// console.log('onPreSolve');
|
||||
// }
|
||||
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
if (otherCollider.group === BoxSet.HERO && selfCollider.group === BoxSet.MONSTER) {
|
||||
// console.log('onPostSolve otherCollider.group :'+otherCollider.group);
|
||||
// this.speed = 0;
|
||||
// this.timer = 1;
|
||||
if(otherCollider.group== BoxSet.HERO_SKILL || otherCollider.group== BoxSet.MONSTER_SKILL){
|
||||
this.in_atked();
|
||||
this.hp_change(10);
|
||||
}
|
||||
// switch (selfCollider.group) {
|
||||
// case BoxSet.HERO:
|
||||
// switch (otherCollider.group){
|
||||
// case BoxSet.MONSTER:
|
||||
// break;
|
||||
// case BoxSet.MONSTER_SKILL:
|
||||
// this.in_atked();
|
||||
// this.hp_change(10);
|
||||
// break;
|
||||
// }
|
||||
// case BoxSet.MONSTER:
|
||||
// switch (otherCollider.group){
|
||||
// case BoxSet.HERO:
|
||||
// // console.log('onBeginContact',selfCollider,otherCollider);
|
||||
// // setTimeout(() => {
|
||||
// // this.toDestroy();
|
||||
// // }, 10);
|
||||
|
||||
// // this.speed = 0;
|
||||
// // this.stop_cd = 1;
|
||||
// // console.log("speed:"+this.speed+" | stop_cd:"+this.stop_cd);
|
||||
// break;
|
||||
// case BoxSet.HERO_SKILL:
|
||||
// this.in_atked();
|
||||
// this.hp_change(10);
|
||||
// break;
|
||||
// // case BoxSet.MONSTER_SKILL:
|
||||
// // break;
|
||||
// }
|
||||
// break;
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
onLoad() {
|
||||
this.as = this.getComponent(MonsterSpine);
|
||||
|
||||
// console.log('hero load ent:',this);
|
||||
// PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.Aabb |
|
||||
// EPhysics2DDrawFlags.Pair |
|
||||
@@ -116,7 +134,7 @@ export class MonsterViewComp extends CCComp {
|
||||
}
|
||||
change_name(hero_name:string='hero',camp:number=1){
|
||||
this.name=hero_name;
|
||||
let label:any =this.node.getChildByName("top").getChildByName("lab_name")
|
||||
let label:any =this.node.getChildByName("lab_name")
|
||||
label.getComponent(Label)!.string = hero_name;
|
||||
let collider = this.getComponent(Collider2D);
|
||||
if(camp==1){
|
||||
@@ -124,10 +142,12 @@ export class MonsterViewComp extends CCComp {
|
||||
}else{
|
||||
collider.group=BoxSet.MONSTER;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
update(dt: number){
|
||||
|
||||
if (this.timer.update(dt)) {
|
||||
this.power_change(this.power_speed)
|
||||
}
|
||||
this.in_destroy();
|
||||
this.in_stop(dt);
|
||||
this.in_act(dt);
|
||||
@@ -148,22 +168,49 @@ export class MonsterViewComp extends CCComp {
|
||||
move(dt: number){
|
||||
this.node.setPosition(this.node.position.x+dt*this.speed*this.camp, this.node.position.y, this.node.position.z);
|
||||
}
|
||||
power_change(power: number){
|
||||
this.power += power;
|
||||
if(this.power >= this.power_max){
|
||||
this.load_skill(this.max_skill_name);
|
||||
this.power = 0
|
||||
}
|
||||
let power_progress= this.power/this.power_max;
|
||||
this.node.getChildByName("power").getComponent(ProgressBar)!.progress = power_progress;
|
||||
}
|
||||
in_act(dt: number) {
|
||||
if(this.atk_cd >= this.atk_speed){
|
||||
this.atk_cd = 0;
|
||||
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.load_skill(this.skill_name);
|
||||
}
|
||||
this.atk_time += dt;
|
||||
}
|
||||
hp_change(hp: number){
|
||||
if(this.is_dead){
|
||||
return;
|
||||
}
|
||||
this.hp -= hp;
|
||||
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;
|
||||
if(this.hp <= 0){
|
||||
this.is_dead = true;
|
||||
setTimeout(() => {
|
||||
this.toDestroy();
|
||||
}, 15);
|
||||
|
||||
}
|
||||
this.atk_cd += dt;
|
||||
}
|
||||
/** 静止时间 */
|
||||
in_stop (dt: number) {
|
||||
if(this.timer > 0){
|
||||
this.timer -= dt;
|
||||
if(this.timer <= 0){
|
||||
if(this.stop_cd > 0){
|
||||
this.stop_cd -= dt;
|
||||
if(this.stop_cd <= 0){
|
||||
this.speed = this.ospeed;
|
||||
this.timer = 0;
|
||||
this.stop_cd = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -171,12 +218,12 @@ export class MonsterViewComp extends CCComp {
|
||||
switch (this.camp) {
|
||||
case -1:
|
||||
if(this.node.position.x < BoxSet.LETF_END){
|
||||
this.reset();
|
||||
this.toDestroy();
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if(this.node.position.x > BoxSet.RIGHT_END){
|
||||
this.reset();
|
||||
this.toDestroy();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -188,25 +235,38 @@ export class MonsterViewComp extends CCComp {
|
||||
}
|
||||
});
|
||||
}
|
||||
load_skill(){
|
||||
load_skill(skill_name){
|
||||
// console.log("load_skill");
|
||||
let skill = ecs.getEntity<Skill>(Skill);
|
||||
let pos = v3(0,0)
|
||||
let speed =200
|
||||
let speed =150
|
||||
let scale = this.camp
|
||||
let range = 80
|
||||
skill.load(pos,speed,range,scale,this.node);
|
||||
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,0)
|
||||
node.setPosition(pos)
|
||||
node.parent = this.node;
|
||||
}
|
||||
dead(){
|
||||
var path = "game/skills/dead";
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
node.setPosition(this.node.position)
|
||||
node.parent = this.node.parent;
|
||||
}
|
||||
toDestroy(){
|
||||
this.dead();
|
||||
smc.monsters_in = smc.monsters_in.filter(element => element.eid !== this.ent.eid);
|
||||
smc.monsters_in = smc.monsters_in.filter(element => element.eid !== this.ent.eid);
|
||||
this.ent.destroy();
|
||||
}
|
||||
reset() {
|
||||
// console.log("node destroy:",this.node,this.ent)
|
||||
smc.monsters_in = smc.monsters_in.filter(element => element.eid !== this.ent.eid);
|
||||
smc.monsters_in = smc.monsters_in.filter(element => element.eid !== this.ent.eid);
|
||||
this.is_dead = false;
|
||||
this.node.destroy();
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
import { Color, Component, EventTouch, sp, Vec3, _decorator } from "cc";
|
||||
import { LayerUtil } from "../../../../../extensions/oops-plugin-framework/assets/core/utils/LayerUtil";
|
||||
import { smc } from "../../common/SingletonModuleComp";
|
||||
// import Charactor, { CharactorDirection, CharactorState } from "../../map/view/map/charactor/Charactor";
|
||||
import RoleSpineAnimator from "./RoleSpineAnimator";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
@@ -21,11 +20,9 @@ export class RoleSpine extends Component {
|
||||
animator: RoleSpineAnimator = null!;
|
||||
|
||||
private spine!: sp.Skeleton;
|
||||
// private charactor!: Charactor;
|
||||
|
||||
onLoad() {
|
||||
// 角色控制组件
|
||||
// this.charactor = this.addComponent(Charactor)!;
|
||||
|
||||
this.initAnimator();
|
||||
// this.setSkin("magic");
|
||||
@@ -42,17 +39,6 @@ export class RoleSpine extends Component {
|
||||
|
||||
|
||||
|
||||
// setState(value: CharactorState): void {
|
||||
// switch (value) {
|
||||
// case CharactorState.Idle:
|
||||
// this.idle();
|
||||
// break;
|
||||
// case CharactorState.Run:
|
||||
// this.walk();
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
setSkin(value: string): void {
|
||||
console.log("RoleSpine setSkin", value);
|
||||
this.spine.setSkin(value);
|
||||
|
||||
@@ -27,23 +27,23 @@ export class Skill extends ecs.Entity {
|
||||
this.remove(SkillCom);
|
||||
super.destroy();
|
||||
}
|
||||
load(pos: Vec3 = Vec3.ZERO,speed:number = 100,range:number = 50,scale:number = 1,parent:Node) {
|
||||
// var path = "game/monster/"+prefab_path;
|
||||
var path = "game/skills/base";
|
||||
load(pos: Vec3 = Vec3.ZERO,speed:number = 100,range:number = 50,scale:number = 1,parent:Node,skill_name:string = "base",atk:number =10) {
|
||||
var path = "game/skills/"+skill_name;
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
node.parent = parent;
|
||||
node.setPosition(pos)
|
||||
var mv = node.getComponent(SkillCom)!;
|
||||
mv.speed = speed;
|
||||
mv.range = range;
|
||||
mv.scale = scale;
|
||||
var sv = node.getComponent(SkillCom)!;
|
||||
sv.speed = speed;
|
||||
sv.range = range;
|
||||
sv.scale = scale;
|
||||
sv.atk = atk;
|
||||
if(scale == 1){
|
||||
mv.change_collider_group(BoxSet.HERO_SKILL)
|
||||
sv.change_collider_group(BoxSet.HERO_SKILL)
|
||||
}else{
|
||||
mv.change_collider_group(BoxSet.MONSTER_SKILL)
|
||||
sv.change_collider_group(BoxSet.MONSTER_SKILL)
|
||||
}
|
||||
this.add(mv);
|
||||
this.add(sv);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,20 +17,29 @@ export class SkillCom extends CCComp {
|
||||
speed:number = 600;
|
||||
range:number = 80;
|
||||
scale:number = 1;
|
||||
atk:number = 10;
|
||||
is_destroy:boolean = false;
|
||||
start() {
|
||||
let collider = this.getComponent(Collider2D);
|
||||
if (collider) {
|
||||
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
|
||||
// collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
|
||||
collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
|
||||
}
|
||||
}
|
||||
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
switch (selfCollider.group) {
|
||||
|
||||
case BoxSet.HERO_SKILL:
|
||||
switch (otherCollider.group){
|
||||
case BoxSet.MONSTER:
|
||||
// this.reset()
|
||||
console.log('hero skill',selfCollider);
|
||||
if(this.is_destroy){
|
||||
return
|
||||
}else{
|
||||
this.is_destroy = true;
|
||||
this.toDestroy();
|
||||
}
|
||||
|
||||
|
||||
// this.speed = 0;
|
||||
// this.timer = 1;
|
||||
// console.log("speed:"+this.speed+" | timer:"+this.timer);
|
||||
@@ -40,6 +49,12 @@ export class SkillCom extends CCComp {
|
||||
case BoxSet.MONSTER_SKILL:
|
||||
switch (otherCollider.group){
|
||||
case BoxSet.HERO:
|
||||
if(this.is_destroy){
|
||||
return
|
||||
}else{
|
||||
this.is_destroy = true;
|
||||
this.toDestroy();
|
||||
}
|
||||
// console.log('monster skill',selfCollider,otherCollider);
|
||||
// this.reset()
|
||||
break;
|
||||
@@ -57,7 +72,13 @@ export class SkillCom extends CCComp {
|
||||
this.node.setPosition(v3(this.node.position.x+deltaTime*this.speed*this.scale,this.node.position.y,this.node.position.z))
|
||||
if(Math.abs(this.node.position.x) > this.range)
|
||||
{
|
||||
this.reset()
|
||||
if(this.is_destroy){
|
||||
return
|
||||
}else{
|
||||
this.is_destroy = true;
|
||||
this.toDestroy()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -68,9 +89,14 @@ export class SkillCom extends CCComp {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
toDestroy() {
|
||||
setTimeout(() => {
|
||||
this.ent.destroy()
|
||||
}, 15);
|
||||
}
|
||||
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
||||
reset() {
|
||||
this.is_destroy=false
|
||||
this.node.destroy();
|
||||
}
|
||||
}
|
||||
20
assets/script/game/skills/atked.ts
Normal file
20
assets/script/game/skills/atked.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { _decorator, Component, Node } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('atked')
|
||||
export class atked extends Component {
|
||||
time = 0.3;
|
||||
start() {
|
||||
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
this.time = this.time - deltaTime;
|
||||
if(this.time <= 0)
|
||||
{
|
||||
this.node.destroy()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,10 +2,8 @@
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "cb924b7b-003d-4995-a223-f41612b1d87c",
|
||||
"uuid": "65d6266f-bba6-4b98-8343-2a67642ec7eb",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
"userData": {}
|
||||
}
|
||||
18
assets/script/game/skills/dead.ts
Normal file
18
assets/script/game/skills/dead.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { _decorator, Component, Node ,Animation} from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('dead')
|
||||
export class dead extends Component {
|
||||
start() {
|
||||
let anim = this.node.getComponent(Animation);
|
||||
anim.on(Animation.EventType.FINISHED, this.onAnimationFinished, this);
|
||||
}
|
||||
onAnimationFinished(){
|
||||
this.node.destroy();
|
||||
}
|
||||
update(deltaTime: number) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
9
assets/script/game/skills/dead.ts.meta
Normal file
9
assets/script/game/skills/dead.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "0f3c4261-15b1-4eda-b105-a81249ee116f",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user