| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454 |
- import Beef, { BeefState, FoodType } from "./Beef";
- import gameScene from "./gameScene";
- import guidePanel from "./guide/guidePanel";
- import { App } from "./Manager/App";
- import Person, { PersonState } from "./Person";
- const {ccclass, property} = cc._decorator;
- @ccclass
- export default class Table extends cc.Component {
- private static _instance: Table = null;
- // @property([cc.SpriteFrame])
- // private tableSpriteFrame: cc.SpriteFrame[] = [];
- @property(cc.Button)
- btnShengNiuPai: cc.Button = null;
- rawSteakList: cc.Node[] = [null, null, null, null];
- cookedSteakList: cc.Node[] = [null, null, null, null];
- @property(cc.Prefab)
- prefabBeef: cc.Prefab = null;
- @property(cc.Button)
- btnYellowSouce: cc.Button = null;
- @property(cc.Button)
- btnCocumber: cc.Button = null;
- @property(cc.Button)
- btnTomato: cc.Button = null;
- @property(cc.Button)
- btnRedSouce: cc.Button = null;
- @property(cc.Node)
- liuShui: cc.Node = null;
- @property(cc.Node)
- drinkCup: cc.Node = null;
- @property([cc.Node])
- kaoPanGaiZi: cc.Node[] = [];
- @property([cc.Node])
- plateGaiZi: cc.Node[] = [];
- @property([cc.Node])
- cupGaiZi: cc.Node[] = [];
- @property(cc.ProgressBar)
- pDrinkBar: cc.ProgressBar = null;
- m_shuiLiuTime = 3;
- @property(cc.Prefab)
- fullCup: cc.Prefab = null;
- drinkCupList: cc.Node[] = [];
- kaoPanNum = 2;
- plateNum = 2;
- cupNum = 3;
- beefBornPos: cc.Vec3[] = [cc.v3(-290, -185, 0), cc.v3(-197, -195, 0), cc.v3(-243, -131, 0), cc.v3(-160, -133, 0)];
- platePos: cc.Vec3[] = [cc.v3(-58, -200, 0), cc.v3(80, -201, 0), cc.v3(-52, -126, 0), cc.v3(68, -131, 0)];
- burntPos: cc.Vec3 = cc.v3(-360, -640, 0);
- cupPos: cc.Vec3[] = [cc.v3(258, -209, 0), cc.v3(232, -161, 0), cc.v3(205, -115, 0)];
- // ------------------------person---------------------------
- @property([cc.Prefab])
- renwuPerfabList:cc.Prefab[] = [];
- personList: cc.Node[] = [];
- // 点餐位置
- personPos:cc.Vec3[] = [cc.v3(30, 38, 0), cc.v3(260, 38, 0), cc.v3(-200, 38, 0)];
- // 人物出生位置
- bornPos: cc.Vec3[] = [cc.v3(-500, 38, 0), cc.v3(550, 38, 0)];
- fixTime = 1;
- passTime = 0;
- personWalkTime = 2;
- createpPersonNum = 0; //已经来了到少人
- fullPersonNum = 0; //多少吃饱了
- maxSitPersonNum = 3; //总共只能坐下人数
- // LIFE-CYCLE CALLBACKS:
- public static getInstance(): any {
- if (this._instance == null) {
- this._instance = new Table();
- }
- return this._instance;
- }
- onLoad () {
- Table._instance = this;
- this.btnShengNiuPai.node.on(cc.Node.EventType.TOUCH_END, this.onClickShengNiuPai.bind(this), this);
- this.btnYellowSouce.node.on(cc.Node.EventType.TOUCH_END, this.onClickYellowSouce.bind(this), this);
- this.btnCocumber.node.on(cc.Node.EventType.TOUCH_END, this.onClickCocumber.bind(this), this);
- this.btnTomato.node.on(cc.Node.EventType.TOUCH_END, this.onClickTomato.bind(this), this);
- this.btnRedSouce.node.on(cc.Node.EventType.TOUCH_END, this.onClickRedSouce.bind(this), this);
- // this.drinksMachine.node.on(cc.Node.EventType.TOUCH_END, this.onClickDrinksMachine.bind(this), this);
- for (let i = 0; i < this.maxSitPersonNum; i++) {
- this.personList[i] = null;
- }
- this.plateNum = App.DataManager.kitchenNum[0][App.DataManager.kinchenLevel[0]];
- this.kaoPanNum = App.DataManager.kitchenNum[1][App.DataManager.kinchenLevel[1]];
- this.cupNum = App.DataManager.kitchenNum[2][App.DataManager.kinchenLevel[2]];
- }
- start () {
- for (let i = 0; i < this.kaoPanNum - 2; i++) {
- this.kaoPanGaiZi[i].active = false
- }
- for (let i = 0; i < this.plateNum - 2; i++) {
- this.plateGaiZi[i].active = true
- }
- for (let i = 0; i < this.cupNum - 1; i++) {
- this.cupGaiZi[i].active = true
- }
- if(App.DataManager.CurrentIntoLevel >= 3){
- this.btnTomato.node.active = true;
- }
- if(App.DataManager.CurrentIntoLevel >= 5){
- this.btnYellowSouce.node.active = true;
- }
- if(App.DataManager.CurrentIntoLevel >= 7){
- this.btnRedSouce.node.active = true;
- }
- this.onClickDrinksMachine();
- if(App.DataManager.guideStep == 0){
- guidePanel.getInstance().showCurGuide();
- }
- }
- onClickShengNiuPai(){
- if(App.DataManager.guideStep == 0){
- App.DataManager.guideStep++;
- App.LocalStorageUtil.setNumber(App.LocalStorageUtil.str_guideStep, App.DataManager.guideStep);
- guidePanel.getInstance().hideGuideStep();
- }
-
- for (let i = 0; i < this.kaoPanNum; i++) {
- if(this.rawSteakList[i] == null){
- let beef = cc.instantiate(this.prefabBeef);
- beef.on(cc.Node.EventType.TOUCH_END, this.onClickRawBeef.bind(this, i), beef);
- beef.setPosition(this.beefBornPos[i]);
- this.node.addChild(beef);
- this.rawSteakList[i] = beef;
- break;
- }
- }
- }
- onClickRawBeef(index: number){
- if(this.rawSteakList[index].getComponent(Beef).m_state == BeefState.Burnt){
- cc.tween(this.rawSteakList[index]).to(0.5, {position: this.burntPos}).removeSelf().start()
- this.rawSteakList[index] = null;
- return;
- }
- else if(this.rawSteakList[index].getComponent(Beef).m_state == BeefState.Cooked){
- for (let i = 0; i < this.plateNum; i++) {
- if(!this.cookedSteakList[i])
- {
- this.rawSteakList[index].targetOff(this.rawSteakList[index]);
- // this.rawSteakList[index].off(cc.Node.EventType.TOUCH_END, this.onClickRawBeef.bind(this, index), this);
- this.cookedSteakList[i] = this.rawSteakList[index];
- this.rawSteakList[index] = null;
-
- // 从烤架移动到盘子里面
- this.cookedSteakList[i].getComponent(Beef).setState(BeefState.Plate);
- this.cookedSteakList[i].on(cc.Node.EventType.TOUCH_END, this.onClickCookedBeef.bind(this, i), this);
- cc.tween(this.cookedSteakList[i]).to(0.5, {position: this.platePos[i]}).start()
- break;
- }
- }
- if(App.DataManager.guideStep == 1){
- App.DataManager.guideStep++;
- App.LocalStorageUtil.setNumber(App.LocalStorageUtil.str_guideStep, App.DataManager.guideStep);
- guidePanel.getInstance().showCurGuide();
- }
-
- }
- }
- // 点击熟牛排
- onClickCookedBeef(index: number){
- if(App.DataManager.guideStep == 3){
- App.DataManager.guideStep++;
- App.LocalStorageUtil.setNumber(App.LocalStorageUtil.str_guideStep, App.DataManager.guideStep);
- guidePanel.getInstance().showCurGuide();
- }
- // todo 移动到人
- // 移动到人之后,从数组里面删除
- let toPos = this.findFoodPos(this.cookedSteakList[index].getComponent(Beef).m_foodType);
- if(toPos){
- let pos = this.node.convertToNodeSpaceAR(toPos);
- cc.tween(this.cookedSteakList[index]).to(0.5, {position: pos, scale: 0.5}).removeSelf().start();
- this.cookedSteakList[index] = null;
- }
- }
- onClickYellowSouce(){
- for (let i = 0; i < this.cookedSteakList.length; i++) {
- if(this.cookedSteakList[i] && this.cookedSteakList[i].getComponent(Beef).m_state == BeefState.Cocumber){
- this.cookedSteakList[i].getComponent(Beef).setState(BeefState.YellowSouce);
- break;
- }
- }
- }
- onClickCocumber(){
- if(App.DataManager.guideStep == 2){
- App.DataManager.guideStep++;
- App.LocalStorageUtil.setNumber(App.LocalStorageUtil.str_guideStep, App.DataManager.guideStep);
- guidePanel.getInstance().showCurGuide();
- }
- for (let i = 0; i < this.cookedSteakList.length; i++) {
- if(this.cookedSteakList[i] && this.cookedSteakList[i].getComponent(Beef).m_state == BeefState.Plate){
- this.cookedSteakList[i].getComponent(Beef).setState(BeefState.Cocumber);
- break;
- }
- }
- }
- onClickTomato(){
- for (let i = 0; i < this.cookedSteakList.length; i++) {
- if(this.cookedSteakList[i] && this.cookedSteakList[i].getComponent(Beef).m_state == BeefState.Plate){
- this.cookedSteakList[i].getComponent(Beef).setState(BeefState.Tomato);
- break;
- }
- }
- }
- onClickRedSouce(){
- for (let i = 0; i < this.cookedSteakList.length; i++) {
- if(this.cookedSteakList[i] && this.cookedSteakList[i].getComponent(Beef).m_state == BeefState.Tomato){
- this.cookedSteakList[i].getComponent(Beef).setState(BeefState.RedSouce);
- break;
- }
- }
- }
- onClickDrinksMachine(){
- this.pDrinkBar.node.active = true;
- this.liuShui.active = true;
- App.SpinManager.PlaySpinAnimation(this.liuShui, "newAnimation", true, null);
- App.SpinManager.PlaySpinAnimation(this.drinkCup, "newAnimation", false, null);
-
- this.pDrinkBar.progress = 0;
- cc.tween(this.pDrinkBar).to(this.m_shuiLiuTime, {progress: 1}).call(()=>{
- this.pDrinkBar.node.active = false;
- this.liuShui.active = false;
- this.drinkCup.getComponent(sp.Skeleton).animation = null;
-
- for (let i = 0; i < this.cupNum; i++) {
- if(!this.drinkCupList[i])
- {
- let cup = cc.instantiate(this.fullCup);
- cup.setPosition(this.drinkCup.getPosition());
- this.node.addChild(cup);
- cup.zIndex = this.cupNum - i;
- this.drinkCupList[i] = cup;
- cup.on(cc.Node.EventType.TOUCH_END, this.onClickFullCup.bind(this, i), this);
-
- if(i == 0){
- cc.tween(cup).to(0.5, {position: this.cupPos[0]}).start();
- }
- else{
- cc.tween(cup).to(0.5, {position: this.cupPos[0]}).to(0.2, {position: this.cupPos[i]}).start();
- }
- }
- }
- }).start();
- }
-
- // 点击饮料
- onClickFullCup(index: number){
- // todo 移动到人
- if(App.DataManager.guideStep == 4){
- App.DataManager.guideStep++;
- App.LocalStorageUtil.setNumber(App.LocalStorageUtil.str_guideStep, App.DataManager.guideStep);
- guidePanel.getInstance().hideGuideStep();
- }
-
- // 移动到人之后,从数组里面删除
- let toPos = this.findFoodPos(FoodType.Drink);
- if(toPos){
- let pos = this.node.convertToNodeSpaceAR(toPos);
- cc.tween(this.drinkCupList[index]).to(0.3, {position: pos, scale: 0.5}).removeSelf().start();
- this.drinkCupList[index] = null;
- // this.m_machineState = DrinksMachineState.None;
-
- this.onClickDrinksMachine();
- }
- }
- onDisable() {
- this.btnShengNiuPai.node.off(cc.Node.EventType.TOUCH_END, this.onClickShengNiuPai.bind(this), this);
- this.btnYellowSouce.node.off(cc.Node.EventType.TOUCH_END, this.onClickYellowSouce.bind(this), this);
- this.btnCocumber.node.off(cc.Node.EventType.TOUCH_END, this.onClickCocumber.bind(this), this);
- this.btnTomato.node.off(cc.Node.EventType.TOUCH_END, this.onClickTomato.bind(this), this);
- this.btnRedSouce.node.off(cc.Node.EventType.TOUCH_END, this.onClickRedSouce.bind(this), this);
- }
- // 找到点这个食物剩余时间最少的人
- findFoodPos(foodt: FoodType): cc.Vec3 {
- let curPerson = null;
- let personIndex = -1;
- let lessLeftTime = 100;
- for (let i = 0; i < this.maxSitPersonNum; i++) {
- if(this.personList[i] && this.personList[i].getComponent(Person).m_state == PersonState.Waite){
- // 点餐种类
- let fTypelist = this.personList[i].getComponent(Person).foodTypeList;
- let time = this.personList[i].getComponent(Person).leftTime;
- for (let j = 0; j < fTypelist.length; j++) {
- if(foodt == fTypelist[j] && lessLeftTime > time){
- lessLeftTime = time;
- personIndex = i;
- curPerson = this.personList[i];
- }
- }
- }
- }
- if(curPerson){
- let worldPos = curPerson.getComponent(Person).getFoodWorldPos(foodt);
- if(curPerson.getComponent(Person).judgeFoodFull()){
-
- this.fullPersonNum++;
- let smallLevel = App.DataManager.PassProgress[App.DataManager.CurrentIntoLevel];
- if(this.fullPersonNum == App.DataManager.personCount[App.DataManager.CurrentIntoLevel - 1][smallLevel - 1]){
- // GameSuccess
- this.personList[personIndex] = null;
- let rand = Math.round(Math.random());
- cc.tween(curPerson).delay(0.6).call(()=>{
- curPerson.getComponent(Person).setState(PersonState.FullOut);
- if(rand == 1){
- curPerson.getChildByName("renwu").scaleX = -0.5;
- }
- }).to( this.personWalkTime, {position: this.bornPos[rand]}).call(()=>{
- curPerson.removeFromParent();
- }).start();
-
- gameScene.instance.GameSuccess();
- }
- else{
- let rand = Math.round(Math.random());
- this.personList[personIndex] = null
- cc.tween(curPerson).delay(0.6).call(()=>{
- curPerson.getComponent(Person).setState(PersonState.FullOut);
- if(rand == 1){
- curPerson.getChildByName("renwu").scaleX = -0.5;
- }
- }).to( this.personWalkTime, {position: this.bornPos[rand]}).call(()=>{
- curPerson.removeFromParent();
- }).start();
- }
- }
- return worldPos;
- }
- return null;
- }
- update (dt) {
- if (!gameScene.instance.GameStutas) return;
- this.passTime+=dt;
- let smallLevel = App.DataManager.PassProgress[App.DataManager.CurrentIntoLevel];
- if(this.passTime >= this.fixTime && this.createpPersonNum < App.DataManager.personCount[App.DataManager.CurrentIntoLevel - 1][smallLevel - 1]){
- this.passTime = 0;
- this.fixTime = 1;
- console.log("aaa-------randomIndex---------", smallLevel);
- for (let i = 0; i < this.maxSitPersonNum; i++) {
- if(!this.personList[i]){
- let randomIndex = Math.floor(Math.random() * this.renwuPerfabList.length);
- let person = cc.instantiate(this.renwuPerfabList[randomIndex])
- person.getComponent(Person).setState(PersonState.Comming);
- person.zIndex = -1;
- this.node.addChild(person);
- this.personList[i] = person;
- let rand = Math.round(Math.random());
- person.setPosition(this.bornPos[rand]);
- if(rand == 0){
- person.getChildByName("renwu").scaleX = -0.5;
- }
- App.SpinManager.PlaySpinAnimation(person.getChildByName("renwu"), "newAnimation", true);
- cc.tween(person).to(this.personWalkTime, {position: this.personPos[i]}).call(()=>{
- person.getChildByName("renwu").scaleX = 0.5;
- person.getComponent(Person).setState(PersonState.Waite);
- }).start();
- this.createpPersonNum++;
- let smallLevel = App.DataManager.PassProgress[App.DataManager.CurrentIntoLevel];
- gameScene.instance.updateLeftPeople(App.DataManager.personCount[App.DataManager.CurrentIntoLevel - 1][smallLevel - 1] - this.createpPersonNum);
- break;
- }
- }
- }
- }
- }
|