(wip) Food now moves with a world flow (which is updated using a manual timer in the GameManager
This commit is contained in:
@@ -4,8 +4,37 @@ var screen_size = Vector2(1920.0, 1080.0) # Default screen size (this is a floa
|
||||
var viewport_size
|
||||
@onready var extent: Rect2 = get_viewport().get_visible_rect()
|
||||
|
||||
# utils.
|
||||
var rng = RandomNumberGenerator.new()
|
||||
var eps: float = 1e-4
|
||||
|
||||
# A world "current"
|
||||
# polar
|
||||
var flow_dir: float # [0, 2pi)
|
||||
var flow_mag: float # [0, 1]
|
||||
# cartesian
|
||||
var flow_x: float
|
||||
var flow_y: float
|
||||
# Swap period
|
||||
var flowT: float = 10
|
||||
|
||||
# A game timer
|
||||
var t: float = 0.0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
viewport_size = get_viewport().get_visible_rect().size
|
||||
|
||||
# initial world current
|
||||
get_new_flow()
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
t += delta
|
||||
|
||||
# Flow current change
|
||||
if abs(fmod(t, flowT)) < eps:
|
||||
get_new_flow()
|
||||
|
||||
|
||||
# TODO: This needs to be called from a script inheriting a CharacterBody2D (e.g. the player)
|
||||
# Alternative would be to pass the player reference to this script (which might be better?)
|
||||
@@ -22,3 +51,12 @@ func get_boundaried_position(position):
|
||||
position.x = wrapf(position.x, 0, screen_size.x)
|
||||
position.y = wrapf(position.y, 0, screen_size.y)
|
||||
return position
|
||||
|
||||
func get_new_flow():
|
||||
flow_dir = rng.randf()*2*PI
|
||||
flow_mag = rng.randf()
|
||||
|
||||
flow_x = flow_mag * cos(flow_dir)
|
||||
flow_y = flow_mag * sin(flow_dir)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user