(wip) Food now moves with a world flow (which is updated using a manual timer in the GameManager

This commit is contained in:
2026-02-07 16:24:37 +01:00
parent d5b33d66b8
commit bef1e9cb53
4 changed files with 49 additions and 4 deletions

View File

@@ -4,9 +4,38 @@ 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?)
func init_screen_size(x:float, y:float) -> void:
@@ -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)

View File

@@ -1,11 +1,11 @@
[gd_scene load_steps=3 format=3 uid="uid://drgv154ei1vrl"]
[gd_scene format=3 uid="uid://drgv154ei1vrl"]
[ext_resource type="Script" uid="uid://dxc66bci2ivrj" path="res://main_menu.gd" id="1_06t4h"]
[sub_resource type="LabelSettings" id="LabelSettings_rhts7"]
font_size = 64
[node name="MainMenu" type="Control"]
[node name="MainMenu" type="Control" unique_id=369570860]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
@@ -14,7 +14,7 @@ grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_06t4h")
[node name="PlayButton" type="Button" parent="."]
[node name="PlayButton" type="Button" parent="." unique_id=1831335357]
layout_mode = 0
offset_left = 448.0
offset_top = 256.0
@@ -22,7 +22,7 @@ offset_right = 768.0
offset_bottom = 314.0
text = "Play"
[node name="MainMenuText" type="Label" parent="."]
[node name="MainMenuText" type="Label" parent="." unique_id=1324657553]
layout_mode = 0
offset_left = 320.0
offset_top = 32.0

View File

@@ -5,11 +5,17 @@ extends Area2D
@export var val: int = 1
@export var food_name: String = "Food"
@export var flow_carry_speed: float = 10.0
signal consumed
func _ready() -> void:
pass
func _physics_process(delta: float) -> void:
var dpos = Vector2(GameManager.flow_x, GameManager.flow_y) * delta * flow_carry_speed
position += dpos
func _on_body_entered(body: Node2D) -> void:
pass

View File

@@ -1,6 +1,7 @@
extends AbstractFood
class_name FoodMolecular
func _on_body_entered(body: Node2D) -> void:
eat(body)