Skip to content

Commit

Permalink
Fine-tune parallax star like entities movement
Browse files Browse the repository at this point in the history
  • Loading branch information
lloydlobo committed Nov 6, 2024
1 parent e8ad173 commit 155ecb8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 22 deletions.
14 changes: 7 additions & 7 deletions src/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,16 @@ return {
FIXED_FPS = _fixed_fps,
GAME_MAX_LEVEL = 2 ^ 6, -- > 64
LASER_FIRE_TIMER_LIMIT = (_inv_phi ^ 0) * ({ 0.21, 0.16, 0.14 })[_speed_mode], --- Reduce this to increase fire rate.
LASER_MAX_CAPACITY = 2 ^ 8, -- Choices: 2^4(balanced [nerfs fast fire rate]) | 2^5 (long range)
LASER_MAX_CAPACITY = 2 ^ 6, -- Choices: 2^4(balanced [nerfs fast fire rate]) | 2^5 (long range)
LASER_PROJECTILE_SPEED = ({ 2 ^ 7, 2 ^ 8, 2 ^ 8 + 256 })[_speed_mode], --- 256|512|768
LASER_RADIUS = (_inv_phi ^ 1.5) * math.max(_inv_phi * _player_radius, math.floor(_player_radius * (_inv_phi ^ (1 * _phi)))),
PARALLAX_ENTITY_IMG_RADIUS = 32,
PARALLAX_ENTITY_MAX_COUNT = (2 ^ 6),
PARALLAX_ENTITY_MAX_DEPTH = 3, --- @type integer
PARALLAX_ENTITY_MIN_DEPTH = 0, --- @type integer
PARALLAX_ENTITY_IMG_RADIUS = 16,
PARALLAX_ENTITY_MAX_COUNT = (2 ^ 5),
PARALLAX_ENTITY_MAX_DEPTH = 4, --- @type integer
PARALLAX_ENTITY_MIN_DEPTH = 1, --- @type integer
PARALLAX_ENTITY_RADIUS_FACTOR = 0.25 * 0.125 * 16, --- QUESTION: Are we scaling up by this factor? (should ensure resulting radius is similar to `PARALLAX_ENTITY_IMG_RADIUS`)
PARALLAX_OFFSET_FACTOR_X = 0.02, -- NOTE: Should be lower to avoid puking
PARALLAX_OFFSET_FACTOR_Y = 0.02,
PARALLAX_OFFSET_FACTOR_X = 0.00, -- NOTE: Should be lower to avoid puking
PARALLAX_OFFSET_FACTOR_Y = 0.00,
PLAYER_ACCELERATION = math.floor(3 * (true and 1 or 1.25) * ({ 150, 200, 300 })[_speed_mode]),
PLAYER_CIRCLE_IRIS_TO_EYE_RATIO = _inv_phi,
PLAYER_DEFAULT_TURN_SPEED = ({ (10 * _inv_phi), 10, -2 + (30 / 2) / 4 + (_player_accel / _fixed_fps) })[_speed_mode],
Expand Down
53 changes: 38 additions & 15 deletions src/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -519,15 +519,33 @@ local parallax_sign1_ = ({ -1, 1 })[love.math.random(1, 2)]
local parallax_sign2_ = ({ -3, 3 })[love.math.random(1, 2)]
function update_background_shader(dt)
local alpha = dt_accum * Config.FIXED_DT_INV
local a, b, t = (parallax_sign1_ * 0.003 * alpha), (parallax_sign2_ * 0.03 * alpha), math.sin(0.003 * alpha)
local smoothValue = smoothstep(a, b, t)
local freq = (smoothstep(Common.sign(smoothValue) * (dt + 0.001), Common.sign(smoothValue) * (smoothValue + 0.001), 0.5))
local vel_x = 0.02 * 5 * freq * dt
local vel_y = 4 * 4 * math.abs(0.4 * 2 * freq) * dt
-- local a, b, t = (parallax_sign1_ * 0.003 * alpha), (parallax_sign2_ * 0.03 * alpha), math.sin(0.003 * alpha)
-- local smoothValue = smoothstep(a, b, t)
-- local freq = (smoothstep(Common.sign(smoothValue) * (dt + 0.001), Common.sign(smoothValue) * (smoothValue + 0.001), 0.5))

local speed_y = (arena_h / 32) * 0.001

local game_freq_x = math.sin(2 * game_timer_t) / 2
local game_freq_y = math.sin((4 + love.math.random()) * game_timer_t * 0.0625) / 4

local vel_x = 0.25 * 0.001 * lume.clamp(game_freq_x, -1, 1)
-- do
-- vel_x = vel_x + 0.5 * 0.001 * math.sin(8 * love.math.random()) / 8
-- end

local vel_y = speed_y * (INV_PHI_SQ * math.abs(game_freq_y))
vel_y = math.max(smoothstep(vel_y, 0.001 * 5, 0.4), vel_y)
-- vel_y = smoothstep(vel_y * PHI, vel_y * 2, love.math.random() - game_freq_x)

if vel_y < 0.000005 then assert(false, vel_y) end
do
-- vel_y = smoothstep(vel_y, (0.125 * 0.001 * math.abs(love.math.random()) + 1) * speed_y, game_freq_y)
end

for i = 1, Config.PARALLAX_ENTITY_MAX_COUNT, 4 do
if Config.IS_GRUG_BRAIN and screenshake.duration > 0 then
vel_x = vel_x - smoothstep(vel_x * (-love.math.random(-4, 4)), vel_x * love.math.random(-4, 4), smoothValue)
vel_y = vel_y - smoothstep(vel_y * (-love.math.random(-0.5, 2.5)), vel_y * love.math.random(0, 8), smoothValue)
vel_x = vel_x - smoothstep(vel_x * (-love.math.random(-4, 4)), vel_x * love.math.random(-4, 4), game_freq_x)
vel_y = vel_y - smoothstep(vel_y * (-love.math.random(-0.5, 2.5)), vel_y * love.math.random(0, 8), game_freq_y)
end
parallax_entities.x[i] = parallax_entities.x[i] - math.sin(parallax_entities.depth[i] * vel_x)
parallax_entities.x[i + 1] = parallax_entities.x[i + 1] - math.sin(parallax_entities.depth[i + 1] * vel_x)
Expand Down Expand Up @@ -2254,28 +2272,32 @@ function love.draw()
if has_background then
LG.rectangle('fill', 0, 0, arena_w, arena_h) --- draw background fill, else background color shows up (maybe use LG.clearBackground())
end
draw_background_shader(alpha)
LG.setShader() -- > background_gradient_shader
else
local blend_mode = LG.getBlendMode()
LG.setBlendMode('alpha', 'premultiplied')
LG.setBlendMode('screen', 'premultiplied')
do
LG.setShader(glsl_shaders.warp)
do
-- Draw background fill, else background color shows up─if menu/pause, or use `LG.clearBackground())`
if has_background then LG.rectangle('fill', 0, 0, arena_w, arena_h) end
if has_background then
-- Draw background fill, else background color shows up─if menu/pause, or
-- use `LG.clearBackground())`
LG.rectangle('fill', 0, 0, arena_w, arena_h)
end
end
LG.setShader() --> glsl_shader.warp
end
do
if true then
--[[ LG.setBlendMode('alpha', 'premultiplied') ]]
moonshine_shaders.fog(function() end)
--[[ LG.setBlendMode('screen', 'premultiplied') ]]
end
if true then
LG.setBlendMode('add', 'premultiplied')
do
draw_background_shader(alpha)
end
draw_background_shader(alpha)
LG.setBlendMode('screen', 'premultiplied')
end
if true then moonshine_shaders.fog(function() end) end
end
LG.setBlendMode(blend_mode) -- end of 'screen'
end
Expand All @@ -2299,6 +2321,7 @@ function love.draw()
for x = -1, 1 do
LG.origin()
LG.translate(x * arena_w, y * arena_h)
draw_background_shader(alpha)
draw_game(alpha)
LG.origin()
end
Expand Down

0 comments on commit 155ecb8

Please sign in to comment.