Commit a031d17d authored by wildfirecode's avatar wildfirecode

1

parents 29a3e0b6 4bb2983d
......@@ -202,9 +202,9 @@ export default class MainBase extends eui.UILayer {
for (var i = 0; i <= 9; i++) {
RES.getResAsync("propNum" + i + "_png")
}
for (var i = 1; i <= 5; i++) {
RES.getResAsync("guideTxt" + i + "_png")
}
// for (var i = 1; i <= 5; i++) {
// RES.getResAsync("guideTxt" + i + "_png")
// }
for (var i = 1; i <= 11; i++) {
RES.getResAsync("stepAni" + i + "_png")
}
......@@ -214,7 +214,18 @@ export default class MainBase extends eui.UILayer {
RES.getResAsync("exLighting" + i + "_png")
}
}
for (var i = 0; i <= 2; i++) {
RES.getResAsync("eggStatus" + i + "_png")
}
for (var i = 1; i <= 5; i++) {
RES.getResAsync("eggPiece" + i + "_png")
}
var arr = [
"yellowCircleDown",
"yellowCircleUp",
"greenCircleDown",
"greenCircleUp",
"jellyArrow",
"lockVine",
"guidePropHand",
"guidePropCow",
......@@ -236,13 +247,14 @@ export default class MainBase extends eui.UILayer {
"hammerBtn",
"stepBtn",
"propNumBg",
"guideBg",
"guideKnowBtn",
// "guideBg",
// "guideKnowBtn",
"bonusShoot",
"ele5",
"ele6",
"ele7",
"ele8",
"ele9",
"leftArrow",
"chooseRect",
"lightedStar",
......
......@@ -4,5 +4,6 @@
<e:Image source="startpanel_block2_png" x="0" y="0"/>
<e:Image id="icon_LOLLIPOP" source="startpanel_ele6_png" width="60" height="60"/>
<e:Image id="icon_ICE" source="startpanel_ice1_png" width="60" height="60"/>
<e:Image id="icon_xxx" width="60" height="60" source="startpanel_xxxx_png"/>
<e:BitmapLabel id="txt" text="X0" font="nums2_fnt" scaleX="0.4" scaleY="0.4" y="46" horizontalCenter="0"/>
</e:Skin>
\ No newline at end of file
This diff is collapsed.
......@@ -9,6 +9,7 @@ export default class TargetItemRenderer extends eui.ItemRenderer {
dataChanged(){
this['icon_LOLLIPOP'].visible=this.data.type == ElementType.LOLLIPOP;
this['icon_ICE'].visible=this.data.type == ElementType.ICE;
this['icon_xxx'].visible=this.data.type == ElementType.xxx;
this['txt'].text = `X${this.data.count }`;
}
}
\ No newline at end of file
......@@ -2941,7 +2941,7 @@ export const Chapters: ChapterData[] = [
},
baseElementTypes: [0, 1, 2, 3],
effectInitProbability: 0.3,
stepCount: 14 + 6 + 5,
stepCount: 25,
passTarget: {
type: PassType.ELEMENT_TARGET,
elements: [
......@@ -2986,7 +2986,7 @@ export const Chapters: ChapterData[] = [
},
baseElementTypes: [0, 1, 2, 3],
effectInitProbability: 0.03,
stepCount: 20 + 6,
stepCount: 26,
passTarget: {
type: PassType.ELEMENT_TARGET,
elements: [
......@@ -3031,7 +3031,7 @@ export const Chapters: ChapterData[] = [
},
baseElementTypes: [0, 1, 2, 3, 4],
effectInitProbability: 0.02,
stepCount: 15 + 5,
stepCount: 20,
passTarget: {
type: PassType.ELEMENT_TARGET,
elements: [
......@@ -3076,7 +3076,7 @@ export const Chapters: ChapterData[] = [
},
baseElementTypes: [0, 1, 2, 3, 4],
effectInitProbability: 0,
stepCount: 20 + 4,
stepCount: 24,
passTarget: {
type: PassType.ELEMENT_TARGET,
elements: [
......@@ -3121,7 +3121,7 @@ export const Chapters: ChapterData[] = [
},
baseElementTypes: [0, 1, 2, 3, 4],
effectInitProbability: 0.03,
stepCount: 20 + 5,
stepCount: 25,
passTarget: {
type: PassType.SCORE_TARGET,
score: 15000
......@@ -3161,7 +3161,7 @@ export const Chapters: ChapterData[] = [
},
baseElementTypes: [0, 1, 2, 3, 4],
effectInitProbability: 0.03,
stepCount: 20 + 4,
stepCount: 24,
passTarget: {
type: PassType.ELEMENT_TARGET,
elements: [
......@@ -3206,7 +3206,7 @@ export const Chapters: ChapterData[] = [
},
baseElementTypes: [0, 1, 2, 3, 4],
effectInitProbability: 0.03,
stepCount: 15 + 5,
stepCount: 20,
passTarget: {
type: PassType.ELEMENT_TARGET,
elements: [
......@@ -3251,7 +3251,7 @@ export const Chapters: ChapterData[] = [
},
baseElementTypes: [0, 1, 2, 3, 4],
effectInitProbability: 0.03,
stepCount: 20 + 4,
stepCount: 24,
passTarget: {
type: PassType.ELEMENT_TARGET,
elements: [
......@@ -3296,7 +3296,7 @@ export const Chapters: ChapterData[] = [
},
baseElementTypes: [0, 1, 2, 3, 4],
effectInitProbability: 0.02,
stepCount: 25 + 3,
stepCount: 28,
passTarget: {
type: PassType.ELEMENT_TARGET,
elements: [
......@@ -3312,6 +3312,7 @@ export const Chapters: ChapterData[] = [
15000
]
},
////////////////////////////////
//第八十一关
{
map: {
......@@ -3331,9 +3332,9 @@ export const Chapters: ChapterData[] = [
0, 1, 0, 1, 0, 1, 0, 1, 0,
5, 1, 1, 1, 1, 1, 1, 1, 5,
0, 1, 1, 1, 1, 1, 1, 1, 0,
2, 1, 1, 1, 1, 1, 1, 1, 2,
0, 1, 1, 1, 1, 1, 1, 1, 0,
2, 1, 1, 1, 1, 1, 1, 1, 2,
2, 1, 1, 1, 6, 1, 1, 1, 2,
0, 1, 1, 1, 6, 1, 1, 1, 0,
2, 1, 1, 1, 6, 1, 1, 1, 2,
0, 1, 1, 1, 1, 1, 1, 1, 0,
5, 1, 1, 1, 1, 1, 1, 1, 5,
0, 5, 0, 5, 0, 5, 0, 5, 0,
......@@ -3346,8 +3347,8 @@ export const Chapters: ChapterData[] = [
type: PassType.ELEMENT_TARGET,
elements: [
{
type: ElementType.ICE,
count: 65
type: ElementType.CHICKEN,
count: 1000
}
],
},
......@@ -3358,4 +3359,49 @@ export const Chapters: ChapterData[] = [
]
},
//第一百关
{
map: {
lattices: [
0, 3, 0, 3, 0, 3, 0, 3, 0,
3, 3, 3, 3, 3, 3, 3, 3, 3,
0, 3, 3, 3, 3, 3, 3, 3, 0,
3, 3, 3, 3, 3, 3, 3, 3, 3,
0, 3, 3, 3, 3, 3, 3, 3, 0,
3, 3, 3, 3, 3, 3, 3, 3, 3,
0, 3, 3, 3, 3, 3, 3, 3, 0,
3, 3, 3, 3, 3, 3, 3, 3, 3,
0, 3, 0, 3, 0, 3, 0, 3, 0,
],
generateLats: [0, 1, 0, 1, 0, 1, 0, 1, 0],
elements: [
0, 1, 0, 1, 0, 1, 0, 1, 0,
5, 1, 1, 1, 1, 1, 1, 1, 5,
0, 1, 1, 1, 1, 1, 1, 1, 0,
2, 1, 1, 1, 6, 1, 1, 1, 2,
0, 1, 1, 1, 6, 1, 1, 1, 0,
2, 1, 1, 1, 6, 1, 1, 1, 2,
0, 1, 1, 1, 1, 1, 1, 1, 0,
5, 1, 1, 1, 1, 1, 1, 1, 5,
0, 5, 0, 5, 0, 5, 0, 5, 0,
],
},
baseElementTypes: [0, 1, 2, 3, 4],
effectInitProbability: 0.02,
stepCount: 250 + 3,
passTarget: {
type: PassType.ELEMENT_TARGET,
elements: [
{
type: ElementType.CHICKEN,
count: 1000
}
],
},
starScores: [
6000,
10000,
22000
]
},
]
\ No newline at end of file
......@@ -802,8 +802,8 @@ export class Tool {
* 获得元素
* @param type
*/
public static getElement(type: ElementType):Element {
let obj:Element = Pool.takeOut(RecoverName.ELEMENT);
public static getElement(type: ElementType): Element {
let obj: Element = Pool.takeOut(RecoverName.ELEMENT);
if (!obj) {
obj = new Element(type)
} else {
......@@ -845,4 +845,35 @@ export class Tool {
}
return r
}
/**
* 随机取数组arr中count个元素
* @param arr
* @param count
*/
public static getRandomArrayElements(arr: any[], count: number) {
var shuffled = arr.slice(0), i = arr.length, min = i - count, temp, index;
//如果count大于等于数组长度,返回所有数组
if (min <= 0) return shuffled;
//随机排序,然后取出后面的元素
while (i-- > min) {
index = Math.floor((i + 1) * Math.random());
temp = shuffled[index];
shuffled[index] = shuffled[i];
shuffled[i] = temp;
}
return shuffled.slice(min);
}
public static getRandomArrayElementsEx(arr: any[], count: number):any[] {
//如果count大于等于数组长度,返回所有数组
if (arr.length <= count) return arr.slice();
if (count <= 0) return [];
var arrCopy = arr.slice();
var outArr = [];
while (count--) {
var rand = Math.floor(Math.random() * arrCopy.length);
var ele = arrCopy.splice(rand, 1)[0];
outArr.push(ele);
}
return outArr
}
}
\ No newline at end of file
import { Ani } from "../class/Ani";
const offsetX = 91 / 2;
const offsetY = 62 / 2;
export class EggBrokenAni extends Ani {
downCircle: egret.Bitmap;
upCircle: egret.Bitmap;
eggPiece1: egret.Bitmap;
eggPiece2: egret.Bitmap;
eggPiece3: egret.Bitmap;
eggPiece4: egret.Bitmap;
eggPiece5: egret.Bitmap;
constructor() {
super()
this.aniName = "EggBrokenAni";
var arr = ["yellowCircleDown_png", "yellowCircleUp_png", "eggPiece1_png", "eggPiece2_png", "eggPiece3_png", "eggPiece4_png", "eggPiece5_png"];
var objs = ["downCircle", "upCircle", "eggPiece1", "eggPiece2", "eggPiece3", "eggPiece4", "eggPiece5"];
for (var i = 0; i < arr.length; i++) {
var texture: egret.Texture = RES.getRes(arr[i])
var obj = new egret.Bitmap(texture);
this.addChild(obj);
obj.anchorOffsetX = texture.textureWidth / 2;
obj.anchorOffsetY = texture.textureHeight / 2;
this[objs[i]] = obj;
}
}
play() {
this.alpha = 1;
//黄色圈下
egret.Tween.get(this.downCircle)
.set({ scaleX: 0.01, scaleY: 0.01 })
.to({ scaleX: 0.6, scaleY: 0.6 }, 300, egret.Ease.cubicOut)
egret.Tween.get(this.downCircle)
.set({ alpha: 1 })
.wait(140)
.to({ alpha: 0 }, 160);
//黄色圈上
egret.Tween.get(this.upCircle)
.set({ scaleX: 0.01, scaleY: 0.01 })
.wait(70)
.to({ scaleX: 1, scaleY: 1 }, 160, egret.Ease.cubicOut);
egret.Tween.get(this.upCircle)
.set({ alpha: 1 })
.wait(170)
.to({ alpha: 0 }, 100);
//下面所有的蛋壳碎片
egret.Tween.get(this.eggPiece1)
.set({ rotation: 0, x: 37 - offsetX, y: 22 - offsetY })
.to({ rotation: 60, x: 37 - offsetX - 30, y: 22 - offsetY - 34 }, 400);
egret.Tween.get(this.eggPiece2)
.set({ rotation: 0, x: 48 - offsetX, y: 20 - offsetY })
.to({ rotation: 60, x: 48 - offsetX + 36, y: 20 - offsetY - 28 }, 400);
egret.Tween.get(this.eggPiece3)
.set({ rotation: 0, x: 52 - offsetX, y: 32 - offsetY })
.to({ rotation: 60, x: 52 - offsetX + 30, y: 32 - offsetY + 10 }, 400);
egret.Tween.get(this.eggPiece4)
.set({ rotation: 0, x: 45 - offsetX, y: 44 - offsetY })
.to({ rotation: 60, x: 45 - offsetX + 32, y: 44 - offsetY + 38 }, 400);
egret.Tween.get(this.eggPiece5)
.set({ rotation: 0, x: 34 - offsetX, y: 34 - offsetY })
.to({ rotation: 60, x: 34 - offsetX - 20, y: 34 - offsetY + 14 }, 400);
//整体透明度
egret.Tween.get(this)
.wait(250)
.to({ alpha: 0 }, 150)
.call(() => {
this.recover();
})
}
}
\ No newline at end of file
import { RecoverName } from "../enum/RecoverName";
import { Pool } from "../Pool";
import { Element } from "../class/Element";
import { Ice } from "../class/Ice";
import { ElementType } from "../enum/ElementType";
import { Tool } from "../Tool";
import MainScene from "../../mainScene/MainScene";
/**
* 孵蛋的动效
*/
export function HatchAni(startIndex: number, endIndexs: number[], thisObj: MainScene, callback: Function) {
let countAll = endIndexs.length;
let count = 0;
var startP = Tool.getPositionByIndex(startIndex);
for (let i = 0; i < endIndexs.length; i++) {
let endIndex = endIndexs[i];
let endP = Tool.getPositionByIndex(endIndex);
let eleC: Element = Tool.getElement(ElementType.CHICKEN);
eleC.x = startP[0];
eleC.y = startP[1];
eleC.scaleX = eleC.scaleY = 0.7;
thisObj.addChild(eleC);
paraCurveAni(eleC, startP, endP, () => {
//回收
thisObj.removeChild(eleC);
Pool.recover(RecoverName.ELEMENT, eleC);
//对应的索引的类型变成鸡
thisObj.lattices[endIndex].element.reset(ElementType.CHICKEN);
//动画,和bonusTime的效果一样,暂时没加
count++;
if (count == countAll) callback();
})
}
}
const deltaTime = 500;
const gravity = 0.003
/**
* 抛物线路径
* @param startP
* @param endP
* @param callback
*/
function paraCurveAni(ele: Element, startP: number[], endP: number[], callback: Function) {
//x方向匀速,线性
var deltaX = endP[0] - startP[0]
//y方向,自由落体,y向下为正,加速度向下为正,初速度根据情况而定
var deltaY = endP[1] - startP[1];
var vy0 = deltaY / deltaTime - gravity * deltaTime / 2;
var a = { t: 0 };
egret.Tween.get(a, {
onChange: function () {
ele.x = deltaX * a.t / deltaTime + startP[0];
ele.y = vy0 * a.t + gravity * a.t * a.t / 2 + startP[1];
}
})
.to({ t: deltaTime }, deltaTime)
.call(() => {
callback();
})
var rotation;
if (deltaX > 0) {
rotation = 360;
}
else if (deltaX < 0) {
rotation = -360;
} else {
rotation = 0
}
//旋转
egret.Tween.get(ele)
.set({ scaleX: 0.3, scaleY: 0.3, rotation: 0 })
.to({ scaleX: 1, scaleY: 1, rotation: rotation }, deltaTime)
}
\ No newline at end of file
import { Ani } from "../class/Ani";
export class JellyDisAni extends Ani {
showImage: egret.Bitmap;
downCircle: egret.Bitmap;
upCircle: egret.Bitmap;
constructor() {
super()
this.aniName = "JellyDisAni";
var arr = ["ele8_png", "greenCircleDown_png", "greenCircleUp_png"];
var objs = ["showImage", "downCircle", "upCircle"];
for (var i = 0; i < arr.length; i++) {
var texture: egret.Texture = RES.getRes(arr[i])
var obj = new egret.Bitmap(texture);
this.addChild(obj);
obj.anchorOffsetX = texture.textureWidth / 2;
obj.anchorOffsetY = texture.textureHeight / 2;
this[objs[i]] = obj;
}
}
play() {
egret.Tween.get(this.showImage)
.set({ alpha: 1 })
.to({ alpha: 0 }, 250*1.5)
egret.Tween.get(this.downCircle)
.set({ scaleX: 0.01, scaleY: 0.01 })
.to({ scaleX: 0.6, scaleY: 0.6 }, 300*1.5, egret.Ease.cubicOut)
.call(() => {
this.recover();
})
egret.Tween.get(this.downCircle)
.set({ alpha: 1 })
.wait(140*1.5)
.to({ alpha: 0 }, 160*1.5);
egret.Tween.get(this.upCircle)
.set({ scaleX: 0.01, scaleY: 0.01 })
.wait(70*1.5)
.to({ scaleX: 1, scaleY: 1 }, 160*1.5, egret.Ease.cubicOut);
egret.Tween.get(this.upCircle)
.set({ alpha: 1 })
.wait(170*1.5)
.to({ alpha: 0 }, 100*1.5);
}
}
\ No newline at end of file
......@@ -2,45 +2,113 @@ import { ImageAni } from "../class/ImageAni";
import { Pool } from "../Pool";
import { RecoverName } from "../enum/RecoverName";
import { playSound, SoundType } from "../../soundCtrl";
import { Tool } from "../Tool";
/**
* 需要回调的
*
*/
export class JellySpreadAni extends egret.DisplayObjectContainer {
//原位置的图片
oriImage: egret.Bitmap;
//目标位置的图片,到时根据方向定
targetImage: egret.Bitmap;
imageAni: ImageAni
shoot: egret.Bitmap;
constructor() {
super()
var texture = RES.getRes("bonusShoot_png")
var texture: egret.Texture = RES.getRes("ele8_png")
this.targetImage = new egret.Bitmap(texture);
this.targetImage.anchorOffsetX = 78;
this.targetImage.anchorOffsetY = 37 / 2;
this.targetImage.anchorOffsetX = texture.textureWidth / 2;
this.targetImage.anchorOffsetY = texture.textureHeight / 2;
this.addChild(this.targetImage);
var arr = []
for (var i = 1; i <= 27; i++) {
arr.push("bonusFra" + i + "_png");
}
this.imageAni = new ImageAni(arr);
this.addChild(this.imageAni);
this.oriImage = new egret.Bitmap(texture);
this.oriImage.anchorOffsetX = texture.textureWidth / 2;
this.oriImage.anchorOffsetY = texture.textureHeight / 2;
this.addChild(this.oriImage);
this.shoot = new egret.Bitmap(RES.getRes("jellyArrow_png"));
this.shoot.anchorOffsetX = 0;
this.shoot.anchorOffsetY = 23 / 2;
this.addChild(this.shoot);
}
play(startP: number[], endP: number[], callback: Function) {
this.x = startP[0];
this.y = startP[1];
//判断方向
this.shoot.visible = true;
this.shoot.x = 0
this.shoot.y = 0;
this.shoot.scaleX = this.shoot.scaleY = 0.01;
this.targetImage.visible = false;
//判断上下左右,
var obj = { scaleX: 0.01, scaleY: 0.01, x: 0, y: 0 };
//x相等 上下
if (Math.abs(endP[0] - startP[0]) <= 0.001) {
//下
if (endP[1] - startP[1] > 0) {
this.shoot.rotation = 90;
this.targetImage.x = 0;
this.targetImage.y = Tool.height;
obj.y = Tool.height;
}
//上
else {
this.shoot.rotation = 270;
this.targetImage.x = 0;
this.targetImage.y = -Tool.height;
obj.y = -Tool.height;
}
}
//y相等 左右
else {
//左
if (endP[0] - startP[0] > 0) {
this.shoot.rotation = 0;
this.targetImage.x = Tool.width;
this.targetImage.y = 0;
obj.x = Tool.width;
}
//右
else {
this.shoot.rotation = 180;
this.targetImage.x = -Tool.width;
this.targetImage.y = 0;
obj.x = -Tool.width;
}
}
egret.Tween.get(this.oriImage)
.to({ scaleX: 1.07, scaleY: 0.89 }, 150)
.to({ scaleX: 0.91, scaleY: 1.07 }, 150)
.to({ scaleX: 1.07, scaleY: 0.89 }, 100)
.to({ scaleX: 0.93, scaleY: 1.06 }, 100)
.to({ scaleX: 1.07, scaleY: 0.93 }, 100)
.to({ scaleX: 1, scaleY: 1 }, 100)
this.imageAni.play(() => {
callback();
if (this.$parent) {
this.$parent.removeChild(this)
};
Pool.recover(RecoverName.JELLYSPREAD_ANI, this)
})
egret.Tween.get(this.shoot)
.to({ scaleX: 2, scaleY: 1 }, 230)
.to(obj, 50)
.call(() => {
callback();
this.shoot.visible = false;
this.targetImage.visible = true;
egret.Tween.get(this.targetImage)
.to({ scaleX: 1.07, scaleY: 0.89 }, 150)
.to({ scaleX: 0.91, scaleY: 1.07 }, 150)
.to({ scaleX: 1.07, scaleY: 0.89 }, 100)
.to({ scaleX: 0.93, scaleY: 1.06 }, 100)
.to({ scaleX: 1.07, scaleY: 0.93 }, 100)
.to({ scaleX: 1, scaleY: 1 }, 100)
.call(() => {
if (this.$parent) {
this.$parent.removeChild(this)
};
Pool.recover(RecoverName.JELLYSPREAD_ANI, this)
})
})
}
}
\ No newline at end of file
import { ImageAni } from "../class/ImageAni";
import { Pool } from "../Pool";
import { RecoverName } from "../enum/RecoverName";
import { playSound, SoundType } from "../../soundCtrl";
import { Tool } from "../Tool";
const offsetX = 91 / 2;
const offsetY = 62 / 2;
/**
* 需要回调的
*
*/
export class PieceToEggAni extends egret.DisplayObjectContainer {
showImage: egret.Bitmap;
eggPiece1: egret.Bitmap;
eggPiece2: egret.Bitmap;
eggPiece3: egret.Bitmap;
eggPiece4: egret.Bitmap;
eggPiece5: egret.Bitmap;
constructor() {
super()
var arr = ["ele9_png", "eggPiece1_png", "eggPiece2_png", "eggPiece3_png", "eggPiece4_png", "eggPiece5_png"];
var objs = ["showImage", "eggPiece1", "eggPiece2", "eggPiece3", "eggPiece4", "eggPiece5"];
for (var i = 0; i < arr.length; i++) {
var texture: egret.Texture = RES.getRes(arr[i])
var obj = new egret.Bitmap(texture);
this.addChild(obj);
obj.anchorOffsetX = texture.textureWidth / 2;
obj.anchorOffsetY = texture.textureHeight / 2;
this[objs[i]] = obj;
}
}
play(p: number[], callback: Function) {
this.x = p[0];
this.y = p[1];
this.showImage.alpha = 0;
egret.Tween.get(this.showImage)
.wait(250)
.to({ alpha: 1 }, 150)
this.alpha = 0;
//整体透明度
egret.Tween.get(this)
.to({ alpha: 1 }, 150)
//下面所有的蛋壳碎片
egret.Tween.get(this.eggPiece1)
.set({ rotation: 60, x: 37 - offsetX - 30, y: 22 - offsetY - 34 })
.to({ rotation: 0, x: 37 - offsetX, y: 22 - offsetY }, 400);
egret.Tween.get(this.eggPiece2)
.set({ rotation: 60, x: 48 - offsetX + 36, y: 20 - offsetY - 28 })
.to({ rotation: 0, x: 48 - offsetX, y: 20 - offsetY }, 400);
egret.Tween.get(this.eggPiece3)
.set({ rotation: 60, x: 52 - offsetX + 30, y: 32 - offsetY + 10 })
.to({ rotation: 0, x: 52 - offsetX, y: 32 - offsetY }, 400);
egret.Tween.get(this.eggPiece4)
.set({ rotation: 60, x: 45 - offsetX + 32, y: 44 - offsetY + 38 })
.to({ rotation: 0, x: 45 - offsetX, y: 44 - offsetY }, 400);
egret.Tween.get(this.eggPiece5)
.set({ rotation: 60, x: 34 - offsetX - 20, y: 34 - offsetY + 14 })
.to({ rotation: 0, x: 34 - offsetX, y: 34 - offsetY }, 400)
.call(() => {
callback();
if (this.$parent) {
this.$parent.removeChild(this)
};
Pool.recover(RecoverName.PIECETOEGG_ANI, this)
})
}
}
\ No newline at end of file
//四种状态的图片
const images = {
3: "ele9_png",
2: "eggStatus2_png",
1: "eggStatus1_png",
0: "eggStatus0_png"
}
/**
* 鸡蛋的状态
*
*/
export class ChickenEgg extends eui.Image {
export class ChickenEgg extends eui.Component {
private showImage: eui.Image;
/**
* 小鸡数量
* 是否孵小鸡
*/
private chickenNum: number = 0;
isActive: boolean;
/**
* 鸡蛋状态变化 3 2 1 0 再往后,直接加孵鸡次数
* 鸡蛋状态变化 3 2 1 0 再往后,可孵鸡
*/
private _statusNum: number;
get statusNum() {
......@@ -17,41 +25,48 @@ export class ChickenEgg extends eui.Image {
set statusNum(value: number) {
if (value >= 0) {
this._statusNum = value;
//修改图片
if (this.showImage.source != images[this._statusNum]) {
this.changeSource(images[this._statusNum]);
}
} else {
this._statusNum = 0;
this.chickenNum++;
this.isActive = true;
}
}
constructor(n: number = 3) {
super()
this.source = "ele7_png";
//图片需要居中
this.showImage = new eui.Image();
this.addChild(this.showImage)
this.changeSource(images[n]);
this.chickenNum = 0;
this.isActive = false;
this._statusNum = n;
}
changeSource(source: string) {
var texture: egret.Texture = RES.getRes(source);
this.showImage.texture = texture
this.showImage.anchorOffsetX = texture.textureWidth / 2;
this.showImage.anchorOffsetY = texture.textureHeight / 2 + 20;
this.showImage.y = 20
}
shakeAni() {
this.showImage.rotation = 0;
egret.Tween.get(this.showImage)
.to({ rotation: 10 }, 80)
.to({ rotation: -8 }, 160)
.to({ rotation: 5 }, 160)
.to({ rotation: 0 }, 50)
}
reset(n: number = 3) {
//图片修改
this.chickenNum = 0;
reset(n: number = 3) {
this.changeSource(images[n]);
this.isActive = false;
this._statusNum = n;
}
/**
* 孵蛋动作
*/
hatch(callback: Function) {
if (!this.chickenNum) {
callback();
return
}
}
}
\ No newline at end of file
......@@ -7,6 +7,7 @@ import { MagicLionBgAni } from "../periodAni/MagicLionBgAni";
import { HorizontalBgAni } from "../periodAni/HorizontalBgAni";
import { VerticalBgAni } from "../periodAni/VerticalBgAni";
import { ExplosiveBgAni } from "../periodAni/ExplosiveBgAni";
import { ChickenEgg } from "./ChickenEgg";
/**
......@@ -17,7 +18,10 @@ export class Element extends eui.Component {
/**
* 初始类型
*/
type: ElementType;
private _type: ElementType;
get type() {
return this._type
}
/**
* 显示的图片,直接改source,"ele"+type+effectType
*/
......@@ -135,13 +139,24 @@ export class Element extends eui.Component {
}
this._isLock = value
}
chickenEgg: ChickenEgg;
constructor(type: ElementType) {
super();
this.type = type;
this._type = type;
this.showImage = new eui.Image();
this.changeSource("ele" + this.type + "_png");
this.addChild(this.showImage);
// this.showImage.touchEnabled=false
if (type == ElementType.CHICKEN_EGG) {
this.chickenEgg = Pool.takeOut(RecoverName.CHICKEN_EGG)
if (!this.chickenEgg) {
//新建,里面是解锁的所有图片组
this.chickenEgg = new ChickenEgg();
} else {
this.chickenEgg.reset();
}
this.addChild(this.chickenEgg)
}
}
/**
......@@ -157,7 +172,7 @@ export class Element extends eui.Component {
this.showImage.y = -texture.textureHeight / 2;
//特殊逻辑,因为魔力鸟动效要旋转,所以隐藏原图showImage
if (source == "magicLion_png") {
if (source == "magicLion_png" || source == "ele9_png") {
this.showImage.alpha = 0;
} else {
this.showImage.alpha = 1;
......@@ -167,7 +182,7 @@ export class Element extends eui.Component {
reset(type: ElementType) {
this.alpha = this.scaleX = this.scaleY = 1;
//类型重置,showImage修改
this.type = type;
this._type = type;
this.changeSource("ele" + type + "_png");
//特效重置
this.effectType = null;
......@@ -180,6 +195,22 @@ export class Element extends eui.Component {
Pool.recover(RecoverName.LOCK_ANI, this.lockAni);
this.lockAni = null;
}
//如果类型是鸡蛋
if (type == ElementType.CHICKEN_EGG) {
this.chickenEgg = this.chickenEgg || Pool.takeOut(RecoverName.CHICKEN_EGG)
if (!this.chickenEgg) {
//新建,里面是解锁的所有图片组
this.chickenEgg = new ChickenEgg();
} else {
this.chickenEgg.reset();
}
this.addChild(this.chickenEgg)
}
else if (this.chickenEgg) {
this.removeChild(this.chickenEgg);
Pool.recover(RecoverName.CHICKEN_EGG, this.chickenEgg);
this.chickenEgg = null;
}
}
private removeHas() {
......
/**
* 特效类型
* 回收类型
*/
export enum RecoverName {
ELEMENT = "Element",
......@@ -12,9 +12,12 @@ export enum RecoverName {
SCORE_ANI = "ScoreAni",
//带回调的动画
BONUSSHOOT_ANI = "BonusShootAni",
JELLYSPREAD_ANI = "JellySpreadAni",
PIECETOEGG_ANI = "PieceToEggAni",
//元素身上
LOCK_ANI = "LockAni",
......@@ -23,6 +26,9 @@ export enum RecoverName {
VERTICALBG_ANI = "VerticalBgAni",
EXPLOSIVEBG_ANI = "ExplosiveBgAni",
//元素身上的鸡蛋
CHICKEN_EGG = "ChickenEgg",
//所有继承ani的,能单独播放的
ROCK_ANI = "RockAni",
ICE_ANI = "IceAni",
......@@ -34,4 +40,6 @@ export enum RecoverName {
THREECROSS_ANI = "ThreeCrossAni",
MAGICLION_ANI = "MagicLionAni",
STEP_ANI = "StepAni",
JELLYDIS_ANI = "JellyDisAni",
EGGBROKEN_ANI = "EggBrokenAni",
}
\ No newline at end of file
......@@ -32,6 +32,7 @@ export interface MapData {
* 3棒棒糖
* 4元素枷锁
* 5果冻
* 6鸡蛋
*/
elements?:number[]
/**
......
......@@ -5,6 +5,12 @@ import { RecoverName } from "../enum/RecoverName";
import { Tool } from "../Tool";
import { ElementType } from "../enum/ElementType";
import { Lattice } from "../class/Lattice";
import { ChickenEgg } from "../class/ChickenEgg";
import { HatchAni } from "../anis/HatchAni";
import { PieceToEggAni } from "../anis/PieceToEggAni";
//孵鸡的数量
const chickenNum: number = 4
export class AiControl {
private static _ins: AiControl
......@@ -15,40 +21,27 @@ export class AiControl {
* 判断是否还有果冻,暂时不考虑果冻无中生有,否则逻辑修改
*/
private hasJelly: boolean;
private hasEgg: boolean;
/**
* 提前记录所有的鸡蛋的索引
*/
private eggs: number[];
init(lattices: Lattice[]) {
this.hasJelly = judgeJellyExist(lattices);
this.hasEgg = judgeEggExist(lattices);
}
aiMotion(thisObj: MainScene, callback: Function) {
//果冻的
this.jellyMotion(thisObj, () => {
//鸡蛋的
this.eggMotion(thisObj, callback)
})
// if (noAction) {
// callback()
// }
this.eggs = getEggs(lattices);
}
private jellyMotion(thisObj: MainScene, callback: Function) {
if (!this.hasJelly || thisObj.jellyBrokeMark) {
thisObj.jellyBrokeMark = false;
jellyMotion(thisObj: MainScene, callback: Function) {
if (!this.hasJelly || thisObj.jellyBrokenMark) {
//没有果冻,或上一步有果冻被消除,直接回调
callback();
thisObj.jellyBrokenMark = false;
return
}
//标识记为false
thisObj.jellyBrokeMark = false;
thisObj.jellyBrokenMark = false;
//果冻蔓延
var spread = getJellySpreadAni(thisObj.lattices);
let spread = getJellySpreadAni(thisObj.lattices);
if (spread) {
//执行动画
let jellySpreadAni: JellySpreadAni = Pool.takeOut(RecoverName.JELLYSPREAD_ANI)
......@@ -56,7 +49,11 @@ export class AiControl {
jellySpreadAni = new JellySpreadAni()
}
thisObj.addChild(jellySpreadAni);
//隐藏原来的元素
thisObj.lattices[spread[0]].element.visible = false;
jellySpreadAni.play(Tool.getPositionByIndex(spread[0]), Tool.getPositionByIndex(spread[1]), () => {
//显示隐藏元素
thisObj.lattices[spread[0]].element.visible = true;
//播放完后,将终点元素变成果冻
thisObj.lattices[spread[1]].element.reset(ElementType.JELLY);
//执行回调
......@@ -76,13 +73,86 @@ export class AiControl {
* @param thisObj
* @param callback
*/
private eggMotion(thisObj: MainScene, callback: Function) {
if (!this.hasEgg) {
eggMotion(thisObj: MainScene, callback: Function) {
//无蛋,直接回调
if (!this.eggs.length) {
callback();
return
}
var activeEggIndexs: number[] = []
//找出所有有鸡的蛋的索引
for (var i = 0; i < this.eggs.length; i++) {
var index = this.eggs[i];
var egg: ChickenEgg = thisObj.lattices[index].element.chickenEgg
if (egg.isActive) activeEggIndexs.push(index);
}
//无有鸡的蛋,直接回调
if (!activeEggIndexs.length) {
callback();
return
}
//逻辑再写,暂时没有
callback();
//找出所有能飞小鸡的格子索引
var chickenIndexs: number[] = [];
for (var a = 0; a < thisObj.lattices.length; a++) {
var lat = thisObj.lattices[a];
if (lat &&
lat.element &&
lat.element.type <= 4) {
chickenIndexs.push(a);
}
}
//如果没有能飞的格子
if (!chickenIndexs.length) {
callback();
return
}
//打乱索引
chickenIndexs.sort(function () {
return (0.5 - Math.random());
});
//拷贝
var chickenIndexsCopy = chickenIndexs.slice();
let countAll = activeEggIndexs.length;
let count = 0;
//开始给每个有鸡的蛋做匹配
for (var b = 0; b < activeEggIndexs.length; b++) {
let activeEggIndex = activeEggIndexs[b];
//从chickenIndexsCopy取四个,不足就在chickenIndexs随个
let four: number[] = chickenIndexsCopy.splice(0, 4);
if (four.length < chickenNum) {
//补上剩下的,如果还不足,就不管
four = four.concat(Tool.getRandomArrayElementsEx(chickenIndexs, chickenNum - four.length))
}
//播蛋壳动画
let activeEgg = thisObj.lattices[activeEggIndex].element.chickenEgg;
activeEgg.visible = false;
HatchAni(activeEggIndex, four, thisObj, () => {
//飞完后恢复蛋的状态
//蛋壳变为蛋的动画,回调里执行吧
let pieceToEggAni: PieceToEggAni = Pool.takeOut(RecoverName.PIECETOEGG_ANI)
if (!pieceToEggAni) {
pieceToEggAni = new PieceToEggAni()
}
thisObj.addChild(pieceToEggAni);
pieceToEggAni.play(Tool.getPositionByIndex(activeEggIndex), () => {
activeEgg.reset();
activeEgg.visible = true;
})
count++;
if (count == countAll) {
setTimeout(() => {
if (thisObj.threeMatch()) {
thisObj.eliminate();
} else {
callback()
}
})
}
})
}
}
......@@ -104,18 +174,24 @@ function judgeJellyExist(lattices: Lattice[]) {
return false;
}
/**
* 判断鸡蛋是否存在
* 获取所有鸡蛋的索引
* @param lattices
* @return false表示不存在,true表示存在
*/
function judgeEggExist(lattices: Lattice[]) {
function getEggs(lattices: Lattice[]) {
var arr = [];
for (var i = 0; i < lattices.length; i++) {
var lattice = lattices[i]
//没有格子或没有元素或不是果冻 跳过
if (!lattice || !lattice.element || lattice.element.type != ElementType.CHICKEN_EGG) continue
return true
if (lattice &&
lattice.element &&
lattice.element.type == ElementType.CHICKEN_EGG
) {
arr.push(i)
}
}
return false;
return arr;
}
......@@ -170,4 +246,4 @@ function judgeSpread(index: number, lattices: Lattice[]): number {
return null
}
//
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