forked from Juhee-Park/somsomcafe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview1.lua
More file actions
166 lines (125 loc) · 7.05 KB
/
Copy pathview1.lua
File metadata and controls
166 lines (125 loc) · 7.05 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
-----------------------------------------------------------------------------------------
--
-- view1.lua
--
-----------------------------------------------------------------------------------------
local composer = require( "composer" )
local scene = composer.newScene()
local success = 0 -- 게임 성공 횟수.
local fail = 0 -- 게임 실패 횟수.
local drinkImage = {"smoothie_img", "coffee_img"} -- 음료 이미지 주소. 나중에 모든 음료 이미지가 완성되면 수정 및 추가가 필요합니다. (랜덤 함수를 활용하기 위한 변수입니다.)
local customerImage = {"customer"} -- 손님 이미지 주소. 나중에 모든 손님 이미지가 완성되면 수정 및 추가가 필요합니다. (랜덤 함수를 활용하기 위한 변수입니다.)
function scene:create( event )
local sceneGroup = self.view
local background = display.newImageRect("img/main_background.png", display.contentWidth, display.contentHeight)
background.x, background.y = display.contentWidth/2, display.contentHeight/2
sceneGroup:insert(background)
local timeBar = nil -- 음료 위에 표시되는 시간 제한 바.
local count = 0 -- 시간 제한 카운트 변수.
local menu = nil -- 손님 위에 표시되는 음료 이미지.
local dialog = nil -- 손님이 음료를 요구하는 대화창 이미지.
local bar = nil -- 진행상황 이미지.
local customer = {} -- 손님 배열로 화면의 왼쪽부터 차례대로 1, 2, 3번.
local customerGroup = display.newGroup()
-- 시간 제한 카운터 함수.
local function counter( event )
count = count + 1
if timeBar == nil then -- 시간 소요를 나타내는 바 생성. 시간이 지날 수록 바의 크기가 줄어들게 설정했습니다. (10초)
timeBar = display.newRect(display.contentWidth*0.59, display.contentHeight*0.6, 353 - 35.3*count, 64)
else
timeBar.width, timeBar.x = 353 - 35.3 * count, display.contentWidth*0.59 - 17.16 * (count-1)
end
timeBar:setFillColor(1, 0, 0) -- 바의 색깔은 빨강색으로 했습니다.
if count == 10 then
count = 0 -- 10초가 지났기 때문에 count를 다시 0으로 바꿉니다. (0초부터 다시 세기)
fail = fail + 1 -- 타임 아웃으로 실패 횟수 늘립니다.
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 = display.contentWidth*0.59, display.contentHeight*0.675
bar = display.newImage("img/main/talk_space/time_limit.png")
bar.x, bar.y = display.contentWidth*0.59, display.contentHeight*0.6
sceneGroup:insert(dialog)
end
local pickMenu = math.random(2) -- 음료 이미지가 추가되면 수정이 필요합니다. (음료 이미지 개수로 수정해야 함.)
menu = display.newImage("img/main/drink/"..drinkImage[pickMenu]..".png")
-- 커피류 음료와 스무디류 음료의 이미지 크기가 다르기 때문에 위치를 따로 잡아줬습니다.
if pickMenu == 1 then -- 스무디류 음료를 뽑았을 때. 나중에 음료 이미지가 추가되면 수정이 필요합니다.(drinkImage array의 스무디류 인덱스 추가.)
menu.x, menu.y = display.contentWidth*0.57, display.contentHeight*0.664
else -- 커피류 음료를 뽑았을 때.
menu.x, menu.y = display.contentWidth*0.6, display.contentHeight*0.67
end
sceneGroup:insert(menu)
if success < 20 and fail < 5 then -- 성공 횟수와 실패 횟수가 각각 20번, 5번 미만이라면 타이머를 시작합니다. (게임 종료 시 타이머 기능을 사용하지 않기 위해서 조건문 사용.)
local timeAttack = timer.performWithDelay(1000, counter, 10) -- 10초 카운트 시작
end
end
-- 새 손님 넣기. 음료 제조에 성공했을 때에도 newCustomerEnter 함수를 호출해야 합니다.
function newCustomerEnter()
local pickCustomer
-- 3번 칸에 손님 이미지가 있다면 이를 먼저 지웁니다.
if customer[3] ~= null then
display.remove(customer[3])
end
-- 2번 칸에 있던 손님 이미지를 3번 칸 위치로 옮기고 customer[3]이 3번 칸으로 이동된 customer[2]를 가리키게 합니다.
customer[2].x, customer[2].y = display.contentWidth*0.78, display.contentHeight*0.83
customer[3] = customer[2]
-- 1번 칸에 있던 손님 이미지를 2번 칸 위치로 옮기고 customer[2]가 2번 칸으로 이동된 customer[1]을 가리키게 합니다.
customer[1].x, customer[1].y = display.contentWidth*0.52, display.contentHeight*0.83
customer[2] = customer[1]
pickCustomer = math.random(1) -- 나중에 손님 이미지가 추가되면 수정이 필요합니다. (손님 이미지 개수로 수정해야 함.)
customer[1] = display.newImage(customerGroup, "img/main/character/"..customerImage[pickCustomer]..".png")
customer[1].x, customer[1].y = display.contentWidth*0.26, display.contentHeight*0.83
sceneGroup:insert(customerGroup)
orderMenu()
end
-- 메뉴를 받기 전 손님 2명을 먼저 받아야 합니다. (손님 이미지 2개 화면에 추가)
orderMenu() -- 처음 손님이 들어온 후 메뉴를 주문합니다.
sceneGroup:insert(customerGroup)
end
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if phase == "will" then
-- Called when the scene is still off screen and is about to move on screen
elseif phase == "did" then
-- Called when the scene is now on screen
--
-- INSERT code here to make the scene come alive
-- e.g. start timers, begin animation, play audio, etc.
end
end
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if event.phase == "will" then
-- Called when the scene is on screen and is about to move off screen
--
-- INSERT code here to pause the scene
-- e.g. stop timers, stop animation, unload sounds, etc.)
elseif phase == "did" then
-- Called when the scene is now off screen
end
end
function scene:destroy( event )
local sceneGroup = self.view
-- Called prior to the removal of scene's "view" (sceneGroup)
--
-- INSERT code here to cleanup the scene
-- e.g. remove display objects, remove touch listeners, save state, etc.
end
---------------------------------------------------------------------------------
-- Listener setup
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
-----------------------------------------------------------------------------------------
return scene