Commit dfb92bdc authored by wjf's avatar wjf

l

parent 1b766b54
This diff is collapsed.
...@@ -6,8 +6,11 @@ import { PassType } from "./enum/PassType"; ...@@ -6,8 +6,11 @@ import { PassType } from "./enum/PassType";
import { EffectType } from "./enum/EffectType"; import { EffectType } from "./enum/EffectType";
import { Pool } from "./Pool"; import { Pool } from "./Pool";
import { RecoverName } from "./enum/RecoverName"; import { RecoverName } from "./enum/RecoverName";
import { RectMask } from "./class/RectMask";
import { FallType } from "./interface/FallAniData";
export class Tool { export class Tool {
public static latDeltaTime = 100;
public static rowNum = 9; public static rowNum = 9;
public static colNum = 9; public static colNum = 9;
/** /**
...@@ -715,37 +718,58 @@ export class Tool { ...@@ -715,37 +718,58 @@ export class Tool {
return arr return arr
} }
/** /**
* 找一个格子,最终掉落点, * 找一个格子,最终掉落点,所有的index吧
* @param lattice 能掉落的格子 * @param lattice 能掉落的格子,格子上肯定有元素,并且能掉落
* @param empty * @param empty
* @param lattices * @param lattices
* @return 返回空格数组中的索引 * @return 所有中间点吧数据
*/ */
public static findBottom(lattice: Lattice, emptys: number[], lattices: Lattice[]): number { public static findBottom(lattice: Lattice, emptys: number[], lattices: Lattice[]): { index: number, type: FallType }[] {
let indexDown, lat; let indexDown: number, lat: Lattice;
let connects: { index: number, type: FallType }[] = [];
let isThrough: boolean = false;
//找下面的
if (lattice.down != null) { if (lattice.down != null) {
indexDown = lattice.down; indexDown = lattice.down;
isThrough = true;
} else { } else {
indexDown = lattice.index + this.colNum; indexDown = lattice.index + this.colNum;
} }
let lastEmptyIndex: number; let lastEmptyIndex: number;
//下方有格子,并且再this.empty中 //下方有格子,并且再this.empty中
let emptyIndex: number = emptys.indexOf(indexDown); let emptyIndex: number = emptys.indexOf(indexDown);
//只要还在里面就一直找下,直到 //只要还在里面就一直找下,直到
while (emptyIndex > -1) { while (emptyIndex > -1) {
if (isThrough) connects.push({ index: indexDown, type: FallType.THROUGH });
//记录下上一个满足的 //记录下上一个满足的
lastEmptyIndex = emptyIndex; lastEmptyIndex = emptyIndex;
//下面格子变成lat //下面格子变成lat
lat = lattices[indexDown]; lat = lattices[indexDown];
if (lat.down != null) { if (lat.down != null) {
//如果上次是false的,就结束加入
if (!isThrough) connects.push({ index: indexDown, type: FallType.STRIGHT });
isThrough = true
indexDown = lat.down; indexDown = lat.down;
} else { } else {
isThrough = false
indexDown = lat.index + this.colNum; indexDown = lat.index + this.colNum;
} }
emptyIndex = emptys.indexOf(indexDown); emptyIndex = emptys.indexOf(indexDown);
} }
if (lastEmptyIndex != undefined) { if (lastEmptyIndex != undefined) {
return lastEmptyIndex //说明已经加过,然后down无空格,直线已加
if (isThrough) {
return connects
}
//直线未加
else {
connects.push({ index: emptys[lastEmptyIndex], type: FallType.STRIGHT })
return connects
}
} else { } else {
return null return null
} }
...@@ -758,11 +782,18 @@ export class Tool { ...@@ -758,11 +782,18 @@ export class Tool {
var index = Tool.rcToIndex(n, m); var index = Tool.rcToIndex(n, m);
let lat = lattices[index]; let lat = lattices[index];
if (Tool.judgeFall(lat)) { if (Tool.judgeFall(lat)) {
var emptyIndex = Tool.findBottom(lat, emptys, lattices); var indexs = Tool.findBottom(lat, emptys, lattices);
var downIndex = emptys[emptyIndex]; if (indexs != null) {
if (emptyIndex != null) { //超过一步,肯定true
if ((downIndex - index) / Tool.colNum > 1) { if (indexs.length > 1) {
return true; return true;
} else {
var downIndex: number = indexs[0].index;
var type: FallType = indexs[0].type;
//直线的
if (type == FallType.STRIGHT && (downIndex - index) / Tool.colNum > 1) {
return true;
}
} }
} }
} else { } else {
...@@ -773,7 +804,12 @@ export class Tool { ...@@ -773,7 +804,12 @@ export class Tool {
var downIndex = index; var downIndex = index;
while (emptys.indexOf(downIndex) > -1) { while (emptys.indexOf(downIndex) > -1) {
arr.push(downIndex); arr.push(downIndex);
downIndex += Tool.colNum; if (lat.down != null) {
downIndex = lat.down;
} else {
downIndex = lat.index + this.colNum;
}
lat = lattices[downIndex];
} }
if (arr.length > 1) return true if (arr.length > 1) return true
} }
...@@ -830,6 +866,14 @@ export class Tool { ...@@ -830,6 +866,14 @@ export class Tool {
} }
return obj return obj
} }
/**
* 获得矩形遮罩
*/
public static getRectMask(): RectMask {
let rect: RectMask = Pool.takeOut(RecoverName.RECT_MASK);
if (!rect) rect = new RectMask()
return rect;
}
/** /**
* 返回个十百等,0是个位 * 返回个十百等,0是个位
......
import { Tool } from "../Tool";
import { ElementType } from "../enum/ElementType";
import { EffectType } from "../enum/EffectType";
import { Element } from "../class/Element";
import { Pool } from "../Pool";
import { RecoverName } from "../enum/RecoverName";
/**
* 矩形遮罩的元素动画
* @param eleC
* @param p
* @param con
* @param callback
*/
export function EleMaskAni(
eleC: Element,
p: number[],
wait: number,
con: egret.DisplayObjectContainer,
isUp: boolean = false,
callback?: Function
) {
let ele = Tool.getElement(eleC.type);
ele.effectType = eleC.effectType;
ele.x = p[0];
ele.y = p[1] - Tool.height * (isUp ? 0 : 1);
let mask = Tool.getRectMask();
mask.x = p[0];
mask.y = p[1];
ele.mask = mask;
con.addChild(mask);
egret.Tween.get(ele)
.wait(wait)
.call(()=>{
con.addChild(ele);
})
.to({ x: p[0], y: p[1] + Tool.height * (isUp ? 1 : 0) }, Tool.latDeltaTime)
.call(() => {
//回收元素
con.removeChild(ele);
Pool.recover(RecoverName.ELEMENT, ele);
//回收遮罩
ele.mask = null;
mask.recover();
//回调
callback && callback();
})
}
\ No newline at end of file
import { Tool } from "../Tool";
import { Pool } from "../Pool";
import { RecoverName } from "../enum/RecoverName";
/**
* 元素出现及消失用到的矩形遮罩
*/
export class RectMask extends egret.Shape {
constructor() {
super();
this.graphics.beginFill(0xffffff);
this.graphics.beginFill(0xff0000, 1);
this.graphics.drawRect(-Tool.width / 2, -Tool.height / 2, Tool.width, Tool.height)
this.graphics.endFill();
}
recover() {
if (this.parent) {
this.parent.removeChild(this);
Pool.recover(RecoverName.RECT_MASK, this);
}
}
}
\ No newline at end of file
...@@ -42,4 +42,7 @@ export enum RecoverName { ...@@ -42,4 +42,7 @@ export enum RecoverName {
STEP_ANI = "StepAni", STEP_ANI = "StepAni",
JELLYDIS_ANI = "JellyDisAni", JELLYDIS_ANI = "JellyDisAni",
EGGBROKEN_ANI = "EggBrokenAni", EGGBROKEN_ANI = "EggBrokenAni",
//方形遮罩
RECT_MASK = "RectMask"
} }
\ No newline at end of file
import { Element } from "../class/Element";
/**
* 掉落动画数据
*/
export interface FallAniData {
/**
* 掉落元素,设为null的时候要生成,并且通过遮罩,生成动画
*/
ele: Element;
/**
* 等待时间,一般用于一个生成口有多个元素排列着的情况
* ele为null才需要wait
*/
wait?: number;
/**
* 起点、中间点及终点的索引,穿过记录下格子,不可能为空
* 索引加类型
*/
indexs: { index: number, type: FallType }[]
// indexs:number[];
}
export enum FallType {
STRIGHT = 0,
THROUGH,
}
\ No newline at end of file
/** /**
* 路径数据 * 路径数据,废弃不用
*/ */
export interface PathData { export interface PathData {
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment