Last active
September 7, 2018 15:48
-
-
Save profan/35066be1297bb9ae785bb3d3e288e0c0 to your computer and use it in GitHub Desktop.
newer thing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Node2D | |
const Util = preload("res://util.gd") | |
const Flickering = Util.Flickering | |
export(float) var width | |
export(float) var height | |
var glow_speed = 0.00125 # per second | |
export(float) var glow_min_target = 0.425 | |
export(float) var glow_max_target = 0.515 | |
export(float) var glow_mul = 0.05 | |
export(float) var flicker_min = 0.5 | |
export(float) var flicker_max = 2.5 | |
var flicker_timer = 0.0 | |
var flicker_next = 1.0 | |
var flicker_steps_min = 1 | |
var flicker_steps_max = 5 | |
var flicker_step_min = 0.1 | |
var flicker_step_max = 0.3 | |
var cur_flickering | |
func _ready(): | |
randomize() | |
cur_flickering = Flickering.new( | |
funcref(self, "_single_flicker"), | |
flicker_steps_min, | |
flicker_steps_max, | |
flicker_step_min, | |
flicker_step_max | |
) | |
func _draw(): | |
draw_rect(Rect2(0, 0, width, height), modulate, true) | |
func _single_flicker(): | |
self_modulate.r += 0.75 | |
self_modulate.g += 0.75 | |
self_modulate.b += 0.75 | |
func _process(delta): | |
if !get_parent().visible: set_process(false) | |
self_modulate.r = glow_min_target + ((sin(OS.get_ticks_msec() * glow_speed) + 0.5) * glow_mul) | |
self_modulate.g = glow_min_target + ((sin(OS.get_ticks_msec() * glow_speed) + 0.5) * glow_mul) | |
self_modulate.b = glow_min_target + ((sin(OS.get_ticks_msec() * glow_speed) + 0.5) * glow_mul) | |
if not cur_flickering.done(): | |
cur_flickering.tick(delta) | |
flicker_timer += delta | |
if flicker_timer >= flicker_next: | |
if cur_flickering.done(): cur_flickering.start() | |
flicker_next = rand_range(flicker_min, flicker_max) | |
flicker_timer = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Object | |
class Flickering: | |
var step = 0 | |
var steps = 0 | |
var steps_max | |
var steps_min | |
var step_max | |
var step_min | |
var wait_time = 0.0 | |
var function | |
func _init(fnc, ss_min, ss_max, s_min, s_max): | |
function = fnc | |
steps_max = ss_max | |
steps_min = ss_min | |
step_max = s_max | |
step_min = s_min | |
func start(): | |
step = 0 | |
steps = int(rand_range(steps_min, steps_max)) | |
wait_time = 0.0 | |
func tick(delta): | |
wait_time -= delta | |
if wait_time <= 0.0: | |
wait_time = rand_range(step_min, step_max) | |
function.call_func() | |
step += 1 | |
func done(): | |
return step >= steps |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment