Commit 48e6178b authored by wjf's avatar wjf

l

parent 2597b5d8
...@@ -277,8 +277,8 @@ export default class MainBase extends eui.UILayer { ...@@ -277,8 +277,8 @@ export default class MainBase extends eui.UILayer {
"chooseRect", "chooseRect",
"lightedStar", "lightedStar",
"lineLight", "lineLight",
"lockDown", // "lockDown",
"lockUp", // "lockUp",
"magicLion", "magicLion",
"magicLionBg", "magicLionBg",
"rectLat", "rectLat",
......
...@@ -1929,12 +1929,14 @@ export default class MainScene extends Scene { ...@@ -1929,12 +1929,14 @@ export default class MainScene extends Scene {
} }
//有毛球的 //有毛球的
else if (ele.hasState(StateType.HAIRBALL)) { else if (ele.hasState(StateType.HAIRBALL)) {
//逻辑再写,记录毛球的状态,是破碎还是分裂 ,待写
//破碎直接执行,分裂到下次,方法全写在毛球的状态里
var hairballState: HairballState = ele.getState(StateType.HAIRBALL); var hairballState: HairballState = ele.getState(StateType.HAIRBALL);
//二级毛球的记录需要分裂isActive
if (hairballState.levelNum == 2) { if (hairballState.levelNum == 2) {
hairballState.isActive = true; hairballState.isActive = true;
} else { }
//一级的直接消失
else {
//播放毛球消失动画 //播放毛球消失动画
this.playAni(RecoverName.HAIRBALLDIS_ANI, p) this.playAni(RecoverName.HAIRBALLDIS_ANI, p)
//设为无毛球 //设为无毛球
......
import { ImageAni } from "../class/ImageAni";
import { Pool } from "../Pool";
import { RecoverName } from "../enum/RecoverName";
import { playSound, SoundType } from "../../soundCtrl";
import { Tool } from "../Tool";
import { ElementType } from "../enum/ElementType";
//位置信息暂时都统一,因为现在所有基础5种元素的长宽都是90,如果以后基础元素图修改
const baseEleWidth = 90;
const baseEleHeight = 90;
//动画时间
const time = 300;
/**
* 需要回调的
* 变色气泡动画
*/
export class BubbleAni extends egret.DisplayObjectContainer {
/**
*
*/
private eleFrom: egret.Bitmap;
private eleTarget: egret.Bitmap;
/**
* 气泡动画
* 不用单独回收,整个用
*/
private bubbleAni: ImageAni;
constructor() {
super()
this.eleFrom = new egret.Bitmap();
this.eleFrom.x = -baseEleWidth / 2;
this.eleFrom.y = -baseEleHeight / 2;
this.eleFrom.visible = false;
this.addChild(this.eleFrom);
this.eleTarget = new egret.Bitmap();
this.eleTarget.x = -baseEleWidth / 2;
this.eleTarget.y = -baseEleHeight / 2;
this.eleTarget.visible = false;
this.addChild(this.eleTarget);
//气泡动画
var arr = [];
for (var i = 1; i <= 19; i++) {
arr.push("bubbleStar" + i + "_png");
}
this.bubbleAni = new ImageAni(arr);
this.bubbleAni.visible = false
this.addChild(this.bubbleAni);
}
play(fromType: ElementType, targetType: ElementType, callback: Function) {
this.eleFrom.texture = RES.getRes("bubleEle" + fromType + "_png");
this.eleFrom.visible = true;
this.eleFrom.alpha = 1;
this.eleTarget.texture = RES.getRes("bubleEle" + targetType + "_png");
this.eleTarget.visible = true;
this.eleTarget.alpha = 0;
//缩放,直接改自己的
egret.Tween.get(this)
.to({ scaleX: 0.96, scaleY: 1.02 }, 100)
.to({ scaleX: 1.02, scaleY: 0.98 }, 100)
.to({ scaleX: 0.98, scaleY: 1.02 }, 100)
.to({ scaleX: 1, scaleY: 1 }, 100)
.call(() => {
//气泡
//显示动画
this.bubbleAni.visible = true;
this.bubbleAni.play(() => {
//隐藏动画
this.bubbleAni.visible = false;
})
//透明度
egret.Tween.get(this.eleTarget)
.to({ alpha: 1 }, 600)
.call(() => {
egret.Tween.get(this.eleFrom)
.to({ alpha: 0 }, 100)
.call(() => {
if (this.$parent) {
this.$parent.removeChild(this)
};
Pool.recover(RecoverName.BUBBLE_ANI, this);
//回调
callback();
})
})
})
}
}
\ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
/** /**
* 直接通过替换source替换图片的动画帧 * 直接通过替换source替换图片的动画帧
* 暂时这些动画帧只播放一次,所以简化 * 暂时这些动画帧只播放一次,所以简化
* 默认按时间间隔播放 * 按时间间隔播放
* 图片都以素材为中心为原点 * 图片都以素材为中心为原点
*/ */
export class ImageAni extends eui.Image { export class ImageAni extends eui.Image {
...@@ -27,10 +27,7 @@ export class ImageAni extends eui.Image { ...@@ -27,10 +27,7 @@ export class ImageAni extends eui.Image {
constructor(sourceAll: string[]) { constructor(sourceAll: string[]) {
super() super()
this.sourceAll = sourceAll; this.sourceAll = sourceAll;
this.texture = RES.getRes(sourceAll[0]) this.changeSource(sourceAll[0])
// this.source = sourceAll[0];
this.x = -this.texture.textureWidth / 2;
this.y = -this.texture.textureHeight / 2;
this.currentFrame = 0; this.currentFrame = 0;
this.totalFrames = sourceAll.length; this.totalFrames = sourceAll.length;
this.addEventListener(egret.Event.ENTER_FRAME, this.onEnterFrame, this) this.addEventListener(egret.Event.ENTER_FRAME, this.onEnterFrame, this)
...@@ -64,9 +61,7 @@ export class ImageAni extends eui.Image { ...@@ -64,9 +61,7 @@ export class ImageAni extends eui.Image {
this.callback && this.callback(); this.callback && this.callback();
} else { } else {
this.currentFrame = (scale * this.sourceAll.length) >> 0; this.currentFrame = (scale * this.sourceAll.length) >> 0;
this.texture = RES.getRes(this.sourceAll[this.currentFrame]) this.changeSource(this.sourceAll[this.currentFrame])
this.x = -this.texture.textureWidth / 2;
this.y = -this.texture.textureHeight / 2;
} }
} }
/** /**
...@@ -77,9 +72,7 @@ export class ImageAni extends eui.Image { ...@@ -77,9 +72,7 @@ export class ImageAni extends eui.Image {
this.startTime = Date.now(); this.startTime = Date.now();
this.isPlay = true; this.isPlay = true;
this.currentFrame = 0; this.currentFrame = 0;
this.texture = RES.getRes(this.sourceAll[this.currentFrame]) this.changeSource(this.sourceAll[this.currentFrame])
this.x = -this.texture.textureWidth / 2;
this.y = -this.texture.textureHeight / 2;
this.callback = callback; this.callback = callback;
} }
...@@ -89,8 +82,18 @@ export class ImageAni extends eui.Image { ...@@ -89,8 +82,18 @@ export class ImageAni extends eui.Image {
reset() { reset() {
this.isPlay = false; this.isPlay = false;
this.currentFrame = 0; this.currentFrame = 0;
this.texture = RES.getRes(this.sourceAll[0]) this.changeSource(this.sourceAll[0])
this.x = -this.texture.textureWidth / 2; }
this.y = -this.texture.textureHeight / 2;
private changeSource(source: string) {
if (source) {
this.texture = RES.getRes(source)
this.x = -this.texture.textureWidth / 2;
this.y = -this.texture.textureHeight / 2;
} else {
//表示为空
this.texture = null
}
} }
} }
\ No newline at end of file
...@@ -16,6 +16,7 @@ export enum RecoverName { ...@@ -16,6 +16,7 @@ export enum RecoverName {
BONUSSHOOT_ANI = "BonusShootAni", BONUSSHOOT_ANI = "BonusShootAni",
JELLYSPREAD_ANI = "JellySpreadAni", JELLYSPREAD_ANI = "JellySpreadAni",
PIECETOEGG_ANI = "PieceToEggAni", PIECETOEGG_ANI = "PieceToEggAni",
BUBBLE_ANI = "BubbleAni",
......
...@@ -41,7 +41,7 @@ export class AiControl { ...@@ -41,7 +41,7 @@ export class AiControl {
* 是否有鸡蛋, * 是否有鸡蛋,
* 是否有毛球, * 是否有毛球,
* 是否有变色气泡, * 是否有变色气泡,
* 必须在初始化元素后执行 * 必须在初始化元素后执行,每关进入游戏都会初始化
* @param lattices * @param lattices
*/ */
init(lattices: Lattice[]) { init(lattices: Lattice[]) {
...@@ -52,40 +52,65 @@ export class AiControl { ...@@ -52,40 +52,65 @@ export class AiControl {
} }
jellyMotion(thisObj: MainScene, callback: Function) { jellyMotion(thisObj: MainScene, callback: Function) {
//没有果冻,或上一步有果冻被消除,直接回调
if (!this.hasJelly || thisObj.jellyBrokenMark) { if (!this.hasJelly || thisObj.jellyBrokenMark) {
//没有果冻,或上一步有果冻被消除,直接回调
callback(); callback();
//都要标记置否
thisObj.jellyBrokenMark = false; thisObj.jellyBrokenMark = false;
return return
} }
//标识记为false //标识记为false
thisObj.jellyBrokenMark = false; thisObj.jellyBrokenMark = false;
//果冻蔓延 //找出所有果冻索引
let spread = getJellySpreadAni(thisObj.lattices); var indexs: number[] = [];
if (spread) { for (var i = 0; i < thisObj.lattices.length; i++) {
//执行动画 var lattice = thisObj.lattices[i]
let jellySpreadAni: JellySpreadAni = Pool.takeOut(RecoverName.JELLYSPREAD_ANI) //没有格子或没有元素或不是果冻 跳过
if (!jellySpreadAni) { if (!lattice || !lattice.element || lattice.element.type != ElementType.JELLY) continue
jellySpreadAni = new JellySpreadAni() indexs.push(i);
} }
thisObj.addChild(jellySpreadAni); //如果没有果冻,直接回调
//隐藏原来的元素 if (!indexs.length) {
thisObj.lattices[spread[0]].element.visible = false; //标记为无果冻
jellySpreadAni.play(Tool.getPositionByIndex(spread[0]), Tool.getPositionByIndex(spread[1]), () => { this.hasJelly = false;
//显示隐藏元素 callback();
thisObj.lattices[spread[0]].element.visible = true; return
//播放完后,将终点元素变成果冻 }
thisObj.lattices[spread[1]].element.reset(ElementType.JELLY); //获取果冻动画,0是自身索引,1是终点索引
//执行回调 let spread: number[];
callback() while (indexs.length) {
}) //随机取
} else { var rand = Math.floor(Math.random() * indexs.length);
callback() var randIndex = indexs.splice(rand, 1)[0];
if (spread === 0) { var index = judgeSpread(randIndex, thisObj.lattices);
//如果无果冻了 //考虑0,判断null,有就break
this.hasJelly = false; if (index != null) {
//能蔓延,返回自身索引和蔓延的索引
spread = [randIndex, index];
break;
} }
} }
//如果没有能蔓延的,直接回调
if (!spread) {
callback();
return
}
//果冻蔓延动画
let jellySpreadAni: JellySpreadAni = Pool.takeOut(RecoverName.JELLYSPREAD_ANI)
if (!jellySpreadAni) {
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);
//执行回调
callback()
})
} }
/** /**
* 鸡蛋得孵化逻辑 * 鸡蛋得孵化逻辑
...@@ -190,21 +215,41 @@ export class AiControl { ...@@ -190,21 +215,41 @@ export class AiControl {
return return
} }
//找出所有的气泡 //找出所有的气泡
var indexs = []; var indexs: number[] = [];
for (var i = 0; i < thisObj.lattices.length; i++) { for (var i = 0; i < thisObj.lattices.length; i++) {
var lat = thisObj.lattices[i]; var lat = thisObj.lattices[i];
//是基础元素,有气泡状态 //是基础元素,有气泡状态
if (Tool.judgeBaseEle(lat) && !lat.element.hasState(StateType.BUBBLE)) { if (Tool.judgeBaseEle(lat) && !lat.element.hasState(StateType.BUBBLE)) {
indexs.push(i); indexs.push(i);
} }
}
if (!indexs.length) {
} }
let count = 0; let count = 0;
let contAll = indexs.length; let countAll = indexs.length;
//对所有气泡进行变色处理 //对所有气泡进行变色处理
for (var a = 0; a < indexs.length; a++) { for (var a = 0; a < countAll; a++) {
let index = indexs[a];
let lat = thisObj.lattices[index];
let ele = lat.element;
//计算type
let type: ElementType = 1;
//直接重置类型,为了后续计算,但是要隐藏,待动画播放完显示
ele.resetType(type);
ele.visible = false;
///重写
ele.getState(StateType.BUBBLE).play(type, () => {
//播完重置类型
ele.resetType(type)
count++;
if (count == countAll) {
callback();
}
})
} }
} }
...@@ -269,34 +314,6 @@ function getEggs(lattices: Lattice[]) { ...@@ -269,34 +314,6 @@ function getEggs(lattices: Lattice[]) {
return arr; return arr;
} }
/**
* 获取能蔓延的果冻
* @param lattices
* @return 返回自身索引和蔓延的索引
*/
function getJellySpreadAni(lattices: Lattice[]) {
var indexs: number[] = [];
for (var i = 0; i < lattices.length; i++) {
var lattice = lattices[i]
//没有格子或没有元素或不是果冻 跳过
if (!lattice || !lattice.element || lattice.element.type != ElementType.JELLY) continue
indexs.push(i);
}
//没有果冻,返回0
if (!indexs.length) return 0
while (indexs.length) {
var rand = Math.floor(Math.random() * indexs.length);
var randIndex = indexs.splice(rand, 1)[0];
var index = judgeSpread(randIndex, lattices);
if (index != null) {
//能蔓延,返回自身索引和蔓延的索引
return [randIndex, index];
}
}
return null;
}
/** /**
* 判断可蔓延的方向,并返回蔓延的格子索引 * 判断可蔓延的方向,并返回蔓延的格子索引
* @param index * @param index
......
...@@ -4,89 +4,38 @@ import { State } from "../class/State"; ...@@ -4,89 +4,38 @@ import { State } from "../class/State";
import { Pool } from "../Pool"; import { Pool } from "../Pool";
import { RecoverName } from "../enum/RecoverName"; import { RecoverName } from "../enum/RecoverName";
import { ElementType } from "../enum/ElementType"; import { ElementType } from "../enum/ElementType";
import { ImageAni } from "../class/ImageAni";
//5种类型对应5种颜色
//位置信息暂时都统一,因为现在所有基础5种元素的长宽都是90,如果以后基础元素图修改
const baseEleWidth = 90;
const baseEleHeight = 90;
//动画时间
const time = 300;
/** /**
* 变色气泡状态 * 变色气泡状态
* 变色动画放外面
*/ */
export class BubbleState extends State { export class BubbleState extends State {
/** /**
* * 显示图片
*/
private eleImage: egret.Bitmap;
private eleImageOther: egret.Bitmap;
/**
* 气泡动画
* 不用回收,整个用
*/
private bubbleAni: ImageAni;
/**
* 基础类型
*/ */
private type: ElementType private showImage: egret.Bitmap;
constructor(type: ElementType) { constructor(type: ElementType) {
super(); super();
this.type = type this.showImage = new egret.Bitmap();
this.eleImage = new egret.Bitmap(); this.changeSource("bubleEle" + type + "_png");
this.eleImage.x = -baseEleWidth / 2; this.addChild(this.showImage);
this.eleImage.y = -baseEleHeight / 2;
this.eleImage.texture = RES.getRes("bubleEle" + type + "_png");
this.addChild(this.eleImage);
this.eleImageOther = new egret.Bitmap();
this.eleImageOther.x = -baseEleWidth / 2;
this.eleImageOther.y = -baseEleHeight / 2;
this.eleImageOther.visible = false;
this.addChild(this.eleImageOther);
//气泡动画,图片再放
this.bubbleAni = new ImageAni([]);
this.bubbleAni.visible = false
this.addChild(this.bubbleAni);
} }
/**
* 先隐藏自己的Ele,通过这里的过度动画后再显示,
* 回调里 执行,重置元素基础类型,都执行完的回调
* @param fromType
* @param targetType
* @param callback
*/
play(targetType: ElementType, callback: Function) {
this.eleImageOther.texture = RES.getRes("bubleEle" + targetType + "_png");
this.eleImageOther.visible = true;
this.eleImageOther.alpha = 0;
egret.Tween.get(this.eleImageOther)
.to({ alpha: 1 }, time)
.call(() => {
this.eleImageOther.visible = false;
callback()
})
egret.Tween.get(this.eleImage)
.to({ alpha: 0 }, time)
//显示动画
this.bubbleAni.visible = true;
this.bubbleAni.play(() => {
//隐藏动画
this.bubbleAni.visible = false;
})
}
//重置为指定的类型,直接设置。没有过度动效 //重置为指定的类型,直接设置。没有过度动效
reset(type: ElementType) { reset(type: ElementType) {
this.type = type; this.changeSource("bubleEle" + type + "_png");
this.eleImage.alpha = 1;
this.eleImage.texture = RES.getRes("bubleEle" + type + "_png");
} }
//直接回收 //直接回收
recover() { recover() {
if (this.parent) this.parent.removeChild(this); if (this.parent) this.parent.removeChild(this);
Pool.recover(RecoverName.HAIRBALL_STATE, this); Pool.recover(RecoverName.HAIRBALL_STATE, this);
} }
private changeSource(source: string) {
var texture: egret.Texture = RES.getRes(source);
this.showImage.texture = texture;
this.showImage.x = -texture.textureWidth / 2;
this.showImage.y = -texture.textureHeight / 2
}
} }
\ No newline at end of file
...@@ -6,7 +6,8 @@ import { RecoverName } from "../enum/RecoverName"; ...@@ -6,7 +6,8 @@ import { RecoverName } from "../enum/RecoverName";
import { ElementType } from "../enum/ElementType"; import { ElementType } from "../enum/ElementType";
/** /**
* 枷锁状态 * 毛球状态
* 消失动画。和分裂动画都在外面单独掉
*/ */
export class HairballState extends State { export class HairballState extends State {
private showImage: egret.Bitmap; private showImage: egret.Bitmap;
......
export class LockAni extends egret.DisplayObjectContainer {
private showImage: egret.Bitmap;
constructor() {
super()
var texture: egret.Texture = RES.getRes("lockVine_png")
this.showImage = new egret.Bitmap(texture);
this.addChild(this.showImage);
this.showImage.x = -texture.textureWidth / 2;
this.showImage.y = -texture.textureHeight / 2
}
/**
* 重置
*/
reset() {
this.alpha = 1;
}
play(callback: Function) {
egret.Tween.get(this)
.to({ alpha: 0 }, 750)
.call(() => {
if (this.parent) this.parent.removeChild(this);
if (callback) callback();
})
}
}
// export class LockAni extends Ani {
// lockUp: eui.Image;
// lockDown: eui.Image;
// constructor() {
// super()
// this.aniName = "LockAni";
// this.lockDown = new eui.Image("lockDown_png");
// this.addChild(this.lockDown);
// setTimeout(() => {
// this.lockDown.x = -this.lockDown.width / 2;
// this.lockDown.y = -this.lockDown.height / 2
// })
// //遮罩
// var mask = new egret.Shape();
// mask.graphics.beginFill(0xff0000, 1);
// mask.graphics.drawRect(-77 / 2, -78 / 2, 77, 78)
// mask.graphics.endFill();
// this.addChild(mask);
// this.lockDown.mask = mask;
// this.lockUp = new eui.Image("lockUp_png");
// this.addChild(this.lockUp);
// setTimeout(() => {
// this.lockUp.x = -this.lockUp.width / 2;
// this.lockUp.y = -this.lockUp.height / 2
// })
// }
// /**
// * 重置
// */
// reset() {
// this.alpha = 1;
// this.lockDown.y = -78 / 2
// // egret.Tween.removeTweens(this.lockDown);
// }
// play() {
// // this.reset();
// egret.Tween.get(this.lockDown)
// .to({ y: -78 - 78 / 2 }, 500)
// .call(() => {
// egret.Tween.get(this)
// .to({ alpha: 0 }, 250)
// .call(() => {
// this.recover();
// })
// })
// }
// }
\ No newline at end of file
...@@ -6,6 +6,7 @@ import { RecoverName } from "../enum/RecoverName"; ...@@ -6,6 +6,7 @@ import { RecoverName } from "../enum/RecoverName";
/** /**
* 枷锁状态 * 枷锁状态
* 动画比较简单,直接写这里
*/ */
export class LockState extends State { export class LockState extends State {
private showImage: egret.Bitmap; private showImage: egret.Bitmap;
...@@ -28,4 +29,85 @@ export class LockState extends State { ...@@ -28,4 +29,85 @@ export class LockState extends State {
Pool.recover(RecoverName.LOCK_STATE, this); Pool.recover(RecoverName.LOCK_STATE, this);
}) })
} }
} }
\ No newline at end of file
// export class LockAni extends egret.DisplayObjectContainer {
// private showImage: egret.Bitmap;
// constructor() {
// super()
// var texture: egret.Texture = RES.getRes("lockVine_png")
// this.showImage = new egret.Bitmap(texture);
// this.addChild(this.showImage);
// this.showImage.x = -texture.textureWidth / 2;
// this.showImage.y = -texture.textureHeight / 2
// }
// /**
// * 重置
// */
// reset() {
// this.alpha = 1;
// }
// play(callback: Function) {
// egret.Tween.get(this)
// .to({ alpha: 0 }, 750)
// .call(() => {
// if (this.parent) this.parent.removeChild(this);
// if (callback) callback();
// })
// }
// }
// export class LockAni extends Ani {
// lockUp: eui.Image;
// lockDown: eui.Image;
// constructor() {
// super()
// this.aniName = "LockAni";
// this.lockDown = new eui.Image("lockDown_png");
// this.addChild(this.lockDown);
// setTimeout(() => {
// this.lockDown.x = -this.lockDown.width / 2;
// this.lockDown.y = -this.lockDown.height / 2
// })
// //遮罩
// var mask = new egret.Shape();
// mask.graphics.beginFill(0xff0000, 1);
// mask.graphics.drawRect(-77 / 2, -78 / 2, 77, 78)
// mask.graphics.endFill();
// this.addChild(mask);
// this.lockDown.mask = mask;
// this.lockUp = new eui.Image("lockUp_png");
// this.addChild(this.lockUp);
// setTimeout(() => {
// this.lockUp.x = -this.lockUp.width / 2;
// this.lockUp.y = -this.lockUp.height / 2
// })
// }
// /**
// * 重置
// */
// reset() {
// this.alpha = 1;
// this.lockDown.y = -78 / 2
// // egret.Tween.removeTweens(this.lockDown);
// }
// play() {
// // this.reset();
// egret.Tween.get(this.lockDown)
// .to({ y: -78 - 78 / 2 }, 500)
// .call(() => {
// egret.Tween.get(this)
// .to({ alpha: 0 }, 250)
// .call(() => {
// this.recover();
// })
// })
// }
// }
\ No newline at end of file
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