Compare commits
3 Commits
2211130fd3
...
bef1e9cb53
| Author | SHA1 | Date | |
|---|---|---|---|
| bef1e9cb53 | |||
| d5b33d66b8 | |||
| ceb0d90c20 |
@@ -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)
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
extends AbstractFood
|
||||
class_name FoodMolecular
|
||||
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
eat(body)
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
[ext_resource type="Texture2D" uid="uid://dcedkos6vgv51" path="res://molecular/assets/food/food-normal.png" id="2_68e2u"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_0vfbj"]
|
||||
radius = 5.0
|
||||
radius = 2.0
|
||||
|
||||
[node name="FoodMol" type="Area2D" unique_id=595352294]
|
||||
collision_layer = 8
|
||||
@@ -15,6 +15,7 @@ script = ExtResource("1_0vfbj")
|
||||
shape = SubResource("CircleShape2D_0vfbj")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=98693723]
|
||||
scale = Vector2(0.385, 0.385)
|
||||
texture = ExtResource("2_68e2u")
|
||||
|
||||
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
||||
|
||||
Reference in New Issue
Block a user