|
|
|
|
@ -1,12 +1,16 @@
|
|
|
|
|
|
|
|
|
|
const {ccclass, property} = cc._decorator;
|
|
|
|
|
|
|
|
|
|
import {gameMY} from './gameModule';
|
|
|
|
|
import {gameMY, moduleState} from './gameModule';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const eventTarget = new cc.EventTarget();
|
|
|
|
|
export enum columnState {
|
|
|
|
|
Ready = 1,
|
|
|
|
|
Spining = 2,
|
|
|
|
|
Stopping = 3,
|
|
|
|
|
|
|
|
|
|
enum columnState {
|
|
|
|
|
|
|
|
|
|
EngStop = 99,
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -20,15 +24,14 @@ export class columnControl extends cc.Component {
|
|
|
|
|
@property((cc.Node))
|
|
|
|
|
gameModule: cc.Node;
|
|
|
|
|
|
|
|
|
|
private nowAction = null;
|
|
|
|
|
@property(Number)
|
|
|
|
|
rollSpeed:number = 1;
|
|
|
|
|
|
|
|
|
|
// private nowAction = null;
|
|
|
|
|
private columnItem: Array<number> = [];
|
|
|
|
|
private itemList:Array<number>;
|
|
|
|
|
private gameModuleScript;
|
|
|
|
|
|
|
|
|
|
actionSet = {
|
|
|
|
|
"stayPosition": cc.moveTo(0, new cc.Vec2(0, 240)),
|
|
|
|
|
"rollingUp2Button": cc.sequence(cc.moveTo(0, new cc.Vec2(0, 240)), cc.moveBy(1.5, new cc.Vec2(0, -240))),
|
|
|
|
|
};
|
|
|
|
|
private gameModuleScript:gameMY;
|
|
|
|
|
nowState:columnState;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected onLoad () {
|
|
|
|
|
@ -36,57 +39,77 @@ export class columnControl extends cc.Component {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected start () {
|
|
|
|
|
cc.log("this columnControl start");
|
|
|
|
|
|
|
|
|
|
this.itemList = Object.values(this.gameModuleScript.itemNameMapping);
|
|
|
|
|
|
|
|
|
|
// column 位置初始化
|
|
|
|
|
this.node.y = this.gameModuleScript.itemSize;
|
|
|
|
|
|
|
|
|
|
// 隨機初始化 item 圖片
|
|
|
|
|
for(let i=0;i<this.node.childrenCount;i++){
|
|
|
|
|
let a = this.itemList[Math.floor(Math.random() * 12)];
|
|
|
|
|
this.columnItem.unshift( a );
|
|
|
|
|
this.columnItem.push( a );
|
|
|
|
|
this.node.children[i].getComponent(cc.Sprite).spriteFrame = this.gameModuleScript.item_spriteFrame[a]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.nowAction = this.node.runAction(this.actionSet["stayPosition"]);
|
|
|
|
|
|
|
|
|
|
this.nowState = columnState.Ready;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected update (dt) {
|
|
|
|
|
if(this.nowAction.isDone() == true) {
|
|
|
|
|
let a = this.itemList[Math.floor(Math.random() * 12)];
|
|
|
|
|
this.columnItem.unshift( a );
|
|
|
|
|
this.columnItem.pop();
|
|
|
|
|
|
|
|
|
|
//換圖
|
|
|
|
|
for(let i=0;i<this.columnItem.length;i++){
|
|
|
|
|
this.node.children[i].getComponent(cc.Sprite).spriteFrame = this.gameModuleScript.item_spriteFrame[this.columnItem[i]]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//移動位置
|
|
|
|
|
this.nowAction = this.node.runAction(this.actionSet["rollingUp2Button"]);
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
|
|
let dY = Math.ceil(this.rollSpeed * this.gameModuleScript.itemSize * dt)
|
|
|
|
|
|
|
|
|
|
switch(this.nowState){
|
|
|
|
|
case columnState.Ready:
|
|
|
|
|
//狀態檢查與更新
|
|
|
|
|
if(this.gameModuleScript.nowState == moduleState.Spining){
|
|
|
|
|
this.nowState = columnState.Spining;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case columnState.Spining:
|
|
|
|
|
if(this.node.y - dY <= 0){
|
|
|
|
|
this.node.y = this.node.y + this.gameModuleScript.itemSize - dY;
|
|
|
|
|
//更新圖片
|
|
|
|
|
this.prepareNextItem();
|
|
|
|
|
for(let i=0;i<this.columnItem.length;i++){
|
|
|
|
|
this.node.children[i].getComponent(cc.Sprite).spriteFrame = this.gameModuleScript.itemBlur_spriteFrame[this.columnItem[i]];
|
|
|
|
|
}
|
|
|
|
|
//狀態檢查與更新
|
|
|
|
|
if(this.gameModuleScript.nowState == moduleState.Stopping){
|
|
|
|
|
this.nowState = columnState.Stopping;
|
|
|
|
|
}
|
|
|
|
|
}else{this.node.y -= dY;}
|
|
|
|
|
break;
|
|
|
|
|
case columnState.Stopping:
|
|
|
|
|
if(this.node.y - dY <= 0){
|
|
|
|
|
this.node.y = this.gameModuleScript.itemSize;
|
|
|
|
|
//更新圖片
|
|
|
|
|
this.prepareNextItem();
|
|
|
|
|
for(let i=0;i<this.columnItem.length;i++){
|
|
|
|
|
this.node.children[i].getComponent(cc.Sprite).spriteFrame = this.gameModuleScript.item_spriteFrame[this.columnItem[i]];
|
|
|
|
|
}
|
|
|
|
|
this.gameModule.emit("AColumnStop")
|
|
|
|
|
//狀態檢查與更新
|
|
|
|
|
this.nowState = columnState.Ready; // 狀態復歸
|
|
|
|
|
|
|
|
|
|
}else{this.node.y -= dY;}
|
|
|
|
|
break;
|
|
|
|
|
case columnState.EngStop:
|
|
|
|
|
// To Nothing just stop whole column
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prepareNextItem() {
|
|
|
|
|
let a = this.itemList[Math.floor(Math.random() * this.itemList.length)];
|
|
|
|
|
this.columnItem.unshift( a );
|
|
|
|
|
this.columnItem.pop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 用 tween 做動畫
|
|
|
|
|
// cc.tween(b)
|
|
|
|
|
// .to(1, { position: cc.v2(100, 0), rotation: 360 })
|
|
|
|
|
// .to(1, { position: cc.v2(0, 0), rotation: 0 })
|
|
|
|
|
// // .to(1, { scale: 2 })
|
|
|
|
|
// .start()
|
|
|
|
|
|
|
|
|
|
// 用 Action 做動畫
|
|
|
|
|
// var seq = cc.sequence(cc.moveBy(1.5, cc.Vec2(100, 50)), cc.moveBy(1.5, cc.Vec2(-100, -50)));
|
|
|
|
|
// b.runAction(this.seq)
|
|
|
|
|
// c.runAction(this.seq) // 失敗 seq 不能一次賦予兩個物件一樣動作
|
|
|
|
|
// this.bigFrameString.node.runAction(seq)
|
|
|
|
|
|