-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
234 lines (196 loc) · 7.88 KB
/
Copy pathmain.lua
File metadata and controls
234 lines (196 loc) · 7.88 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
-- 가상 해상도 설정 (16:9 비율)
local VIRTUAL_WIDTH = 1280
local VIRTUAL_HEIGHT = 720
local scaleX, scaleY = 1, 1
-- 게임 상태 관리
local gameState = "MENU" -- "MENU", "GAME"
-- [수정] 여러 폰트를 저장할 2차원 테이블 구조
local gameFonts = {}
local GLYPH_BASE_SIZE = 32
-- [추정] 사용할 폰트 폴더 이름 목록 정의
local fontStyles = { "classic", "fire" }
-- 메뉴 버튼 설정
local menuButtons = {
{ text = "NEW GAME", action = function() gameState = "GAME" end, y = 320 },
{ text = "LOAD GAME", action = function() print("Load clicked") end, y = 420 },
{ text = "CONFIG", action = function() print("Config clicked") end, y = 520 }
}
-- 카드 데이터 설정
local cards = {}
local draggedCard = nil
local dragOffsetX, dragOffsetY = 0, 0
-- [수정] 텍스트 렌더링 함수에 fontName 인자 추가
local function drawText(text, x, y, scale, fontName)
scale = scale or 1.0
fontName = fontName or "classic" -- 폰트 지정을 안 하면 기본값으로 classic 사용
local currentX = x
-- 선택한 폰트 세트가 존재하는지 확인
local currentFont = gameFonts[fontName]
if not currentFont then return end
for i = 1, #text do
local char = text:sub(i, i)
if char == " " then
currentX = currentX + (GLYPH_BASE_SIZE * scale * 0.5)
else
local img = currentFont[char] -- 해당 폰트 세트에서 글자 이미지 탐색
if img then
love.graphics.draw(img, currentX, y, 0, scale, scale)
currentX = currentX + (GLYPH_BASE_SIZE * scale * 0.75)
end
end
end
end
-- 카드 생성 함수
local function createCard(name, cost, atk, hp, x, y)
return {
name = name,
cost = tostring(cost),
atk = tostring(atk),
hp = tostring(hp),
x = x,
y = y,
w = 160,
h = 220,
baseX = x,
baseY = y
}
end
function love.load()
-- [수정] 반복문을 통해 여러 폴더의 폰트를 동적으로 로드
for _, style in ipairs(fontStyles) do
gameFonts[style] = {} -- 각 폰트 이름을 키로 하는 테이블 생성
-- 소문자 로드
for i = string.byte('a'), string.byte('z') do
local char = string.char(i)
local path = "fonts/" .. style .. "/lower_" .. char .. ".png"
if love.filesystem.getInfo(path) then
gameFonts[style][char] = love.graphics.newImage(path)
end
end
-- 대문자 로드
for i = string.byte('A'), string.byte('Z') do
local char = string.char(i)
local path = "fonts/" .. style .. "/upper_" .. char .. ".png"
if love.filesystem.getInfo(path) then
gameFonts[style][char] = love.graphics.newImage(path)
end
end
-- 숫자 로드
for i = 0, 9 do
local char = tostring(i)
local path = "fonts/" .. style .. "/num_" .. char .. ".png"
if love.filesystem.getInfo(path) then
gameFonts[style][char] = love.graphics.newImage(path)
end
end
end
-- 화면 스케일 초기화
scaleX = love.graphics.getWidth() / VIRTUAL_WIDTH
scaleY = love.graphics.getHeight() / VIRTUAL_HEIGHT
-- 테스트용 카드 데이터 생성
table.insert(cards, createCard("Dragon", 5, 5, 5, 200, 420))
table.insert(cards, createCard("Soldier", 2, 2, 3, 400, 420))
table.insert(cards, createCard("Golem", 4, 3, 6, 600, 420))
end
function love.resize(w, h)
scaleX = w / VIRTUAL_WIDTH
scaleY = h / VIRTUAL_HEIGHT
end
local function getVirtualMousePos()
local mx, my = love.mouse.getPosition()
return mx / scaleX, my / scaleY
end
function love.update(dt)
if gameState == "GAME" and draggedCard then
local mx, my = getVirtualMousePos()
draggedCard.x = mx - dragOffsetX
draggedCard.y = my - dragOffsetY
end
end
function love.draw()
love.graphics.push()
love.graphics.scale(scaleX, scaleY)
if gameState == "MENU" then
-- [사용 예시] 타이틀은 화려한 'fire' 폰트 사용
drawText("MY CARD GAME", 380, 150, 1.8, "fire")
-- 메뉴 버튼들 렌더링
local mx, my = getVirtualMousePos()
for _, btn in ipairs(menuButtons) do
local bx, by, bw, bh = 440, btn.y, 400, 65
if mx >= bx and mx <= bx + bw and my >= by and my <= by + bh then
love.graphics.setColor(0.2, 0.2, 0.25, 0.6)
love.graphics.rectangle("fill", bx, by, bw, bh, 12)
love.graphics.setColor(1, 0.6, 0.2, 1)
else
love.graphics.setColor(0.05, 0.05, 0.05, 0.5)
love.graphics.rectangle("fill", bx, by, bw, bh, 12)
love.graphics.setColor(0.5, 0.5, 0.5, 1)
end
love.graphics.rectangle("line", bx, by, bw, bh, 12)
love.graphics.setColor(1, 1, 1, 1)
-- [사용 예시] 버튼 메뉴 글자는 깔끔한 'classic' 폰트 사용
local textOffset = 100
if btn.text == "CONFIG" then textOffset = 140 end
drawText(btn.text, bx + textOffset, by + 18, 1.0, "classic")
end
elseif gameState == "GAME" then
love.graphics.setColor(0.3, 0.3, 0.3, 1)
love.graphics.setLineWidth(2)
love.graphics.line(0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, VIRTUAL_HEIGHT / 2)
love.graphics.setColor(1, 1, 1, 1)
-- UI 텍스트는 'classic' 사용
drawText("BATTLE FIELD", 50, 40, 1.2, "classic")
drawText("YOUR HAND", 50, 370, 1.2, "classic")
-- 카드 렌더링
for _, card in ipairs(cards) do
love.graphics.setColor(0.1, 0.1, 0.12, 0.95)
love.graphics.rectangle("fill", card.x, card.y, card.w, card.h, 15)
love.graphics.setColor(0.6, 0.5, 0.35, 1)
love.graphics.rectangle("line", card.x, card.y, card.w, card.h, 15)
love.graphics.setColor(1, 1, 1, 1)
-- [사용 예시] 카드 이름은 'fire'로 강조하고 숫자는 'classic'으로 표현 가능
drawText(card.cost, card.x + 15, card.y + 15, 0.9, "classic")
drawText(card.name, card.x + 20, card.y + 95, 0.7, "fire")
drawText(card.atk, card.x + 15, card.y + 175, 0.9, "classic")
drawText(card.hp, card.x + card.w - 35, card.y + 175, 0.9, "classic")
end
end
love.graphics.pop()
end
function love.mousepressed(x, y, button, istouch, presses)
local mx, my = getVirtualMousePos()
if gameState == "MENU" then
for _, btn in ipairs(menuButtons) do
local bx, by, bw, bh = 440, btn.y, 400, 65
if mx >= bx and mx <= bx + bw and my >= by and my <= by + bh then
btn.action()
break
end
end
elseif gameState == "GAME" then
for i = #cards, 1, -1 do
local card = cards[i]
if mx >= card.x and mx <= card.x + card.w and my >= card.y and my <= card.y + card.h then
draggedCard = card
dragOffsetX = mx - card.x
dragOffsetY = my - card.y
table.remove(cards, i)
table.insert(cards, card)
break
end
end
end
end
function love.mousereleased(x, y, button, istouch, presses)
if gameState == "GAME" and draggedCard then
local mx, my = getVirtualMousePos()
if my < VIRTUAL_HEIGHT / 2 then
draggedCard.baseX = draggedCard.x
draggedCard.baseY = draggedCard.y
else
draggedCard.x = draggedCard.baseX
draggedCard.y = draggedCard.baseY
end
draggedCard = nil
end
end