This commit is contained in:
2024-08-11 16:50:42 +08:00
parent 37bc93aa1c
commit 6355d80a2c
70 changed files with 1696 additions and 2535 deletions

View File

@@ -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

View File

@@ -1,12 +0,0 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "f58752f0-7320-4a2f-b7a3-d4d59e42c1f6",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@@ -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;
}
}

View File

@@ -1,11 +0,0 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "cbc1684f-2e32-4088-a784-3c147c9b6f31",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -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;
}

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "977105e0-d01b-402a-b649-080e33733218",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -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;
}
}

View File

@@ -1,11 +0,0 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "cb924b7b-003d-4995-a223-f41612b1d87c",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -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 => {

View File

@@ -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;
}
}

View File

@@ -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 => {