diff --git a/DECISIONS.md b/DECISIONS.md index 5acb73e..75d97ac 100644 --- a/DECISIONS.md +++ b/DECISIONS.md @@ -36,6 +36,11 @@ - 가져오기: Luau Execution 작업 안에서 `AssetService:LoadAssetAsync`로 무료 공개 에셋을 불러오고(`AllowInsertFreeAssets` 필요), `.rbxm`으로 직렬화해 받아서 리포 `assets/`에 넣습니다. 리포가 계속 원본으로 남습니다. - 직접 만든 이미지·모델·소리: Open Cloud Assets API로 올립니다. 업로드마다 로블록스 검수가 붙습니다. - 주의: Place Publishing API는 Union(PartOperation)과 SurfaceAppearance를 올리지 못합니다. 그래서 Union 대신 Part 조합이나 MeshPart를 씁니다. +- 원칙(2026-10-12 사용자 요청): 마음에 드는 에셋이 없으면 직접 만듭니다. 분식집은 지금 모두 직접 만든 것입니다. + - 맵·가게·음식 모형: 코드로 Part를 조합(`src/server/PlotBuilder.luau`, `Food.luau`) + - 효과음 4개: `tools/sfx.py`로 합성해 오디오 에셋으로 업로드(`sfx/`, ID는 `src/shared/Sounds.luau`) + - 게임패스·상품 아이콘, 게임 아이콘, 썸네일: `tools/art.py`로 그림(`art/`) + - 로블록스 기본 제공만 그대로 씀: 손님 NPC의 기본 아바타 몸, 기본 걷기·앉기 애니메이션 - 원격 실행 한도: 작업 1회 5분, 키 주인 기준 분당 5회 생성. 근거: https://create.roblox.com/docs/cloud/reference/features/luau-execution , https://create.roblox.com/docs/cloud/guides/usage-place-publishing , https://create.roblox.com/docs/cloud/reference/features/assets , https://create.roblox.com/docs/reference/engine/classes/AssetService @@ -47,8 +52,9 @@ bunsik-tycoon/ src/server/ 서버 코드(돈, 세이브, 결제) src/client/ 화면 UI, 입력 src/shared/ 경제 수치표 같은 공용 데이터 - assets/ 맵·모델(.rbxm) - tools/ 시뮬레이터 등 개발 도구 + art/ 직접 그린 아이콘·썸네일(PNG) + sfx/ 직접 합성한 효과음(OGG) + tools/ 시뮬레이터, 업로드·원격 테스트, 그림·소리 생성 도구 ``` 근거: https://github.com/rojo-rbx/rojo/releases , https://create.roblox.com/docs/scripting/sync , https://create.roblox.com/docs/cloud/guides/usage-place-publishing , https://create.roblox.com/docs/cloud/reference/features/luau-execution diff --git a/SETUP.md b/SETUP.md index acf71a6..6b9615f 100644 --- a/SETUP.md +++ b/SETUP.md @@ -76,7 +76,8 @@ AI가 서버에서 게임을 올리고, 로블록스 서버에서 테스트를 - 키는 서버 `secrets.json`의 `roblox.opencloud/bunsik-tycoon`에 있습니다. 리포와 채팅에는 넣지 않습니다. - Bunsik Tycoon: universe `10770390863`, 루트 플레이스 `98118751156219`. - 서버에서 확인한 것: 게임 설정 읽기·수정, 게임패스·개발자 상품 목록, 에셋 읽기, Rojo 빌드 업로드(Saved 버전 4), 그 버전에서 Luau 원격 실행. 모두 성공했습니다. -- 2026-10-12 API로 만든 것: 게임패스 `Double Money (2배 수익)` 199 로벅스(ID 2026574937), 개발자 상품 `Money Boost (돈 부스트)` 25 로벅스(ID 3717970589), 서버 인원 6명, 게임 설명. +- 2026-10-12 API로 만든 것: 게임패스 `Double Money (2배 수익)` 199 로벅스(ID 2026574937), 개발자 상품 `Money Boost (돈 부스트)` 25 로벅스(ID 3717970589), 서버 인원 6명, 게임 설명, 효과음 오디오 4개(직접 합성). +- 게임 아이콘(`bunsik-tycoon/art/game_icon.png`)과 썸네일(`art/thumbnail_1.png`)은 그려 두었습니다. 올리는 공식 API가 없어서 출시 직전에 Creator Hub → Bunsik Tycoon → Places → Thumbnails 화면에서 직접 올립니다(그때 화면 순서를 안내). ## 6. 나중에 할 것 (지금은 안 해도 됨) diff --git a/bunsik-tycoon/art/game_icon.png b/bunsik-tycoon/art/game_icon.png new file mode 100644 index 0000000..ce0b8b2 Binary files /dev/null and b/bunsik-tycoon/art/game_icon.png differ diff --git a/bunsik-tycoon/art/thumbnail_1.png b/bunsik-tycoon/art/thumbnail_1.png new file mode 100644 index 0000000..75233ae Binary files /dev/null and b/bunsik-tycoon/art/thumbnail_1.png differ diff --git a/bunsik-tycoon/sfx/buy.ogg b/bunsik-tycoon/sfx/buy.ogg new file mode 100644 index 0000000..a7d4d3a Binary files /dev/null and b/bunsik-tycoon/sfx/buy.ogg differ diff --git a/bunsik-tycoon/sfx/coin.ogg b/bunsik-tycoon/sfx/coin.ogg new file mode 100644 index 0000000..d5a1372 Binary files /dev/null and b/bunsik-tycoon/sfx/coin.ogg differ diff --git a/bunsik-tycoon/sfx/levelup.ogg b/bunsik-tycoon/sfx/levelup.ogg new file mode 100644 index 0000000..7a4c401 Binary files /dev/null and b/bunsik-tycoon/sfx/levelup.ogg differ diff --git a/bunsik-tycoon/sfx/sizzle.ogg b/bunsik-tycoon/sfx/sizzle.ogg new file mode 100644 index 0000000..6da4f47 Binary files /dev/null and b/bunsik-tycoon/sfx/sizzle.ogg differ diff --git a/bunsik-tycoon/src/client/Main.client.luau b/bunsik-tycoon/src/client/Main.client.luau index d9266bf..0ff3a29 100644 --- a/bunsik-tycoon/src/client/Main.client.luau +++ b/bunsik-tycoon/src/client/Main.client.luau @@ -2,6 +2,8 @@ local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") +local SoundService = game:GetService("SoundService") + local Guide = require(script.Parent.Guide) local Hud = require(script.Parent.Hud) local Stove = require(script.Parent.Stove) @@ -27,9 +29,30 @@ local function rescale() end camera:GetPropertyChangedSignal("ViewportSize"):Connect(rescale) rescale() +-- 구매·확장 효과음은 내 화면에서만 크게(위치 없이) 들립니다. +local Sounds = require(ReplicatedStorage:WaitForChild("Shared"):WaitForChild("Sounds")) +local function uiSound(id: string, volume: number): Sound + local s = Instance.new("Sound") + s.SoundId = id + s.Volume = volume + s.Parent = SoundService + return s +end +local buySound = uiSound(Sounds.BUY, 0.7) +local levelSound = uiSound(Sounds.LEVELUP, 0.8) +local NOTIFY_SOUND: { [string]: Sound } = { + purchased = buySound, + boostGot = buySound, + expanded = levelSound, +} + notifyRemote.OnClientEvent:Connect(function(key, args) if typeof(key) == "string" then hud.notify(key, if typeof(args) == "table" then args else nil) + local s = NOTIFY_SOUND[key] + if s then + s:Play() + end end end) diff --git a/bunsik-tycoon/src/server/PlotController.luau b/bunsik-tycoon/src/server/PlotController.luau index 2c14590..563ff03 100644 --- a/bunsik-tycoon/src/server/PlotController.luau +++ b/bunsik-tycoon/src/server/PlotController.luau @@ -57,8 +57,6 @@ export type PlotController = typeof(setmetatable( handModels: { Model }, counterModels: { Model }, lastCook: number, - coin: Sound, - buySound: Sound, helper: Npc.Handle?, guide: BasePart, guideValue: ObjectValue, @@ -93,8 +91,6 @@ function PlotController.new(slot: Slot, owner: Instance, opts: Options): PlotCon handModels = {}, counterModels = {}, lastCook = 0, - coin = makeSound(slot.refs.stove, Sounds.COIN, 0.7), - buySound = makeSound(slot.refs.stove, Sounds.BUY, 0.8), helper = nil :: Npc.Handle?, guide = Instance.new("Part") :: BasePart, guideValue = Instance.new("ObjectValue"), @@ -384,8 +380,13 @@ function PlotController.serve(self: PlotController, id: number): number? label.Text = "😋" end floatText(view.npc.root, "+" .. Locale.number(earn)) + -- 동전 소리는 손님 자리에서 납니다(근처 사람도 들림). + local coin = makeSound(view.npc.root, Sounds.COIN, 0.7) + coin:Play() + task.delay(2, function() + coin:Destroy() + end) end - self.coin:Play() self.data.Served = (self.data.Served or 0) + 1 self.data.Earned = (self.data.Earned or 0) + earn if self.tut == 2 then @@ -500,7 +501,6 @@ function PlotController.buy(self: PlotController): (boolean, string?) hl:Destroy() end) end - self.buySound:Play() self:refreshHelper() self:refreshPrompt() if self.tut == 3 then @@ -533,8 +533,6 @@ function PlotController.destroy(self: PlotController) end self.slot.refs.stove:SetAttribute("OwnerId", nil) self.slot.refs.stove:SetAttribute("CookMenu", nil) - self.coin:Destroy() - self.buySound:Destroy() self.guideValue:Destroy() for _, m in self.handModels do m:Destroy() diff --git a/bunsik-tycoon/src/shared/Sounds.luau b/bunsik-tycoon/src/shared/Sounds.luau index 355df9f..de677eb 100644 --- a/bunsik-tycoon/src/shared/Sounds.luau +++ b/bunsik-tycoon/src/shared/Sounds.luau @@ -1,8 +1,9 @@ --!strict --- 효과음 ID. ProSoundEffects는 로블록스가 라이선스한 공개 효과음이라 누구나 쓸 수 있습니다. +-- 효과음 ID. 모두 tools/sfx.py로 직접 합성해 tkrmagid 계정으로 올린 것입니다(원본 파일: sfx/*.ogg). return { - SIZZLE = "rbxassetid://9114542867", -- Fry Or Sizzle 1 (SFX), ProSoundEffects - COIN = "rbxasset://sounds/electronicpingshort.wav", -- 로블록스 기본 내장음 - BUY = "rbxasset://sounds/electronicpingshort.wav", + SIZZLE = "rbxassetid://130884716661482", -- 조리 버튼을 누르는 동안(반복) + COIN = "rbxassetid://96594483709547", -- 서빙하고 돈 받을 때 + BUY = "rbxassetid://90178922626515", -- 업그레이드 구매, 돈 부스트 + LEVELUP = "rbxassetid://134931950463198", -- 실내 분식집 확장 } diff --git a/bunsik-tycoon/tests/cloud/integration.luau b/bunsik-tycoon/tests/cloud/integration.luau index 68dfcfb..1f8e4c3 100644 --- a/bunsik-tycoon/tests/cloud/integration.luau +++ b/bunsik-tycoon/tests/cloud/integration.luau @@ -310,6 +310,20 @@ eq(prompt.ActionText, "🍙 김밥 만들기", "버튼 글자") eq(prompt.HoldDuration, 1.5, "누르는 시간") prompt:Destroy() +section("효과음(직접 만든 오디오 에셋)") +local Sounds = require(ReplicatedStorage.Shared.Sounds) +for name, id in Sounds do + local num = tonumber(string.match(id, "%d+")) + local okInfo, info = pcall(function() + return game:GetService("MarketplaceService"):GetProductInfoAsync(num :: number, Enum.InfoType.Asset) + end) + check(okInfo, `효과음 {name} 정보 조회`) + if okInfo then + eq(info.AssetTypeId, 3, `효과음 {name}은 오디오`) + eq(info.Creator.CreatorTargetId, game.CreatorId, `효과음 {name}은 게임 주인 소유`) + end +end + section("Products") local Products = require(ReplicatedStorage.Shared.Products) local MarketplaceService = game:GetService("MarketplaceService") diff --git a/bunsik-tycoon/tools/art.py b/bunsik-tycoon/tools/art.py index e434cc9..1d30997 100644 --- a/bunsik-tycoon/tools/art.py +++ b/bunsik-tycoon/tools/art.py @@ -1,11 +1,13 @@ #!/usr/bin/env python3 -"""게임패스·개발자 상품 아이콘(512x512 PNG)을 그립니다. 외부 그림을 쓰지 않아 저작권 걱정이 없습니다. +"""게임패스·개발자 상품 아이콘(512x512), 게임 아이콘(512x512), 썸네일(1920x1080)을 그립니다. +외부 그림을 쓰지 않아 저작권 걱정이 없습니다. python3 tools/art.py # art/*.png 생성 """ import math import os +import numpy as np from PIL import Image, ImageDraw, ImageFilter, ImageFont OUT = os.path.join(os.path.dirname(__file__), "..", "art") @@ -76,8 +78,136 @@ def money_boost(): return img +def stall_scene(W, H, scale): + """포장마차와 떡볶이 판 그림(W x H, 크게 그린 뒤 줄여서 부드럽게).""" + k = scale + img = Image.new("RGBA", (W, H)) + d = ImageDraw.Draw(img) + # 저녁 하늘 + for y in range(H): + tt = y / H + c = (int(255 * (1 - tt) + 255 * tt), int(170 * (1 - tt) + 120 * tt), int(90 * (1 - tt) + 140 * tt), 255) + d.line([(0, y), (W, y)], fill=c) + rays = Image.new("RGBA", (W, H), (0, 0, 0, 0)) + rd = ImageDraw.Draw(rays) + cx, cy = W / 2, H * 0.55 + for i in range(24): + a0 = i * math.pi / 12 + a1 = a0 + math.pi / 24 + rd.polygon([(cx, cy), (cx + 4000 * math.cos(a0), cy + 4000 * math.sin(a0)), + (cx + 4000 * math.cos(a1), cy + 4000 * math.sin(a1))], fill=(255, 255, 255, 28)) + img.alpha_composite(rays) + d = ImageDraw.Draw(img) + # 바닥 + d.rectangle([0, H * 0.82, W, H], fill=(120, 95, 80)) + # 천막 기둥 + left, right = W / 2 - 330 * k, W / 2 + 330 * k + top = H * 0.30 + for x in (left + 30 * k, right - 30 * k): + d.rectangle([x - 9 * k, top, x + 9 * k, H * 0.84], fill=(180, 180, 190)) + # 수레(나무) + d.rounded_rectangle([left + 10 * k, H * 0.58, right - 10 * k, H * 0.84], radius=18 * k, fill=(165, 105, 60), + outline=(110, 65, 35), width=int(8 * k)) + for i in range(1, 6): + x = left + 10 * k + i * (right - left - 20 * k) / 6 + d.line([(x, H * 0.60), (x, H * 0.82)], fill=(140, 85, 45), width=int(5 * k)) + d.rounded_rectangle([left - 10 * k, H * 0.55, right + 10 * k, H * 0.60], radius=10 * k, fill=(215, 220, 225), + outline=(150, 150, 160), width=int(5 * k)) + # 줄무늬 천막과 물결 테두리 + roof = [(left - 60 * k, top + 110 * k), (W / 2, top - 40 * k), (right + 60 * k, top + 110 * k)] + d.polygon(roof, fill=(245, 110, 40), outline=(170, 60, 20)) + n = 8 + for i in range(n): + if i % 2 == 0: + x0 = left - 60 * k + i * (right - left + 120 * k) / n + x1 = x0 + (right - left + 120 * k) / n + d.polygon([(W / 2, top - 40 * k), (x0, top + 110 * k), (x1, top + 110 * k)], fill=(255, 235, 205)) + d.line(roof + [roof[0]], fill=(170, 60, 20), width=int(8 * k), joint="curve") + sw = (right - left + 120 * k) / n + for i in range(n): + x0 = left - 60 * k + i * sw + col = (245, 110, 40) if i % 2 == 0 else (255, 235, 205) + d.pieslice([x0, top + 70 * k, x0 + sw, top + 150 * k], 0, 180, fill=col, outline=(170, 60, 20), width=int(5 * k)) + # 전구 + for i in range(9): + x = left - 20 * k + i * (right - left + 40 * k) / 8 + d.ellipse([x - 14 * k, top + 150 * k, x + 14 * k, top + 178 * k], fill=(255, 230, 140), outline=(230, 170, 60), + width=int(3 * k)) + # 큰 떡볶이 판 + px, py, pr = W / 2, H * 0.60, 250 * k + d.ellipse([px - pr, py - pr * 0.42, px + pr, py + pr * 0.42], fill=(45, 45, 50)) + d.ellipse([px - pr * 0.9, py - pr * 0.36, px + pr * 0.9, py + pr * 0.36], fill=(215, 45, 25)) + r2 = random_state = np.random.default_rng(3) # noqa: F841 + for _ in range(26): + a = r2.uniform(0, 2 * math.pi) + rr = r2.uniform(0, 0.78) + x = px + math.cos(a) * pr * 0.85 * rr + y = py + math.sin(a) * pr * 0.32 * rr + ang = r2.uniform(-0.6, 0.6) + tl, tw = 70 * k, 22 * k + pts = [(-tl / 2, -tw / 2), (tl / 2, -tw / 2), (tl / 2, tw / 2), (-tl / 2, tw / 2)] + pts = [(x + px_ * math.cos(ang) - py_ * math.sin(ang), y + px_ * math.sin(ang) + py_ * math.cos(ang)) + for px_, py_ in pts] + d.polygon(pts, fill=(250, 120, 80), outline=(170, 40, 20)) + d.line([pts[0], pts[1]], fill=(255, 190, 160), width=int(4 * k)) + for _ in range(4): + x = px + r2.uniform(-0.6, 0.6) * pr + y = py + r2.uniform(-0.2, 0.15) * pr + d.polygon([(x - 40 * k, y + 15 * k), (x + 40 * k, y + 15 * k), (x, y - 40 * k)], fill=(240, 200, 130), + outline=(170, 120, 60)) + # 김 + steam = Image.new("RGBA", (W, H), (0, 0, 0, 0)) + sd = ImageDraw.Draw(steam) + for j, off in enumerate((-110, 0, 110)): + pts = [] + for i in range(30): + yy = py - pr * 0.4 - i * 9 * k + xx = px + off * k + math.sin(i / 4 + j) * 26 * k + pts.append((xx, yy)) + sd.line(pts, fill=(255, 255, 255, 170), width=int(22 * k), joint="curve") + steam = steam.filter(ImageFilter.GaussianBlur(8 * k)) + img.alpha_composite(steam) + return img + + +def title(img, cx, cy, size, sub=True): + d = ImageDraw.Draw(img) + outlined(d, (cx, cy), "분식 타이쿤", font(size), (255, 245, 120), (150, 40, 20), max(6, size // 10)) + if sub: + outlined(d, (cx, cy + size * 0.95), "BUNSIK TYCOON", font(int(size * 0.45)), (255, 255, 255), (150, 40, 20), + max(4, size // 18)) + + +def game_icon(): + big = stall_scene(1024, 1024, 1.25) + title(big, 512, 150, 150) + img = big.resize((S, S), Image.LANCZOS) + mask = Image.new("L", (S, S), 0) + ImageDraw.Draw(mask).rounded_rectangle([0, 0, S - 1, S - 1], radius=90, fill=255) + out = Image.new("RGBA", (S, S), (0, 0, 0, 0)) + out.paste(img, (0, 0), mask) + return out + + +def thumbnail(): + big = stall_scene(1920, 1080, 1.35) + d = ImageDraw.Draw(big) + title(big, 960, 120, 130) + # 메뉴 말풍선 + for (x, y, label) in [(250, 560, "떡볶이"), (1670, 560, "김밥"), (300, 860, "순대"), (1620, 860, "어묵")]: + d.rounded_rectangle([x - 150, y - 60, x + 150, y + 60], radius=40, fill=(255, 255, 255), outline=(255, 140, 60), + width=8) + d.text((x, y), label, font=font(64), fill=(200, 60, 30), anchor="mm") + outlined(d, (960, 1010), "손님을 받고 가게를 키우세요! Serve customers & grow your shop!", font(48), + (255, 255, 255), (90, 40, 20), 6) + return big.convert("RGB") + + def main(): os.makedirs(OUT, exist_ok=True) + game_icon().save(os.path.join(OUT, "game_icon.png")) + thumbnail().save(os.path.join(OUT, "thumbnail_1.png")) + print(os.path.join(OUT, "game_icon.png"), os.path.join(OUT, "thumbnail_1.png")) for name, fn in [("double_money", double_money), ("money_boost", money_boost)]: path = os.path.join(OUT, name + ".png") fn().save(path) diff --git a/bunsik-tycoon/tools/cloud.py b/bunsik-tycoon/tools/cloud.py index 25fc1a7..dc20743 100644 --- a/bunsik-tycoon/tools/cloud.py +++ b/bunsik-tycoon/tools/cloud.py @@ -5,6 +5,7 @@ python3 tools/cloud.py run script.luau [--version N] [--out file] # 기본: 가장 최근 저장 버전 python3 tools/cloud.py products # 게임패스·개발자 상품 만들기(이미 있으면 건너뜀) python3 tools/cloud.py place # 서버 인원 6명, 설명 설정 + python3 tools/cloud.py audio sfx/coin.ogg "이름" # 효과음 업로드, 에셋 ID 출력 API 키는 ~/.config/ejclaw/secrets.json 의 roblox.opencloud/bunsik-tycoon 에서 읽습니다. """ @@ -16,6 +17,7 @@ import urllib.error import urllib.request UNIVERSE = 10770390863 +CREATOR_USER = 4054147118 # tkrmagid PLACE = 98118751156219 SECRETS = os.path.expanduser("~/.config/ejclaw/secrets.json") @@ -143,7 +145,43 @@ def place(): return request("PATCH", url, body) +def upload_audio(path, name): + meta = { + "assetType": "Audio", + "displayName": name, + "description": "Bunsik Tycoon sound effect (synthesized, original).", + "creationContext": {"creator": {"userId": str(CREATOR_USER)}}, + } + boundary = "----bunsik" + str(int(time.time() * 1000)) + with open(path, "rb") as f: + data = f.read() + body = (f"--{boundary}\r\nContent-Disposition: form-data; name=\"request\"\r\n" + f"Content-Type: application/json\r\n\r\n{json.dumps(meta)}\r\n").encode() + body += (f"--{boundary}\r\nContent-Disposition: form-data; name=\"fileContent\"; " + f"filename=\"{os.path.basename(path)}\"\r\nContent-Type: audio/ogg\r\n\r\n").encode() + body += data + f"\r\n--{boundary}--\r\n".encode() + op = request("POST", "https://apis.roblox.com/assets/v1/assets", body, f"multipart/form-data; boundary={boundary}") + for _ in range(60): + if op.get("done"): + break + time.sleep(3) + op = request("GET", f"https://apis.roblox.com/assets/v1/{op['path']}") + if op.get("error"): + raise SystemExit(f"업로드 실패: {op['error']}") + return op.get("response", {}).get("assetId") + + +def asset_status(asset_id): + return request("GET", f"https://apis.roblox.com/assets/v1/assets/{asset_id}?readMask=moderationResult,state") + + def main(argv): + if argv[:1] == ["audio"]: + print(upload_audio(argv[1], argv[2])) + return 0 + if argv[:1] == ["asset"]: + print(json.dumps(asset_status(argv[1]), ensure_ascii=False)) + return 0 if argv[:1] == ["products"]: print(json.dumps(products())) return 0 diff --git a/bunsik-tycoon/tools/sfx.py b/bunsik-tycoon/tools/sfx.py new file mode 100644 index 0000000..592c43a --- /dev/null +++ b/bunsik-tycoon/tools/sfx.py @@ -0,0 +1,122 @@ +#!/usr/bin/env python3 +"""효과음을 직접 합성합니다(외부 음원 없음, 저작권 걱정 없음). sfx/*.ogg 로 저장합니다. + + python3 tools/sfx.py +""" +import os +import subprocess +import wave + +import numpy as np + +SR = 44100 +OUT = os.path.join(os.path.dirname(__file__), "..", "sfx") +rng = np.random.default_rng(7) + + +def t(sec): + return np.arange(int(SR * sec)) / SR + + +def env(n, attack=0.005, decay=0.3): + x = np.arange(n) / SR + a = np.clip(x / attack, 0, 1) + return a * np.exp(-x / decay) + + +def bell(freq, sec, decay): + x = t(sec) + # 맑은 종소리: 기본음 + 배음(조금 어긋난 비율) + s = (np.sin(2 * np.pi * freq * x) + 0.45 * np.sin(2 * np.pi * freq * 2.01 * x) + + 0.2 * np.sin(2 * np.pi * freq * 3.03 * x)) + return s * env(len(x), 0.002, decay) + + +def place(buf, sig, at): + i = int(at * SR) + end = min(len(buf), i + len(sig)) + buf[i:end] += sig[: end - i] + + +def coin(): + buf = np.zeros(int(SR * 0.6)) + place(buf, bell(1318.5, 0.6, 0.09), 0.0) # E6 + place(buf, bell(1975.5, 0.55, 0.18), 0.07) # B6 + return buf + + +def buy(): + # 도-미-솔-높은도 빠른 아르페지오 + 반짝임 + buf = np.zeros(int(SR * 1.0)) + for i, f in enumerate([523.25, 659.25, 783.99, 1046.5]): + place(buf, bell(f, 0.7, 0.22), i * 0.075) + sparkle = rng.standard_normal(int(SR * 0.4)) + sparkle = np.convolve(sparkle, np.ones(3) / 3, "same") * env(len(sparkle), 0.01, 0.12) * 0.08 + place(buf, sparkle * np.sin(2 * np.pi * 6000 * t(0.4)), 0.3) + return buf + + +def levelup(): + # 확장 축하: 두 박자 팡파레(사각파 느낌을 배음으로) + buf = np.zeros(int(SR * 1.6)) + notes = [(523.25, 0.0, 0.15), (659.25, 0.15, 0.15), (783.99, 0.3, 0.15), (1046.5, 0.45, 0.6)] + for f, at, d in notes: + x = t(d + 0.4) + s = sum(np.sin(2 * np.pi * f * k * x) / k for k in (1, 3, 5)) * 0.6 + s += 0.5 * np.sin(2 * np.pi * f * 2 * x) + e = env(len(x), 0.01, 0.35 if d > 0.3 else 0.12) + place(buf, s * e, at) + return buf + + +def sizzle(sec=3.0): + n = int(SR * sec) + noise = rng.standard_normal(n) + # 고역 위주(지글지글): 1차 고역 통과 + hp = np.empty(n) + a = 0.92 + prev_x = prev_y = 0.0 + for i in range(n): + y = a * (prev_y + noise[i] - prev_x) + hp[i] = y + prev_x, prev_y = noise[i], y + # 천천히 출렁이는 세기 + x = t(sec) + mod = 0.55 + 0.25 * np.sin(2 * np.pi * 0.7 * x) + 0.2 * np.sin(2 * np.pi * 1.9 * x + 1) + s = hp * mod * 0.25 + # 기름 튀는 소리(짧은 딱딱) + for at in rng.uniform(0, sec, 70): + click = rng.standard_normal(int(SR * 0.012)) * env(int(SR * 0.012), 0.0005, 0.003) + place(s, click * rng.uniform(0.3, 0.9), at) + # 이음매 없이 반복되게 앞뒤를 겹칩니다. + fade = int(SR * 0.3) + w = np.linspace(0, 1, fade) + s[:fade] = s[:fade] * w + s[-fade:] * (1 - w) + return s[:-fade] + + +def save(name, sig): + sig = sig / max(1e-9, np.max(np.abs(sig))) * 0.85 + pcm = (sig * 32767).astype(np.int16) + wav = os.path.join(OUT, name + ".wav") + with wave.open(wav, "wb") as f: + f.setnchannels(1) + f.setsampwidth(2) + f.setframerate(SR) + f.writeframes(pcm.tobytes()) + ogg = os.path.join(OUT, name + ".ogg") + subprocess.run(["ffmpeg", "-y", "-loglevel", "error", "-i", wav, "-c:a", "libvorbis", "-q:a", "5", ogg], check=True) + os.remove(wav) + print(ogg) + + +def main(): + os.makedirs(OUT, exist_ok=True) + save("coin", coin()) + save("buy", buy()) + save("levelup", levelup()) + save("sizzle", sizzle()) + + +if __name__ == "__main__": + main()