From 18e654b3e9d17c27a4e76b11f1cc595b710df79c Mon Sep 17 00:00:00 2001 From: Nicholas Hayashi Date: Wed, 14 Jul 2021 22:55:23 -0400 Subject: [PATCH] tracks, balancing --- main.lua | 55 +++++++++++++++++++++++++++++++++------------- sound.lua | 15 +++++++++++-- src/mob.lua | 2 +- src/projectile.lua | 2 +- 4 files changed, 55 insertions(+), 19 deletions(-) diff --git a/main.lua b/main.lua index a3cf5da..f34a594 100644 --- a/main.lua +++ b/main.lua @@ -92,6 +92,44 @@ require "src/mob" require "src/projectile" require "src/tower" + +local sound_toggle_node_tag = "sound-on-off-icon" +local function make_sound_toggle_node(on) + local sprite + if on then + sprite = pack_texture_into_sprite(TEXTURES.SOUND_ON1, 40, 30) + else + sprite = pack_texture_into_sprite(TEXTURES.SOUND_OFF, 40, 30) + end + + return (am.translate(win.right - 30, win.top - 60) ^ sprite) + :tag(sound_toggle_node_tag) + :action(function() + + end) +end + +local cached_music_volume = 0.2 +local cached_sfx_volume = 0.1 +local function toggle_mute() + settings.sound_on = not settings.sound_on + + if settings.sound_on then + settings.music_volume = cached_music_volume + settings.sfx_volume = cached_sfx_volume + else + cached_music_volume = settings.music_volume + cached_sfx_volume = settings.sfx_volume + + settings.music_volume = 0 + settings.sfx_volume = 0 + end + + update_music_volume(settings.music_volume) + + win.scene:replace(sound_toggle_node_tag, make_sound_toggle_node(settings.sound_on)) +end + -- text popup in the middle of the screen that dissapates, call from anywhere function alert(message, color) win.scene:append( @@ -117,6 +155,8 @@ function main_action(self) end elseif win:key_pressed("f4") then win:close() + elseif win:key_pressed("m") then + toggle_mute() end if self"hex_backdrop" then self"hex_backdrop""rotate".angle = math.wrapf(self"hex_backdrop""rotate".angle - 0.005 * am.delta_time, math.pi*2) @@ -236,21 +276,6 @@ function make_main_scene_toolbelt() return am.translate(pixel_offset) ^ group end -function make_sound_toggle_node(on) - local sprite - if on then - sprite = pack_texture_into_sprite(TEXTURES.SOUND_ON1, 40, 30) - else - sprite = pack_texture_into_sprite(TEXTURES.SOUND_OFF, 40, 30) - end - - return (am.translate(win.right - 30, win.top - 60) ^ sprite) -end - -function toggle_mute() - settings.sound_on = not settings.sound_on - win.scene:replace("sound-on-off-icon", make_sound_toggle_node(settings.sound_on)) -end function main_scene(do_backdrop, do_logo) local group = am.group() diff --git a/sound.lua b/sound.lua index bede6d6..dea8a13 100644 --- a/sound.lua +++ b/sound.lua @@ -24,6 +24,16 @@ SOUNDS = { MAIN_THEME = am.track(am.load_audio("res/maintheme.ogg"), true, 1, settings.music_volume) } +-- doesn't get unset when a track is 'done' playing automatically +CURRENT_TRACK = nil + +function update_sfx_volume() end +function update_music_volume(volume) + if CURRENT_TRACK then + CURRENT_TRACK.volume = math.clamp(volume, 0, 1) + end +end + -- play sound effect with variable pitch function vplay_sfx(sound, pitch_range) local pitch = (math.random() + 0.5)/(pitch_range and 1/pitch_range or 2) @@ -34,7 +44,8 @@ function play_sfx(sound) win.scene:action(am.play(sound, false, 1, settings.sfx_volume)) end -function play_track(track) - win.scene:action(am.play(track)) +function play_track(track, loop) + CURRENT_TRACK = track + win.scene:action(am.play(track, loop or true)) end diff --git a/src/mob.lua b/src/mob.lua index 46fdc18..b60b4b6 100644 --- a/src/mob.lua +++ b/src/mob.lua @@ -36,7 +36,7 @@ local function grow_mob_speed(mob_type, spec_speed, time) return spec_speed + math.log(state.current_wave + 1) end local function grow_mob_bounty(mob_type, spec_bounty, time) - return spec_bounty + math.pow(state.current_wave - 1, 2) + return spec_bounty + (state.current_wave - 1) * 2 end function mobs_on_hex(hex) diff --git a/src/projectile.lua b/src/projectile.lua index 7472c4d..8868a5a 100644 --- a/src/projectile.lua +++ b/src/projectile.lua @@ -18,7 +18,7 @@ local PROJECTILE_SPECS = { }, [PROJECTILE_TYPE.BULLET] = { velocity = 25, - damage = 5, + damage = 4, hitbox_radius = 10 } }