forked from Juhee-Park/somsomcafe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.lua
More file actions
1238 lines (1144 loc) · 37.1 KB
/
Copy pathgame.lua
File metadata and controls
1238 lines (1144 loc) · 37.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-----------------------------------------------------------------------------------------
--
-- game.lua
--
-----------------------------------------------------------------------------------------
local composer = require( "composer" )
local scene = composer.newScene()
function scene:create( event )
local sceneGroup = self.view
------ 변수 설정 ------
-- 배경
local background = display.newImage("img/main_background.png",display.contentCenterX, display.contentCenterY)
--local background = display.newRect(display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight)
-- 선택 재료 칸
local box = display.newImage("img/main/what_I_choose.png", display.contentCenterX, display.contentCenterY)
box.x = box.x - 156
box.y = box.y - 986
-- 만들기 버튼
local makeButton = display.newImage("img/main/button/make.png", display.contentCenterX, display.contentCenterY)
makeButton.x = 1232
makeButton.y = 303
-- 쓰레기 통
local trash = display.newImage("img/main/trash.png", display.contentCenterX, display.contentCenterY)
trash.x, trash.y = 470, 924
-- 물 버튼
local waterB = display.newImage("img/recipe/water.png", display.contentCenterX, display.contentCenterY)
waterB.x = 257
waterB.y = 681
-- 우유 버튼
local milkB = display.newImage("img/recipe/milk.png",display.contentCenterX, display.contentCenterY)
milkB.x = 242
milkB.y = 944
-- 시럽 버튼
local syrupB = display.newImage("img/recipe/syrup.png", display.contentCenterX, display.contentCenterY)
syrupB.x = 242
syrupB.y = 1157
-- 에스프레소 버튼
local espressoB = display.newImage("img/recipe/espresso.png", display.contentCenterX, display.contentCenterY)
espressoB.x = 587
espressoB.y = 730
-- 얼음 버튼
local iceB = display.newImage("img/recipe/ice.png",display.contentCenterX, display.contentCenterY)
iceB.x = 861
iceB.y = 730
-- 초코 버튼
local chocoB = display.newImage("img/recipe/choco.png", display.contentCenterX, display.contentCenterY)
chocoB.x = 1200
chocoB.y = 720
-- 딸기 버튼
local strawberryB = display.newImage("img/recipe/strawberry.png", display.contentCenterX, display.contentCenterY)
strawberryB.x = 1200
strawberryB.y = 930
-- 바나나 버튼
local bananaB = display.newImage("img/recipe/banana.png", display.contentCenterX, display.contentCenterY)
bananaB.x = 1200
bananaB.y = 1141
-- 블루베리 버튼
local blueberryB = display.newImage("img/recipe/blueberry.png", display.contentCenterX, display.contentCenterY)
blueberryB.x = 1200
blueberryB.y = 1370
--물
local water = display.newImageRect("img/recipe/water.png", 176, 178)
water.y = 290
water:toBack()
--우유
local milk = display.newImage("img/recipe/milk.png", display.contentCenterX, display.contentCenterY)
milk.y = 290
milk:toBack()
--시럽
local syrup = display.newImage("img/recipe/syrup.png", display.contentCenterX, display.contentCenterY)
syrup.y = 290
syrup:toBack()
--에스프레소
local espresso = display.newImageRect("img/recipe/espresso.png", 210, 142)
espresso.y = 290
espresso:toBack()
--얼음
local ice = display.newImageRect("img/recipe/ice.png", 210, 159)
ice.y = 290
ice:toBack()
--초코
local choco = display.newImage("img/recipe/choco.png", display.contentCenterX, display.contentCenterY)
choco.y = 290
choco:toBack()
--딸기
local strawberry = display.newImage("img/recipe/strawberry.png", display.contentCenterX, display.contentCenterY)
strawberry.y = 290
strawberry:toBack()
--바나나 (임시 딸기 이미지 사용)
local banana = display.newImage("img/recipe/banana.png", display.contentCenterX, display.contentCenterY)
banana.y = 290
banana:toBack()
--블루베리
local blueberry = display.newImage("img/recipe/blueberry.png", display.contentCenterX, display.contentCenterY)
blueberry.y = 290
blueberry:toBack()
--아메리카노 (추후 알맞은 이미지로 대체)
local americano = display.newImage("img/recipe/americano.png", display.contentCenterX, display.contentCenterY)
americano.x = americano.x + 200
americano.alpha = 0
americano:toBack()
--바닐라라떼 (추후 알맞은 이미지로 대체)
local latte = display.newImage("img/recipe/vanilla_latte.png", display.contentCenterX, display.contentCenterY)
latte.x = latte.x + 200
latte.alpha = 0
latte:toBack()
--카페모카 (추후 알맞은 이미지로 대체)
local mocha = display.newImage("img/recipe/cafe_moca.png", display.contentCenterX, display.contentCenterY)
mocha.x = mocha.x + 200
mocha.alpha = 0
mocha:toBack()
--딸기 스무디 (추후 알맞은 이미지로 대체)
local smoothie_s = display.newImage("img/recipe/strawberry_smoothie.png", display.contentCenterX, display.contentCenterY)
smoothie_s.x = smoothie_s.x + 200
smoothie_s.alpha = 0
smoothie_s:toBack()
--바나나 스무디 (추후 알맞은 이미지로 대체)
local smoothie_ba = display.newImage("img/recipe/banana_smoothie.png", display.contentCenterX, display.contentCenterY)
smoothie_ba.x = smoothie_ba.x + 200
smoothie_ba:toBack()
smoothie_ba.alpha = 0
--블루베리 스무디 (추후 알맞은 이미지로 대체)
local smoothie_b = display.newImage("img/recipe/blueberry_smoothie.png", display.contentCenterX, display.contentCenterY)
smoothie_b.x = smoothie_b.x + 200
smoothie_b:toBack()
smoothie_b.alpha = 0
--딸기바나나 스무디 (추후 알맞은 이미지로 대체)
local smoothie_sb = display.newImage("img/main/drink/smoothie_img.png", display.contentCenterX, display.contentCenterY)
smoothie_sb.x = smoothie_sb.x + 200
smoothie_sb:toBack()
smoothie_sb.alpha = 0
-- 재료 팝업 위한 변수 (selected[i]로 담겨진거 구분)
------- 물: 1 / 우유: 2 / 시럽: 3
------- 에스프레소: 4 / 얼음: 5
------- 초코: 6 / 딸기: 7 / 바나나: 8 / 블루베리: 9
local selected = {}
for i = 1, 4 do
selected[i] = 0
end
--설정된 음료 구분
------- 아메리카노: 1 / 바닐라라떼: 2 / 카페모카: 3
------- 딸기스무디: 4 / 바나나스무디: 5 / 블루베리스무디: 6
------- 딸기바나나스무디: 7
local drinkMade = 0
--숫자 세는 변수
local cntNum
-- 문 오픈 여부
local doorOpen = 0
--팝업 닫았는지 여부
local popupClose = 0
--레시피 닫았는지 여부
local recipeClose = 1
--특별한 손님 등장
local specialCustomer = 0
--특별한 메뉴
local specialCnt = 0
------------------------------------
-- 문
local door = display.newImage("img/main/button/door.png")
door.x = 52
door.y = 2162
------------------------------------
-- 손님
local customer = {} -- 손님 배열로 화면의 왼쪽부터 차례대로 1, 2, 3번.
local customerGroup = display.newGroup()
local success = 0 -- 게임 성공 횟수.
local fail = 0 -- 게임 실패 횟수.
local pickMenu = 0
local drinkImage = {"americano", "vanilla_latte", "cafe_moca", "strawberry_smoothie", "banana_smoothie", "blueberry_smoothie", "smoothie_img"} -- 음료 이미지 주소. 나중에 모든 음료 이미지가 완성되면 수정 및 추가가 필요합니다. (랜덤 함수를 활용하기 위한 변수입니다.)
local customerImage = {"customer"} -- 손님 이미지 주소. 나중에 모든 손님 이미지가 완성되면 수정 및 추가가 필요합니다. (랜덤 함수를 활용하기 위한 변수입니다.)
local timeBar = nil -- 음료 위에 표시되는 시간 제한 바.
local count = 0 -- 시간 제한 카운트 변수.
local menu = nil -- 손님 위에 표시되는 음료 이미지.
local dialog = nil -- 손님이 음료를 요구하는 대화창 이미지.
local bar = nil -- 진행상황 이미지.
local timeAttack
------------------------------------
--제조성공시 점수
local score_s = display.newText("성공 : " .. 0 .. " / 20", 660, 660) --성공시 점수
score_s.x = 410
score_s.y = 520
score_s.size = 80
score_s:setFillColor(0)
--score_s.alpha = 0.5
--성공주문수
local order_success = display.newImage("img/main/success_count.png", display.contentCenterX, display.contentCenterY)
order_success.x = order_success.x - 322
order_success.y = order_success.y - 763
--제조 실패시 점수
local score_f = display.newText("실패 : " .. 0 .. " / 5", 660, 660) --성공시 점수
score_f.x = 1056
score_f.y = 520
score_f.size = 80
score_f:setFillColor(0)
--score_f.alpha = 0.5
--실패 주문 수
local order_fail = display.newImage("img/main/fail_count.png", display.contentCenterX, display.contentCenterY)
order_fail.x = order_fail.x + 327
order_fail.y = order_fail.y - 763
------------------------------------
local group = display.newGroup()
local tableGroup = display.newGroup()
-- 팝업 이미지1 삽입 (배경 설명)
local popup = display.newImage(group, "img/main_popup/popup.png")
popup.x, popup.y = 725, 1908
popup.alpha = 1
-- 팝업 이미지2 삽입 (게임방법 설명)
local popup2 = display.newImage(group, "img/main_popup/popup2.png")
popup2.x, popup2.y = 725, 1908
popup2.alpha = 0
-- 팝업 버튼 이미지 삽입
local popup_button = display.newImage(group, "img/main_popup/popup_button.png")
popup_button.x, popup_button.y = 1154, 2149
popup_button.alpha = 1
------------------------------------
-- 레시피 북 이미지 삽입
local recipe = display.newImage(group, 'img/main/button/recipe_book.png')
recipe.x, recipe.y = 253, 1444
recipe.alpha = 1
-- 레시피 팝업 이미지 삽입
tableGroup.alpha = 0
local recipe_popup
recipe_popup = display.newImage(tableGroup, "img/recipe_background.png", display.contentCenterX, display.contentCenterY)
recipe_popup.x, recipe_popup.y = display.contentWidth/2, display.contentHeight/2
--레시피 닫기 이미지 삽입
local recipe_x
recipe_x = display.newImage(tableGroup, "img/recipe/recipe_out.png")
recipe_x.x, recipe_x.y = 1282, 182
--재료 이미지 삽입
local in_table = {}
local line = {}
local drink = {}
local ingredient = {}
----효과음
--재료 클릭 시
local ingred_clink = audio.loadSound("sound/ingred_click.mp3")
-- 만들기 버튼
local make_button_click = audio.loadSound("sound/make_button_click_trash_can.mp3")
-- 음료 건넸을 때
local coffee_down = audio.loadSound("sound/new_somsom_in.mp3")
-- 레시피 북 열기
local recipebook_open = audio.loadSound("sound/recipebook_open.mp3")
-- 레시피 북 닫기
local recipebook_close = audio.loadSound("sound/recipebook_close.mp3")
-----------------------------------------------------------
sceneGroup:insert(water)
sceneGroup:insert(milk)
sceneGroup:insert(syrup)
sceneGroup:insert(espresso)
sceneGroup:insert(ice)
sceneGroup:insert(choco)
sceneGroup:insert(strawberry)
sceneGroup:insert(banana)
sceneGroup:insert(blueberry)
sceneGroup:insert(americano)
sceneGroup:insert(latte)
sceneGroup:insert(mocha)
sceneGroup:insert(smoothie_s)
sceneGroup:insert(smoothie_ba)
sceneGroup:insert(smoothie_b)
sceneGroup:insert(background)
sceneGroup:insert(box)
sceneGroup:insert(makeButton)
sceneGroup:insert(order_success)
sceneGroup:insert(order_fail)
sceneGroup:insert(waterB)
sceneGroup:insert(milkB)
sceneGroup:insert(syrupB)
sceneGroup:insert(espressoB)
sceneGroup:insert(iceB)
sceneGroup:insert(chocoB)
sceneGroup:insert(strawberryB)
sceneGroup:insert(bananaB)
sceneGroup:insert(blueberryB)
sceneGroup:insert(score_s)
sceneGroup:insert(score_f)
sceneGroup:insert(trash)
sceneGroup:insert(door)
sceneGroup:insert(group)
sceneGroup:insert(tableGroup)
-----------------------------------------------------------
----------------------팝업 닫기-----------------------------
-- 팝업 닫기 이벤트
local function popupOff( event )
if( event.phase == "began") then
audio.play(ingred_clink, {channel=1})
if(popup.alpha == 1) then
popup.alpha = 0
popup2.alpha = 1
else
popup2.alpha = 0
popup_button.alpha = 0
--팝업 내려야 문 열림 확인 변수
popupClose = 1
end
end
end
-- 팝업 닫기 이벤트 적용
popup_button:addEventListener("touch", popupOff)
----------------------레시피북 열기/닫기---------------------
--레시피 북 클릭 구현
function recipe:tap( event )
--레시피 엶
recipeClose = 0
audio.play(recipebook_open, {channel=1})
--타임바 안보이게
if timeBar ~= nil then
timeBar.alpha = 0
end
tableGroup.alpha = 1
-- 맨 앞에 출력 되게
tableGroup:toFront()
--레시피 닫기 이벤트
local function recipe_off( event )
if( event.phase == "began" ) then
audio.play(recipebook_close, {channel=1})
--레시피 닫음
recipeClose = 1
--타임바 보이게
if timeBar ~= nil then
timeBar.alpha = 1
end
--닫을 때 손님 다시 보이게
customerGroup.alpha = 1
--닫을 때 음료 다시 보이게
if menu ~= nil then
menu.alpha = 1
end
tableGroup.alpha = 0
end
end
-- 레시피 닫기 이벤트 적용
recipe_x:addEventListener("touch", recipe_off)
end
recipe:addEventListener("tap", recipe)
----------------------10초 타이머---------------------------
--- 시간 제한 카운터 함수.
local function counter( event )
count = count + 1
if timeBar == nil then -- 시간 소요를 나타내는 바 생성. 시간이 지날 수록 바의 크기가 줄어들게 설정했습니다. (10초)
timeBar = display.newRect(836, 1594, 353 - 35.3*count, 64)
else
timeBar.width, timeBar.x = 353 - 35.3 * count, 836 - 16 * (count-1)
end
timeBar:setFillColor(1, 0, 0, 1) -- 바의 색깔은 빨강색으로 했습니다.
print("count: " .. count)
if count == 10 then
count = 0 -- 10초가 지났기 때문에 count를 다시 0으로 바꿉니다. (0초부터 다시 세기)
fail = fail + 1 -- 타임 아웃으로 실패 횟수 늘립니다.
-- 5번 실패 시 이동
score_f.text = "실패 : " .. fail .. " / 5"
if (fail == 5) then
composer.gotoScene('fail')
end
print("성공 횟수: " .. success)
print("실패 횟수: " .. fail)
newCustomerEnter() -- 타임 아웃 후 새 손님을 받습니다.
end
end
----------------------주문 랜덤 생성 ------------------------
--- 메뉴를 랜덤으로 생성합니다. 현재는 이미지가 coffee와 smoothie 총 2개라 랜덤을 2로 돌렸습니다.
local function orderMenu()
if menu ~= nil then -- 음료 이미지가 이미 화면에 있다면 이를 먼저 지우고 시작합니다.
display.remove(menu)
end
if dialog == nil and bar == nil then -- 대화창 이미지와 시간제한 이미지가 화면에 생성되어 있지 않다면 먼저 생성하고 시작합니다.
dialog = display.newImage("img/main/talk_space/demand.png")
dialog.x, dialog.y = 835, 1729
bar = display.newImage("img/main/talk_space/time_limit.png")
bar.x, bar.y = 836, 1594
sceneGroup:insert(dialog)
sceneGroup:insert(bar)
end
-- 스페셜 메뉴 주문
if specialCnt == 1 then
pickMenu = 7
else
pickMenu = math.random(6) -- 음료 이미지가 추가되면 수정이 필요합니다. (음료 이미지 개수로 수정해야 함.)
end
print("고른 음료: " .. pickMenu)
-- 커피류 음료와 스무디류 음료의 이미지 크기가 다르기 때문에 위치를 따로 잡아줬습니다.
if pickMenu == 4 or pickMenu == 5 or pickMenu == 6 then -- 스무디류 음료를 뽑았을 때. 나중에 음료 이미지가 추가되면 수정이 필요합니다.(drinkImage array의 스무디류 인덱스 추가.)
menu = display.newImageRect("img/recipe/"..drinkImage[pickMenu]..".png", 100, 209)
menu.x, menu.y = 836, 1733
elseif pickMenu == 7 then --스페셜
menu = display.newImageRect("img/main/drink/"..drinkImage[pickMenu]..".png", 100, 209)
menu.x, menu.y = 836, 1733
else -- 커피류 음료를 뽑았을 때.
menu = display.newImageRect("img/recipe/"..drinkImage[pickMenu]..".png", 155, 192)
menu.x, menu.y = 836, 1733
end
sceneGroup:insert(menu)
--레시피 열었을 때 안보이게 생성
if recipeClose ~= 1 then
menu.alpha = 0
end
if success < 20 and fail < 5 then -- 성공 횟수와 실패 횟수가 각각 20번, 5번 미만이라면 타이머를 시작합니다. (게임 종료 시 타이머 기능을 사용하지 않기 위해서 조건문 사용.)
timeAttack = timer.performWithDelay(1000, counter, 10) -- 10초 카운트 시작
end
end
------------------손님 이동----------------------------------
-- 새 손님 넣기. 음료 제조에 성공했을 때에도 newCustomerEnter 함수를 호출해야 합니다.
function newCustomerEnter()
local pickCustomer
-- 효과음
audio.play(coffee_down, {channel=1})
-- 스페셜 손님 온지 얼마나 지났는지 확인용
if specialCustomer == 1 then
specialCnt = specialCnt + 1
end
-- 3번 칸에 손님 이미지가 있다면 이를 먼저 지웁니다.
if customer[3] ~= null then
display.remove(customer[3])
end
-- 2번 칸에 있던 손님 이미지를 3번 칸 위치로 옮기고 customer[3]이 3번 칸으로 이동된 customer[2]를 가리키게 합니다.
customer[2].x, customer[2].y = 1140, 2124
customer[3] = customer[2]
--3번째 손님 스르르 사라짐
transition.fadeOut(customer[3], {time = 1500})
-- 1번 칸에 있던 손님 이미지를 2번 칸 위치로 옮기고 customer[2]가 2번 칸으로 이동된 customer[1]을 가리키게 합니다.
customer[1].x, customer[1].y = 750, 2124
customer[2] = customer[1]
-- 특별한 손님 유뮤
if success == 20 and specialCustomer == 0 then
specialCustomer = 1
customer[1] = display.newImage(customerGroup, "img/main/character/"..customerImage[pickCustomer]..".png")
else
pickCustomer = math.random(1) -- 나중에 손님 이미지가 추가되면 수정이 필요합니다. (손님 이미지 개수로 수정해야 함.)
customer[1] = display.newImage(customerGroup, "img/main/character/"..customerImage[pickCustomer]..".png")
end
customer[1].x, customer[1].y = 355, 2124
sceneGroup:insert(customerGroup)
--레시피 열었을 때 안보이게 생성
if recipeClose ~= 1 then
customerGroup.alpha = 0
end
orderMenu()
end
------------------문 클릭시 손님 등장----------------------------------
--- 문을 클릭하면 손님 2명의 이미지가 화면에 나타남
local function tapEventListener( event )
--문 이미 열었는지 여부
if doorOpen == 0 then
if popupClose == 1 then
--효과음
audio.play(coffee_down, {channel=1})
doorOpen = 1
customer[1] = display.newImage(customerGroup, "img/main/character/customer.png", display.contentCenterX, display.contentCenterY)
customer[1].x , customer[1].y = 355, 2124
customer[2] = display.newImage(customerGroup, "img/main/character/customer.png", display.contentCenterX, display.contentCenterY)
customer[2].x , customer[2].y = 750, 2124
-- 메뉴를 받기 전 손님 2명을 먼저 받아야 합니다. (손님 이미지 2개 화면에 추가)
orderMenu() -- 처음 손님이 들어온 후 메뉴를 주문합니다.
sceneGroup:insert(customerGroup)
end
end
end
door:addEventListener("tap",tapEventListener)
--------------재료 선택 및 취소---------------------------
-- 물 선택 버튼
local function water_button(event)
if recipeClose == 1 then --레시피 안열려 있으면
audio.play(ingred_clink, {channel=1})
cntNum = 0
for i = 1, 4 do
if selected[i] == 1 then
cntNum = cntNum + 1
end
end
if cntNum == 0 then
for i = 1, 4 do
if selected[i] == 0 then
selected[i] = 1
water:toFront()
if i == 1 then
water.x = 220
elseif i == 2 then
water.x = 440
elseif i == 3 then
water.x = 660
elseif i == 4 then
water.x = 880
end
break
end
end
end
end
end
waterB:addEventListener("tap", water_button)
-- 물 선택 취소
local function water_delete(event)
if recipeClose == 1 then --레시피 안열려 있으면
audio.play(ingred_clink, {channel=1})
for i = 1, 5 do
if selected[i] == 1 then
selected[i] = 0
water:toBack()
break
end
end
end
end
water:addEventListener("tap", water_delete)
-- 우유 선택 버튼
local function milk_button(event)
if recipeClose == 1 then --레시피 안열려 있으면
audio.play(ingred_clink, {channel=1})
cntNum = 0
for i = 1, 4 do
if selected[i] == 2 then
cntNum = cntNum + 1
end
end
if cntNum == 0 then
for i = 1, 4 do
if selected[i] == 0 then
selected[i] = 2
milk:toFront()
if i == 1 then
milk.x = 220
elseif i == 2 then
milk.x = 440
elseif i == 3 then
milk.x = 660
elseif i == 4 then
milk.x = 880
end
break
end
end
end
end
end
milkB:addEventListener("tap", milk_button)
-- 우유 선택 취소
local function milk_delete(event)
if recipeClose == 1 then --레시피 안열려 있으면
audio.play(ingred_clink, {channel=1})
for i = 1, 5 do
if selected[i] == 2 then
selected[i] = 0
milk:toBack()
break
end
end
end
end
milk:addEventListener("tap", milk_delete)
-- 시럽 선택 버튼
local function syrup_button(event)
if recipeClose == 1 then --레시피 안열려 있으면
audio.play(ingred_clink, {channel=1})
cntNum = 0
for i = 1, 4 do
if selected[i] == 3 then
cntNum = cntNum + 1
end
end
if cntNum == 0 then
for i = 1, 4 do
if selected[i] == 0 then
selected[i] = 3
syrup:toFront()
if i == 1 then
syrup.x = 220
elseif i == 2 then
syrup.x = 440
elseif i == 3 then
syrup.x = 660
elseif i == 4 then
syrup.x = 880
end
break
end
end
end
end
end
syrupB:addEventListener("tap", syrup_button)
-- 시럽 선택 취소
local function syrup_delete(event)
if recipeClose == 1 then --레시피 안열려 있으면
audio.play(ingred_clink, {channel=1})
for i = 1, 5 do
if selected[i] == 3 then
selected[i] = 0
syrup:toBack()
break
end
end
end
end
syrup:addEventListener("tap", syrup_delete)
-- 에스프레소 선택 버튼
local function espresso_button(event)
if recipeClose == 1 then --레시피 안열려 있으면
audio.play(ingred_clink, {channel=1})
cntNum = 0
for i = 1, 4 do
if selected[i] == 4 then
cntNum = cntNum + 1
end
end
if cntNum == 0 then
for i = 1, 4 do
if selected[i] == 0 then
selected[i] = 4
espresso:toFront()
if i == 1 then
espresso.x = 220
elseif i == 2 then
espresso.x = 440
elseif i == 3 then
espresso.x = 660
elseif i == 4 then
espresso.x = 880
end
break
end
end
end
end
end
espressoB:addEventListener("tap", espresso_button)
-- 에스프레소 선택 취소
local function espresso_delete(event)
if recipeClose == 1 then --레시피 안열려 있으면
audio.play(ingred_clink, {channel=1})
for i = 1, 5 do
if selected[i] == 4 then
selected[i] = 0
espresso:toBack()
break
end
end
end
end
espresso:addEventListener("tap", espresso_delete)
-- 얼음 선택 버튼
local function ice_button(event)
if recipeClose == 1 then --레시피 안열려 있으면
audio.play(ingred_clink, {channel=1})
cntNum = 0
for i = 1, 4 do
if selected[i] == 5 then
cntNum = cntNum + 1
end
end
if cntNum == 0 then
for i = 1, 4 do
if selected[i] == 0 then
selected[i] = 5
ice:toFront()
if i == 1 then
ice.x = 220
elseif i == 2 then
ice.x = 440
elseif i == 3 then
ice.x = 660
elseif i == 4 then
ice.x = 880
end
break
end
end
end
end
end
iceB:addEventListener("tap", ice_button)
-- 얼음 선택 취소
local function ice_delete(event)
if recipeClose == 1 then --레시피 안열려 있으면
audio.play(ingred_clink, {channel=1})
for i = 1, 5 do
if selected[i] == 5 then
selected[i] = 0
ice:toBack()
break
end
end
end
end
ice:addEventListener("tap", ice_delete)
-- 초코 선택 버튼
local function choco_button(event)
if recipeClose == 1 then --레시피 안열려 있으면
audio.play(ingred_clink, {channel=1})
cntNum = 0
for i = 1, 4 do
if selected[i] == 6 then
cntNum = cntNum + 1
end
end
if cntNum == 0 then
for i = 1, 4 do
if selected[i] == 0 then
selected[i] = 6
choco:toFront()
if i == 1 then
choco.x = 220
elseif i == 2 then
choco.x = 440
elseif i == 3 then
choco.x = 660
elseif i == 4 then
choco.x = 880
end
break
end
end
end
end
end
chocoB:addEventListener("tap", choco_button)
-- 초코 선택 취소
local function choco_delete(event)
if recipeClose == 1 then --레시피 안열려 있으면
audio.play(ingred_clink, {channel=1})
for i = 1, 5 do
if selected[i] == 6 then
selected[i] = 0
choco:toBack()
break
end
end
end
end
choco:addEventListener("tap", choco_delete)
-- 딸기 선택 버튼
local function strawberry_button(event)
if recipeClose == 1 then --레시피 안열려 있으면
audio.play(ingred_clink, {channel=1})
cntNum = 0
for i = 1, 4 do
if selected[i] == 7 then
cntNum = cntNum + 1
end
end
if cntNum == 0 then
for i = 1, 4 do
if selected[i] == 0 then
selected[i] = 7
strawberry:toFront()
if i == 1 then
strawberry.x = 220
elseif i == 2 then
strawberry.x = 440
elseif i == 3 then
strawberry.x = 660
elseif i == 4 then
strawberry.x = 880
end
break
end
end
end
end
end
strawberryB:addEventListener("tap", strawberry_button)
-- 딸기 선택 취소
local function strawberry_delete(event)
if recipeClose == 1 then --레시피 안열려 있으면
audio.play(ingred_clink, {channel=1})
for i = 1, 5 do
if selected[i] == 7 then
selected[i] = 0
strawberry:toBack()
break
end
end
end
end
strawberry:addEventListener("tap", strawberry_delete)
-- 바나나 선택 버튼
local function banana_button(event)
if recipeClose == 1 then --레시피 안열려 있으면
audio.play(ingred_clink, {channel=1})
cntNum = 0
for i = 1, 4 do
if selected[i] == 8 then
cntNum = cntNum + 1
end
end
if cntNum == 0 then
for i = 1, 4 do
if selected[i] == 0 then
selected[i] = 8
banana:toFront()
if i == 1 then
banana.x = 220
elseif i == 2 then
banana.x = 440
elseif i == 3 then
banana.x = 660
elseif i == 4 then
banana.x = 880
end
break
end
end
end
end
end
bananaB:addEventListener("tap", banana_button)
-- 바나나 선택 취소
local function banana_delete(event)
if recipeClose == 1 then --레시피 안열려 있으면
audio.play(ingred_clink, {channel=1})
for i = 1, 5 do
if selected[i] == 8 then
selected[i] = 0
banana:toBack()
break
end
end
end
end
banana:addEventListener("tap", banana_delete)
-- 블루베리 선택 버튼
local function blueberry_button(event)
if recipeClose == 1 then --레시피 안열려 있으면
audio.play(ingred_clink, {channel=1})
cntNum = 0
for i = 1, 4 do
if selected[i] == 9 then
cntNum = cntNum + 1
end
end
if cntNum == 0 then
for i = 1, 4 do
if selected[i] == 0 then
selected[i] = 9
blueberry:toFront()
if i == 1 then
blueberry.x = 220
elseif i == 2 then
blueberry.x = 440
elseif i == 3 then
blueberry.x = 660
elseif i == 4 then
blueberry.x = 880
end
break
end
end
end
end
end
blueberryB:addEventListener("tap", blueberry_button)
-- 블루베리 선택 취소
local function blueberry_delete(event)
if recipeClose == 1 then --레시피 안열려 있으면
audio.play(ingred_clink, {channel=1})
for i = 1, 5 do
if selected[i] == 9 then
selected[i] = 0
blueberry:toBack()
break
end
end
end
end
blueberry:addEventListener("tap", blueberry_delete)
--------------------------------------------------------
--------------만들기 버튼--------------------------------
local function make_drink(event)
if doorOpen == 1 then --문을 클릭해서 열었다면
if recipeClose == 1 then --레시피 안열려 있으면
if drinkMade == 0 then --음료 없다면
audio.play(make_button_click, {channel=1})
local waterCnt = 0
local milkCnt = 0
local syrupCnt = 0
local espressoCnt = 0
local iceCnt = 0
local chocoCnt = 0
local strawberryCnt = 0
local bananaCnt = 0
local blueberryCnt = 0
--재료 선택 여부 확인
for i = 1, 4 do
if selected[i] == 1 then
waterCnt = waterCnt + 1
elseif selected[i] == 2 then
milkCnt = milkCnt + 1
elseif selected[i] == 3 then
syrupCnt = syrupCnt + 1
elseif selected[i] == 4 then
espressoCnt = espressoCnt + 1
elseif selected[i] == 5 then
iceCnt = iceCnt + 1
elseif selected[i] == 6 then
chocoCnt = chocoCnt + 1
elseif selected[i] == 7 then
strawberryCnt = strawberryCnt + 1
elseif selected[i] == 8 then
bananaCnt = bananaCnt + 1
elseif selected[i] == 9 then
blueberryCnt = blueberryCnt + 1
end
end
--아메리카노
if waterCnt ~= 0 and milkCnt == 0 and syrupCnt == 0 and espressoCnt ~= 0 and iceCnt == 0
and chocoCnt == 0 and strawberryCnt == 0 and bananaCnt == 0 and blueberryCnt == 0 then
drinkMade = 1
water:toBack()
espresso:toBack()
americano:toFront()
americano.alpha = 1
end
--바닐라라떼
if waterCnt == 0 and milkCnt ~= 0 and syrupCnt ~= 0 and espressoCnt ~= 0 and iceCnt == 0
and chocoCnt == 0 and strawberryCnt == 0 and bananaCnt == 0 and blueberryCnt == 0 then
drinkMade = 2
milk:toBack()
syrup:toBack()
espresso:toBack()
latte:toFront()
latte.alpha = 1
end
--카페모카
if waterCnt == 0 and milkCnt ~= 0 and syrupCnt == 0 and espressoCnt ~= 0 and iceCnt == 0
and chocoCnt ~= 0 and strawberryCnt == 0 and bananaCnt == 0 and blueberryCnt == 0 then
drinkMade = 3
milk:toBack()
espresso:toBack()
choco:toBack()
mocha:toFront()