8 Commits

12 changed files with 77 additions and 21 deletions

View File

@@ -11,6 +11,7 @@ var extent: Rect2
# utils.
var rng = RandomNumberGenerator.new()
var eps: float = 1e-4
var legacy_movement: bool = false
# managers
var foodManager: FoodManager2D

View File

@@ -10,6 +10,10 @@ func _on_play_button_pressed() -> void:
print(\"Starting game by pressing button...\")
GameManager.start_game()
self.queue_free()
func _on_settings_wheel_button_pressed() -> void:
$Settings.visible = true
"
[sub_resource type="LabelSettings" id="LabelSettings_rhts7"]
@@ -54,8 +58,9 @@ horizontal_alignment = 1
vertical_alignment = 1
[node name="Settings" parent="." unique_id=112964493 node_paths=PackedStringArray("MenuPanelRef") instance=ExtResource("1_06t4h")]
visible = false
layout_mode = 1
MenuPanelRef = NodePath("../SettingsWheelButton")
MenuPanelRef = NodePath("..")
[node name="SettingsWheelButton" type="Button" parent="." unique_id=2147291321]
layout_mode = 0
@@ -63,3 +68,5 @@ offset_left = 898.0
offset_top = 46.0
offset_right = 954.0
offset_bottom = 93.0
[connection signal="pressed" from="SettingsWheelButton" to="." method="_on_settings_wheel_button_pressed"]

View File

@@ -3,6 +3,7 @@ class_name FoodMolecular
@onready var collision: Area2D = $Collision
@onready var sprite: AnimatedSprite2D = $Collision/Sprite
@onready var player = get_tree().get_first_node_in_group("player") # FIXME: this is not v efficient; global resource? or at least per Stage.
func _ready() -> void:
sprite.play()
@@ -30,3 +31,10 @@ func apply_effect(consumer: Node2D) -> void:
if consumer.has_method("collect_resource"): # TODO: Define a "consumer" group instead?
consumer.collect_resource(val) # val is from parent (default 1), override if required
# TODO: *Some cool effect here*
# FIXME: position tracking inaccurate?
func _on_collision_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
if player:
player.target = self.collision

View File

@@ -53,9 +53,6 @@ radius = 5.0
[node name="FoodMol" type="Node2D" unique_id=742430243]
script = ExtResource("1_0vfbj")
val = null
food_name = null
flow_carry_speed = null
metadata/_custom_type_script = "uid://cayxffay17o0u"
[node name="Collision" type="Area2D" parent="." unique_id=927700818]
@@ -78,3 +75,4 @@ script = ExtResource("3_8lhj0")
metadata/_custom_type_script = "uid://bvbc0n0pslq7p"
[connection signal="body_entered" from="Collision" to="." method="_on_body_entered"]
[connection signal="input_event" from="Collision" to="." method="_on_collision_input_event"]

View File

@@ -35,31 +35,29 @@ func _ready() -> void:
sprite.play("default")
func set_target(target) -> void:
$Input.target = target
func _physics_process(delta):
var target_pos = $Input.get_target_position()
var dir: Vector2 = position.direction_to(target_pos)
if position.distance_to(target_pos) > 2:
self.desired_rotation = atan2(dir.y, dir.x)
move_and_collide(speed * dir * delta)
position = GameManager.get_boundaried_position(position)
func _process(delta):
if isAlive:
velocity = Vector2.ZERO
if Input.is_action_pressed("move_right"):
velocity.x += 1
if Input.is_action_pressed("move_left"):
velocity.x -= 1
if Input.is_action_pressed("move_down"):
velocity.y += 1
if Input.is_action_pressed("move_up"):
velocity.y -= 1
if Input.is_action_pressed("try_attack"):
try_attack()
if not velocity.is_zero_approx():
self.desired_rotation = atan2(velocity.y, velocity.x)
# smoothly rotate
if self.rotation != self.desired_rotation:
self.rotation = lerp_angle(self.rotation, self.desired_rotation, clampf(4 * delta, 0, 1))
move_and_collide(speed * velocity * delta)
position = GameManager.get_boundaried_position(position)
func try_attack() -> void:
if not can_attack:
return

View File

@@ -4,6 +4,7 @@
[ext_resource type="Texture2D" uid="uid://du1lb4nr47kvl" path="res://molecular/assets/player-sprite-attacking.png" id="2_rq1v6"]
[ext_resource type="Texture2D" uid="uid://bsd1qtw50esai" path="res://molecular/assets/player-sprite-attacking2.png" id="3_xiwfn"]
[ext_resource type="Texture2D" uid="uid://cd0iv6hsi3fad" path="res://molecular/assets/player-sprite.png" id="4_rq1v6"]
[ext_resource type="Script" uid="uid://dehus7ao5xv2l" path="res://molecular/player_input.gd" id="5_xiwfn"]
[sub_resource type="SpriteFrames" id="SpriteFrames_onrkg"]
animations = [{
@@ -49,6 +50,9 @@ animation = &"attacking"
rotation = -1.5732701
shape = SubResource("CapsuleShape2D_4flbx")
[node name="Input" type="Node" parent="." unique_id=2043215647]
script = ExtResource("5_xiwfn")
[node name="AttackArea" type="Area2D" parent="." unique_id=187975387]
position = Vector2(0, 56)
rotation = -1.5732701

View File

@@ -92,7 +92,7 @@ tile_set = SubResource("TileSet_ojt85")
position = Vector2(112, 64)
[node name="Camera2D" type="Camera2D" parent="player" unique_id=1614218911]
zoom = Vector2(5, 5)
zoom = Vector2(3, 3)
limit_enabled = false
limit_left = 0
limit_top = 0

View File

@@ -0,0 +1,29 @@
extends Node
var target = Vector2.ZERO # should be either Vector2 or Node2D
var updating: bool = false
var holding_lmb: bool = false
func _input(event):
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
if event.pressed:
# start tracking
target = owner.get_global_mouse_position()
updating = true
else:
# stop tracking
updating = false
func _process(delta):
if typeof(target) == TYPE_VECTOR2 and updating:
target = owner.get_global_mouse_position()
func get_target_position() -> Vector2:
if typeof(target) == TYPE_VECTOR2 or typeof(target) == TYPE_VECTOR3:
return target
elif "position" in target:
return target.position
else:
return Vector2.ZERO
target = Vector2.ZERO # reset target to a Vector2

View File

@@ -0,0 +1 @@
uid://dehus7ao5xv2l

View File

@@ -101,6 +101,7 @@ metadata/_custom_type_script = "uid://dgfimmq53whll"
scale = Vector2(0.8, 0.8)
collision_layer = 4
collision_mask = 3
input_pickable = true
script = ExtResource("2_7qt2q")
[node name="Sprite" type="AnimatedSprite2D" parent="Collision" unique_id=410999609]
@@ -154,6 +155,7 @@ script = ExtResource("8_7qt2q")
wait_time = 0.5
one_shot = true
[connection signal="input_event" from="Collision" to="." method="_on_collision_input_event"]
[connection signal="body_entered" from="Collision/Sight" to="." method="_on_sight_body_entered"]
[connection signal="timeout" from="StateMachine/Idle/Timer" to="StateMachine/Idle" method="_on_timer_timeout"]
[connection signal="timeout" from="StateMachine/RandomMovement/Timer" to="StateMachine/RandomMovement" method="_on_timer_timeout"]

View File

@@ -59,6 +59,7 @@ maxHealth = 20
scale = Vector2(0.2, 0.2)
collision_layer = 2
collision_mask = 5
input_pickable = true
script = ExtResource("3_teu34")
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Collision" index="0" unique_id=1471691984]
@@ -109,6 +110,7 @@ script = ExtResource("12_ubfhk")
[node name="Timer" type="Timer" parent="StateMachine/Idle" index="0" unique_id=1050348256]
one_shot = true
[connection signal="input_event" from="Collision" to="." method="_on_collision_input_event"]
[connection signal="body_entered" from="Collision/Sight" to="." method="_on_sight_body_entered"]
[connection signal="timeout" from="StateMachine/RandomMovement/Timer" to="StateMachine/RandomMovement" method="_on_timer_timeout"]
[connection signal="timeout" from="StateMachine/Idle/Timer" to="StateMachine/Idle" method="_on_timer_timeout"]

View File

@@ -4,6 +4,7 @@ class_name NPC
@export var maxHealth: int = 0
@export var idle_sprite: String = "Healthy"
var health: int = maxHealth
@onready var player = get_tree().get_first_node_in_group("player")
signal died
@@ -36,3 +37,8 @@ func play_sprite(anim: String) -> void:
self.sprite.play(anim)
if "wrapper" in self:
self.wrapper.play_sprite(anim)
func _on_collision_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
if player:
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
player.set_target(self.collision)