From b1a784112a2f500f85dd2d7ea78de17d93b5c2bd Mon Sep 17 00:00:00 2001 From: Martijn de Boer Date: Sat, 15 Oct 2022 18:12:58 +0200 Subject: [PATCH] split variance --- planet/mapthread.lua | 2 ++ scene/game.lua | 18 +++++++----------- vendor/math.lua | 9 +++++++-- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/planet/mapthread.lua b/planet/mapthread.lua index f5fe9ac..195ffa1 100644 --- a/planet/mapthread.lua +++ b/planet/mapthread.lua @@ -1,3 +1,5 @@ +require "vendor/math" + channel = {} channel.tomap = love.thread.getChannel("tomap") channel.blocks = love.thread.getChannel("blocks") diff --git a/scene/game.lua b/scene/game.lua index 7db9075..66decf8 100644 --- a/scene/game.lua +++ b/scene/game.lua @@ -241,8 +241,8 @@ function GameScene:generateExplosion(px,py) GameScene.explosionObj = {angle=100, radius=100} GameScene.godsrayObj = {weight=0} - flux.to(GameScene.explosionObj, 0.5, {angle= GameScene:variance(100,90), radius=GameScene:variance(1600, 150)}):ease("quintout"):after( GameScene.explosionObj, 0.5, { angle= 100, radius= 100 }) - flux.to(GameScene.godsrayObj, 0.5, {weight=GameScene:variance(100,50)}):ease("quintout"):after( GameScene.godsrayObj, 0.5, { weight=1 }) + flux.to(GameScene.explosionObj, 0.5, {angle= math.variance(100,90), radius=math.variance(1600, 150)}):ease("quintout"):after( GameScene.explosionObj, 0.5, { angle= 100, radius= 100 }) + flux.to(GameScene.godsrayObj, 0.5, {weight=math.variance(100,50)}):ease("quintout"):after( GameScene.godsrayObj, 0.5, { weight=1 }) eSystem:emit(32) end @@ -257,16 +257,16 @@ function GameScene:generateExplosionSound(px,py) local sound = sfxr.newSound() sound:resetParameters() sound.waveform = sfxr.WAVEFORM.NOISE - sound.frequency.start = GameScene:variance(0.19907648104897,150) + sound.frequency.start = math.variance(0.19907648104897,150) sound.frequency.slide = -0.057634852747835 sound.repeatspeed = 0 sound.envelope.attack = 0 - sound.envelope.sustain = GameScene:variance(0.30484231377123, 150) - sound.envelope.punch = GameScene:variance(0.7393770288859, 150) + sound.envelope.sustain = math.variance(0.30484231377123, 150) + sound.envelope.punch = math.variance(0.7393770288859, 150) sound.envelope.decay = 0.43495283918775 - sound.phaser.offset = GameScene:variance(0.53418301267674, 150) + sound.phaser.offset = math.variance(0.53418301267674, 150) sound.phaser.sweep = -0.26648187020582 - sound.vibrato.depth = GameScene:variance(0.24860915303688, 150) + sound.vibrato.depth = math.variance(0.24860915303688, 150) sound.vibrato.speed = 0.44703997451237 sound.change.speed = 0.83105037145914 sound.change.amount = -0.66873272021076 @@ -277,7 +277,3 @@ function GameScene:generateExplosionSound(px,py) source:setPosition(px,py) source:play() end - -function GameScene:variance(seed, variance) - return seed * ((math.random( 100 - (variance/2), 100 + (variance/2)))/100) -end \ No newline at end of file diff --git a/vendor/math.lua b/vendor/math.lua index ec46adc..2176854 100644 --- a/vendor/math.lua +++ b/vendor/math.lua @@ -1,3 +1,8 @@ +-- randomize input +function math.variance(seed, variance) + return seed * ((math.random( 100 - (variance/2), 100 + (variance/2)))/100) +end + -- Averages an arbitrary number of angles (in radians). function math.averageAngles(...) local x,y = 0,0 @@ -23,10 +28,10 @@ function math.clamp(low, n, high) return math.min(math.max(low, n), high) end -- Linear interpolation between two numbers. -function lerp(a,b,t) return a+(b-a)*t end +function math.lerp(a,b,t) return a+(b-a)*t end -- Cosine interpolation between two numbers. -function cerp(a,b,t) local f=(1-math.cos(t*math.pi))*.5 return a*(1-f)+b*f end +function math.cerp(a,b,t) local f=(1-math.cos(t*math.pi))*.5 return a*(1-f)+b*f end -- Normalize two numbers.