split variance

This commit is contained in:
Martijn de Boer 2022-10-15 18:12:58 +02:00
parent 7f975fddc8
commit b1a784112a
No known key found for this signature in database
GPG key ID: 9D2E42402DD372D1
3 changed files with 16 additions and 13 deletions

View file

@ -1,3 +1,5 @@
require "vendor/math"
channel = {} channel = {}
channel.tomap = love.thread.getChannel("tomap") channel.tomap = love.thread.getChannel("tomap")
channel.blocks = love.thread.getChannel("blocks") channel.blocks = love.thread.getChannel("blocks")

View file

@ -241,8 +241,8 @@ function GameScene:generateExplosion(px,py)
GameScene.explosionObj = {angle=100, radius=100} GameScene.explosionObj = {angle=100, radius=100}
GameScene.godsrayObj = {weight=0} 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.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=GameScene:variance(100,50)}):ease("quintout"):after( GameScene.godsrayObj, 0.5, { weight=1 }) flux.to(GameScene.godsrayObj, 0.5, {weight=math.variance(100,50)}):ease("quintout"):after( GameScene.godsrayObj, 0.5, { weight=1 })
eSystem:emit(32) eSystem:emit(32)
end end
@ -257,16 +257,16 @@ function GameScene:generateExplosionSound(px,py)
local sound = sfxr.newSound() local sound = sfxr.newSound()
sound:resetParameters() sound:resetParameters()
sound.waveform = sfxr.WAVEFORM.NOISE 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.frequency.slide = -0.057634852747835
sound.repeatspeed = 0 sound.repeatspeed = 0
sound.envelope.attack = 0 sound.envelope.attack = 0
sound.envelope.sustain = GameScene:variance(0.30484231377123, 150) sound.envelope.sustain = math.variance(0.30484231377123, 150)
sound.envelope.punch = GameScene:variance(0.7393770288859, 150) sound.envelope.punch = math.variance(0.7393770288859, 150)
sound.envelope.decay = 0.43495283918775 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.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.vibrato.speed = 0.44703997451237
sound.change.speed = 0.83105037145914 sound.change.speed = 0.83105037145914
sound.change.amount = -0.66873272021076 sound.change.amount = -0.66873272021076
@ -277,7 +277,3 @@ function GameScene:generateExplosionSound(px,py)
source:setPosition(px,py) source:setPosition(px,py)
source:play() source:play()
end end
function GameScene:variance(seed, variance)
return seed * ((math.random( 100 - (variance/2), 100 + (variance/2)))/100)
end

9
vendor/math.lua vendored
View file

@ -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). -- Averages an arbitrary number of angles (in radians).
function math.averageAngles(...) function math.averageAngles(...)
local x,y = 0,0 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. -- 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. -- 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. -- Normalize two numbers.