Skip to content

Custom Level with Sound #4541

@cerwym

Description

@cerwym

With given architecture this is what a LEVEL with custom scripting elements should look like, exact correctness may or may not be there, but this is considered POC / Pseudo

Scenario

Create a level with ambient cave sounds, triggered event sounds, and boss battle music.

File Structure

levels/
└── map00001/
    ├── map00001.txt          # DKScript
    ├── sounds/
    │   ├── cave_drip.wav     # Ambient
    │   ├── alarm_triggered.wav
    │   ├── boss_intro.wav
    │   └── boss_theme.ogg
    └── speech/
        └── level_intro.ogg   # Narration

DKScript Implementation

File: levels/map00001.txt

REM ============================================
REM Level: The Forgotten Caves
REM Custom sounds: ambient, events, boss music
REM ============================================

REM --- Load sounds at level start ---
LOAD_SOUND("CAVE_DRIP", "levels/map00001/sounds/cave_drip.wav", 1)
LOAD_SOUND("ALARM", "levels/map00001/sounds/alarm_triggered.wav", 1)
LOAD_SOUND("BOSS_INTRO", "levels/map00001/sounds/boss_intro.wav", 1)

REM --- Play intro narration ---
REM This plays when the level loads
PLAY_SPEECH_FILE("levels/map00001/speech/level_intro.ogg")

REM --- Ambient cave drip at water pool (Action Point 1) ---
REM Play looping ambient at position
IF_CONTROLS(PLAYER0, TOTAL_CREATURES >= 1)
    PLAY_SOUND_AT(20, 15, "CAVE_DRIP", 180)
ENDIF

REM --- Alarm when player enters treasure room (Action Point 2) ---
IF(PLAYER0, CREATURE_ARRIVED_AT_ACTION_POINT == 2)
    PLAY_SOUND("ALARM")
    ADD_CREATURE_TO_LEVEL(PLAYER_GOOD, KNIGHT, 3, 5, 5, 0)
    QUICK_INFORMATION(1, "Intruders have been spotted!")
ENDIF

REM --- Boss battle trigger (Action Point 3) ---
IF(PLAYER0, CREATURE_ARRIVED_AT_ACTION_POINT == 3)
    PLAY_SOUND("BOSS_INTRO")
    PLAY_MUSIC_FILE("levels/map00001/sounds/boss_theme.ogg")
    ADD_CREATURE_TO_LEVEL(PLAYER_GOOD, KNIGHT, 1, 10, 10, 0)
ENDIF

REM --- Victory: restore normal music ---
IF(PLAYER0, ALL_DUNGEONS_DESTROYED == 1)
    STOP_MUSIC
    PLAY_MUSIC(2)
ENDIF

Alternative: Lua Implementation

File: levels/map00001/level.lua

local boss_spawned = false
local alarm_triggered = false

function OnLevelStart()
    -- Preload critical sounds
    LoadCustomSound("cave_drip", "levels/map00001/sounds/cave_drip.wav", true)
    LoadCustomSound("alarm", "levels/map00001/sounds/alarm_triggered.wav", true)
    LoadCustomSound("boss_intro", "levels/map00001/sounds/boss_intro.wav", true)
    
    -- Play level intro
    PlaySpeechFile("levels/map00001/speech/level_intro.ogg")
    
    -- Start ambient sound at water pool
    PlaySoundAt(20 * 256, 15 * 256, 0, "cave_drip", 180)
end

function OnCreatureEntersActionPoint(creature, action_point)
    if action_point == 2 and not alarm_triggered then
        alarm_triggered = true
        PlaySound("alarm", 6, 256)
        ShowQuickInfo(1, "Intruders have been spotted!")
        SpawnCreature("KNIGHT", PLAYER_GOOD, 3, 5, 5)
    end
    
    if action_point == 3 and not boss_spawned then
        boss_spawned = true
        PlaySound("boss_intro", 6, 256)
        PlayMusicFile("levels/map00001/sounds/boss_theme.ogg")
        SpawnCreature("KNIGHT", PLAYER_GOOD, 1, 10, 10)
    end
end

function OnVictory()
    StopMusic()
    PlayMusic(2)
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions