summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.lua9
-rw-r--r--render/draws/ui.lua87
2 files changed, 53 insertions, 43 deletions
diff --git a/config.lua b/config.lua
index e30b0d0..6f732dc 100644
--- a/config.lua
+++ b/config.lua
@@ -58,6 +58,15 @@ config = {
},
},
+ ui = {
+ minimap = {
+ mapSize = 100,
+ roomSize = 25,
+ padding = 10,
+ lineWidth = 2,
+ }
+ },
+
defaultMusic = "briskFight"
}
diff --git a/render/draws/ui.lua b/render/draws/ui.lua
index 03237b1..d44c469 100644
--- a/render/draws/ui.lua
+++ b/render/draws/ui.lua
@@ -7,20 +7,24 @@ function ui.ammoBar()
local y = love.graphics.getHeight() - height
local x = 10
local gap = 20
+ local screenWidth = love.graphics.getWidth()
+ -- avoid overlap with room name
+ local roomNameWidth = love.graphics.getFont():getWidth(G.currentRoom.name) + 20
+ local maxPerRow = math.floor((screenWidth - roomNameWidth - 20) / gap)
local hearts = G.player.hearts
for i, v in pairs(hearts) do
- local position = { x = x+gap*(i-1), y = y }
+ local position = { x = x + gap * ((i - 1) % maxPerRow), y = y - math.floor((i - 1) / maxPerRow) * (height + 5) }
local heartR = config.heartSize
-- if a heart is charging
-- draw circle behind it to indicate the progress
local chargingStarted = G.player.chargingStarted
local chargingTime = G.time - (chargingStarted or 0)
- if chargingStarted and i==G.player.nextBullet then
+ if chargingStarted and i == G.player.nextBullet then
local arc = math.pi * 2 * (chargingTime or 0)
- love.graphics.setColor(1,0,0,0.6)
- love.graphics.arc("fill", position.x+heartR/2, position.y+heartR/2,
+ love.graphics.setColor(1, 0, 0, 0.6)
+ love.graphics.arc("fill", position.x + heartR / 2, position.y + heartR / 2,
config.heartSize, 0, arc)
utils.resetGraphics()
end
@@ -42,10 +46,13 @@ end
function ui.roomName()
local text = G.currentRoom.name
local screenWidth = love.graphics.getWidth()
+ local screenHeight = love.graphics.getHeight()
local font = love.graphics.getFont()
local textWidth = font:getWidth(text)
+ local textHeight = font:getHeight()
- love.graphics.print(text, screenWidth - textWidth, 0)
+ -- put room name in bottom right corner
+ love.graphics.print(text, screenWidth - textWidth - 10, screenHeight - textHeight - 10)
end
function ui.speakerText()
@@ -53,69 +60,64 @@ function ui.speakerText()
end
function ui.minimap()
- local mapSize = 100 -- 缩小小地图的大小
- local roomSize = 25 -- 每个房间的大小
- local padding = 10 -- 边距
- local lineWidth = 2 -- 连接线宽度
-
- -- 计算小地图位置(右上角)
- local mapX = love.graphics.getWidth() - mapSize - padding
- local mapY = padding
+ -- minimap
+ local mapX = love.graphics.getWidth() - config.ui.minimap.mapSize - config.ui.minimap.padding
+ local mapY = config.ui.minimap.padding
- -- 绘制半透明背景
+ -- draw semi-transparent background
love.graphics.setColor(0, 0, 0, 0.5)
- love.graphics.rectangle("fill", mapX, mapY, mapSize, mapSize)
+ love.graphics.rectangle("fill", mapX, mapY, config.ui.minimap.mapSize, config.ui.minimap.mapSize)
- -- 获取当前房间位置作为中心点
- local centerX = mapX + mapSize/2
- local centerY = mapY + mapSize/2
+ -- get current room position as center
+ local centerX = mapX + config.ui.minimap.mapSize/2
+ local centerY = mapY + config.ui.minimap.mapSize/2
- -- 用于存储要绘制的房间及其位置
+ -- store rooms to draw
local roomsToDraw = {}
- -- 递归函数:收集已探索的房间及其直接连接的房间
+ -- recursive function: collect explored rooms and their directly connected rooms
local function collectRooms(room, x, y, visited)
if visited[room] then return end
visited[room] = true
- -- 添加当前房间到绘制列表
+ -- add current room to draw list
table.insert(roomsToDraw, {
room = room,
x = x,
y = y
})
- -- 遍历所有门,收集相连的房间
+ -- iterate all doors, collect connected rooms
for _, door in pairs(room.doors) do
local nextX, nextY = x, y
if door.location == Direction.LEFT then
- nextX = x - roomSize
+ nextX = x - config.ui.minimap.roomSize
elseif door.location == Direction.RIGHT then
- nextX = x + roomSize
+ nextX = x + config.ui.minimap.roomSize
elseif door.location == Direction.TOP then
- nextY = y - roomSize
+ nextY = y - config.ui.minimap.roomSize
elseif door.location == Direction.BOTTOM then
- nextY = y + roomSize
+ nextY = y + config.ui.minimap.roomSize
end
- -- 如果房间已探索或是直接连接的房间,继续收集
+ -- if room is explored or directly connected, continue collecting
if door.to and (door.to.isExplored or room.isExplored) then
collectRooms(door.to, nextX, nextY, visited)
end
end
end
- -- 从当前房间开始,收集所有已探索的房间及其直接连接的房间
+ -- collect all explored rooms and their directly connected rooms
collectRooms(G.currentRoom, centerX, centerY, {})
- -- 先绘制连接线
+ -- draw connecting lines first
love.graphics.setColor(0.5, 0.5, 0.5, 0.7)
- love.graphics.setLineWidth(lineWidth)
+ love.graphics.setLineWidth(config.ui.minimap.lineWidth)
for _, roomData in ipairs(roomsToDraw) do
local room = roomData.room
for _, door in pairs(room.doors) do
if door.to and (door.to.isExplored or room.isExplored) then
- -- 查找目标房间的位置
+ -- find target room position
for _, targetRoomData in ipairs(roomsToDraw) do
if targetRoomData.room == door.to then
love.graphics.line(roomData.x, roomData.y, targetRoomData.x, targetRoomData.y)
@@ -126,38 +128,37 @@ function ui.minimap()
end
end
- -- 然后绘制房间
+ -- draw rooms
for _, roomData in ipairs(roomsToDraw) do
local room = roomData.room
local x = roomData.x
local y = roomData.y
- -- 根据状态设置颜色
+ -- set color based on state
if room == G.currentRoom then
if room.isCleared then
- love.graphics.setColor(0, 1, 0, 1) -- 当前已清理房间:绿色
+ love.graphics.setColor(0, 1, 0, 1) -- current cleared room: green
else
- love.graphics.setColor(1, 0, 0, 1) -- 当前未清理房间:红色
+ love.graphics.setColor(1, 0, 0, 1) -- current unexplored room: red
end
else
if room.isCleared then
- love.graphics.setColor(0, 0.7, 0, 0.7) -- 已清理房间:暗绿色
+ love.graphics.setColor(0, 0.7, 0, 0.7) -- cleared room: dark green
else
- love.graphics.setColor(0.7, 0, 0, 0.7) -- 未清理房间:暗红色
+ love.graphics.setColor(0.7, 0, 0, 0.7) -- unexplored room: dark red
end
end
- -- 绘制房间
- love.graphics.rectangle("fill", x - roomSize/4, y - roomSize/4, roomSize/2, roomSize/2)
+ -- draw room
+ love.graphics.rectangle("fill", x - config.ui.minimap.roomSize/4, y - config.ui.minimap.roomSize/4, config.ui.minimap.roomSize/2, config.ui.minimap.roomSize/2)
- -- 如果是初始房间,添加特殊标记
+ -- if initial room, add special mark
if room.type == roomType.INITIAL then
love.graphics.setColor(1, 1, 1, 0.8)
- love.graphics.rectangle("line", x - roomSize/4, y - roomSize/4, roomSize/2, roomSize/2)
+ love.graphics.rectangle("line", x - config.ui.minimap.roomSize/4, y - config.ui.minimap.roomSize/4, config.ui.minimap.roomSize/2, config.ui.minimap.roomSize/2)
end
end
- -- 重置颜色
utils.resetGraphics()
end
@@ -166,7 +167,7 @@ function ui.draw()
ui.roomClearedCounter()
ui.roomName()
ui.speakerText()
- ui.minimap() -- 添加小地图绘制
+ ui.minimap()
end
return ui