Merge remote-tracking branch 'refs/remotes/origin/stage/molecular' into stage/molecular

This commit is contained in:
2026-03-01 15:41:03 +01:00
28 changed files with 232 additions and 194 deletions

View File

@@ -1,6 +1,6 @@
@abstract
class_name AbstractFood
extends Area2D
extends Node2D
@export var val: int = 1
@export var food_name: String = "Food"

View File

@@ -1,8 +1,11 @@
extends AbstractFood
class_name FoodMolecular
@onready var collision: Area2D = $Collision
@onready var sprite: AnimatedSprite2D = $"Collision/Sprite"
func _ready() -> void:
$AnimatedSprite2D.play()
sprite.play()
func _on_body_entered(body: Node2D) -> void:
eat(body)

View File

@@ -7,9 +7,6 @@
[ext_resource type="Texture2D" uid="uid://dj4lyyloj1ke1" path="res://molecular/assets/food/food-left-bottom-bolt.png" id="5_i3g2v"]
[ext_resource type="Texture2D" uid="uid://cbynycukppmup" path="res://molecular/assets/food/food-right-bottom-bolt.png" id="6_07uaq"]
[sub_resource type="CircleShape2D" id="CircleShape2D_0vfbj"]
radius = 5.0
[sub_resource type="SpriteFrames" id="SpriteFrames_oo5vd"]
animations = [{
"frames": [{
@@ -51,28 +48,38 @@ animations = [{
"speed": 5.0
}]
[node name="FoodMol" type="Area2D" unique_id=595352294]
[sub_resource type="CircleShape2D" id="CircleShape2D_0vfbj"]
radius = 5.0
[node name="FoodMol" type="Node2D" unique_id=742430243]
script = ExtResource("1_0vfbj")
collision_layer = 8
collision_mask = 7
script = ExtResource("1_0vfbj")
val = null
food_name = null
flow_carry_speed = null
metadata/_custom_type_script = "uid://cayxffay17o0u"
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=762721134]
shape = SubResource("CircleShape2D_0vfbj")
[node name="Collision" type="Area2D" parent="." unique_id=927700818]
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=98693723]
visible = false
scale = Vector2(0.385, 0.385)
texture = ExtResource("2_68e2u")
[node name="WrappingManager" type="Node" parent="." unique_id=1406150436 node_paths=PackedStringArray("sprite", "shape")]
script = ExtResource("3_8lhj0")
sprite = NodePath("../AnimatedSprite2D")
shape = NodePath("../CollisionShape2D")
metadata/_custom_type_script = "uid://bvbc0n0pslq7p"
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=1856148995]
[node name="Sprite" type="AnimatedSprite2D" parent="Collision" unique_id=1856148995]
texture_filter = 1
sprite_frames = SubResource("SpriteFrames_oo5vd")
frame_progress = 0.9373464
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
[node name="Sprite2D" type="Sprite2D" parent="Collision" unique_id=98693723]
visible = false
scale = Vector2(0.385, 0.385)
texture = ExtResource("2_68e2u")
[node name="CollisionShape2D" type="CollisionShape2D" parent="Collision" unique_id=762721134]
shape = SubResource("CircleShape2D_0vfbj")
[node name="WrappingManager" type="Node" parent="." unique_id=1406150436 node_paths=PackedStringArray("sprite", "shape")]
script = ExtResource("3_8lhj0")
sprite = NodePath("../Collision/Sprite")
shape = NodePath("../Collision/CollisionShape2D")
dupFlags = 0
metadata/_custom_type_script = "uid://bvbc0n0pslq7p"
[connection signal="body_entered" from="Collision" to="." method="_on_body_entered"]

View File

@@ -86,12 +86,9 @@ func _on_attack_hit(body: Node2D) -> void:
if body.has_method("handle_damage"):
body.handle_damage(damage, self)
hit_hittable = true
elif body.is_in_group("resources"):
pass
if hit_hittable:
await get_tree().create_timer(0.2).timeout
sprite.play("default")
# TODO: resource handling logic
func _on_invulnerable_cooldown_timeout() -> void:
hasiframes = false

View File

@@ -31,7 +31,6 @@ animations = [{
}]
[sub_resource type="CircleShape2D" id="CircleShape2D_5hxmy"]
radius = 10.999997
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_4flbx"]
radius = 5.999982
@@ -52,7 +51,7 @@ rotation = -1.5732701
collision_mask = 6
[node name="CollisionShape2D" type="CollisionShape2D" parent="AttackArea" unique_id=1968501358]
position = Vector2(55.984985, 6.138512)
position = Vector2(55.977566, 9.138502)
shape = SubResource("CircleShape2D_5hxmy")
debug_color = Color(0.80813414, 0.3957308, 0.3356335, 0.41960785)

View File

@@ -0,0 +1,22 @@
extends CharacterBody2D
var desired_rotation: float = self.rotation
@export var speed = 0.8
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
# smoothly rotate
if self.rotation != self.desired_rotation:
self.rotation = lerp_angle(self.rotation, self.desired_rotation, clampf(4 * delta, 0, 1))
func move(motion: Vector3, mod: float) -> void:
self.desired_rotation = atan2(motion.y, motion.x)
move_and_collide(Vector2(motion.x, motion.y).normalized() * self.speed * mod) # Moves along the given vector
# Apply boundary to new position
position = GameManager.get_boundaried_position(position)
func duplicate_init() -> void:
var sight = $Sight
remove_child(sight)
sight.queue_free()

View File

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

View File

@@ -1,40 +1,33 @@
extends AbstractPredator2D
extends AbstractPredator
# FIXME: (general) tracking across wrapping boundary
var starting_pos
var can_attack: bool = true
var desired_rotation: float = self.rotation
@onready var sprite = $AnimatedSprite2D
@onready var fsm: StateMachine = $StateMachine
@onready var attack_cooldown_timer: Timer = $AttackCooldownTimer
@onready var wrapper: WrappingManager = $WrappingManager
@onready var collision: CharacterBody2D = $Collision
@onready var sprite = $"Collision/Sprite"
@export var damage: int = 15
@export var attack_range = 40
@export var sight_range = 200
@export var speed = 0.8
func _ready() -> void:
health = maxHealth
sprite.play("Healthy")
if starting_pos:
collision.set_position(starting_pos)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
# smoothly rotate
if self.rotation != self.desired_rotation:
self.rotation = lerp_angle(self.rotation, self.desired_rotation, clampf(4 * delta, 0, 1))
func _physics_process(delta: float) -> void:
pass
# FIXME: (also goes for prey) this is framerate dependent UNLESS called from a _physics function.
func move(motion: Vector3, mod: float = 1.0) -> void:
move_and_collide(Vector2(motion.x, motion.y).normalized() * self.speed * mod) # Moves along the given vector
self.desired_rotation = atan2(motion.y, motion.x)
# Apply boundary to new position
position = GameManager.get_boundaried_position(position)
collision.move(motion, mod)
func set_position(pos: Vector2) -> void:
if collision:
collision.set_position(pos)
else:
starting_pos = pos
func try_attack(target: Node) -> void:
if not can_attack:
@@ -46,7 +39,7 @@ func attack(target: Node) -> void:
var hit_hittable = false
if target.is_in_group("prey") or target.is_in_group("player"):
if target.has_method("handle_damage"):
target.handle_damage(damage, self)
target.handle_damage(damage, self.collision)
hit_hittable = true
elif target.is_in_group("resources"):
# TODO: resource handling logic

View File

@@ -1,6 +1,7 @@
[gd_scene format=3 uid="uid://s4s66oaexava"]
[ext_resource type="Script" uid="uid://d07cjelbqbiug" path="res://molecular/predator/hammerhead_predator.gd" id="1_xp037"]
[ext_resource type="Script" uid="uid://cus6ogtwxx4v7" path="res://molecular/predator/collision.gd" id="2_7qt2q"]
[ext_resource type="Texture2D" uid="uid://ch5rddsumyyhm" path="res://molecular/assets/predator/predator-healthy.png" id="2_34kwa"]
[ext_resource type="Texture2D" uid="uid://30uwkdbnuu3h" path="res://molecular/assets/predator/hammerheadRibozyme-hunting.png" id="3_0ts4d"]
[ext_resource type="Script" uid="uid://cygrmt03sx0k1" path="res://molecular/predator/state_machine.gd" id="3_xp037"]
@@ -91,31 +92,43 @@ animations = [{
"speed": 5.0
}]
[node name="HammerheadPredator" type="CharacterBody2D" unique_id=678504815 groups=["predator"]]
collision_layer = 4
collision_mask = 3
motion_mode = 1
[node name="HammerheadPredator" type="Node" unique_id=1312337720]
script = ExtResource("1_xp037")
maxHealth = 50
metadata/_custom_type_script = "uid://dgfimmq53whll"
[node name="WrappingManager" type="Node" parent="." unique_id=826586678 node_paths=PackedStringArray("sprite", "shape")]
script = ExtResource("9_shhro")
sprite = NodePath("../AnimatedSprite2D")
shape = NodePath("../CollisionPolygon2D")
metadata/_custom_type_script = "uid://bvbc0n0pslq7p"
[node name="Collision" type="CharacterBody2D" parent="." unique_id=76553184 groups=["predator"]]
scale = Vector2(0.8, 0.8)
collision_layer = 4
collision_mask = 3
script = ExtResource("2_7qt2q")
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="." unique_id=1596156928]
[node name="Sprite" type="AnimatedSprite2D" parent="Collision" unique_id=410999609]
rotation = -1.5707964
sprite_frames = SubResource("SpriteFrames_shhro")
animation = &"Healthy"
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Collision" unique_id=1596156928]
light_mask = 4
visibility_layer = 4
position = Vector2(0.111679085, 1.1167793)
rotation = -1.5707964
polygon = PackedVector2Array(-22.184862, -27.994831, 23.481365, -27.21198, 13.82622, 25.891317, -6.005971, 25.891317)
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=410999609]
rotation = 4.712389
sprite_frames = SubResource("SpriteFrames_shhro")
animation = &"Hunting"
[node name="Sight" type="Area2D" parent="Collision" unique_id=1608385873]
collision_layer = 0
collision_mask = 7
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Collision/Sight" unique_id=1707240701]
light_mask = 4
visibility_layer = 4
position = Vector2(-1.0900421, 1.6350927)
rotation = -1.5707964
polygon = PackedVector2Array(-27.769547, -29.426758, 31.88504, -29.184647, 12.700996, 28.7294, 56.058624, 148.93633, 22.979004, 163.77974, -19.854843, 161.65926, -53.782654, 143.84715, -8.333115, 30.157196)
[node name="WrappingManager" type="Node" parent="." unique_id=826586678]
script = ExtResource("9_shhro")
metadata/_custom_type_script = "uid://bvbc0n0pslq7p"
[node name="StateMachine" type="Node" parent="." unique_id=1857729810 node_paths=PackedStringArray("initial_state")]
script = ExtResource("3_xp037")
@@ -137,22 +150,11 @@ one_shot = true
[node name="Hunting" type="Node" parent="StateMachine" unique_id=1569866955]
script = ExtResource("8_7qt2q")
[node name="Sight" type="Area2D" parent="." unique_id=1608385873]
collision_layer = 0
collision_mask = 7
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Sight" unique_id=1707240701]
light_mask = 4
visibility_layer = 4
position = Vector2(-1.0900421, 1.6350927)
rotation = -1.5707964
polygon = PackedVector2Array(-27.769547, -29.426758, 31.88504, -29.184647, 12.700996, 28.7294, 56.058624, 148.93633, 22.979004, 163.77974, -19.854843, 161.65926, -53.782654, 143.84715, -8.333115, 30.157196)
[node name="AttackCooldownTimer" type="Timer" parent="." unique_id=435253442]
wait_time = 0.5
one_shot = true
[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"]
[connection signal="body_entered" from="Sight" to="." method="_on_sight_body_entered"]
[connection signal="timeout" from="AttackCooldownTimer" to="." method="_on_attack_cooldown_timer_timeout"]

View File

@@ -11,16 +11,16 @@ func enter(previous_state_path: String, data := {}) -> void:
finished.emit(owner.fsm.States.IDLE, {})
func physics_update(_delta: float) -> void:
if target == null or GameManager.calc_distance(owner.position, target.position) > owner.sight_range:
if target == null or GameManager.calc_distance(owner.collision.position, target.position) > owner.sight_range:
finished.emit(owner.fsm.States.IDLE, {})
return
# alternatively, we could use a collision shape and inbuilt signals, but im not sure if that works better (mixing signals and custom fsm stuff i mean
if GameManager.calc_distance(owner.position, target.position) > owner.attack_range:
if GameManager.calc_distance(owner.collision.position, target.position) > owner.attack_range:
owner.move(move_towards(target.position))
else:
owner.attack(target)
func move_towards(pos: Vector2) -> Vector3:
var diff = target.position - owner.position
var diff = target.position - owner.collision.position
return Vector3(diff.x, diff.y ,0)

View File

@@ -0,0 +1,28 @@
extends CharacterBody2D
var desired_rotation: float = self.rotation
@export var speed = 0.5
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
# smoothly rotate
if self.rotation != self.desired_rotation:
self.rotation = lerp_angle(self.rotation, self.desired_rotation, clampf(4 * delta, 0, 1))
func move(motion: Vector3, mod: float) -> void:
move_and_collide(Vector2(motion.x, motion.y).normalized() * self.speed * mod) # Moves along the given vector
self.desired_rotation = atan2(motion.y, motion.x)
# Apply boundary to new position
position = GameManager.get_boundaried_position(position)
func handle_damage(dmg: int, src: Node) -> void:
if owner:
owner.handle_damage(dmg, src)
func duplicate_init() -> void:
var sight = $Sight
remove_child(sight)
sight.queue_free()

View File

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

View File

@@ -1,33 +1,26 @@
extends AbstractPrey2D
extends AbstractPrey
@onready var wrapper: WrappingManager = $WrappingManager
@onready var sprite: AnimatedSprite2D = $AnimatedSprite2D
@onready var collision: CharacterBody2D = $Collision
@onready var sprite: AnimatedSprite2D = $"Collision/Sprite"
@onready var fsm: StateMachine = $StateMachine
@export var speed = 0.5
var desired_rotation: float = self.rotation
var starting_pos
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
health = maxHealth
sprite.play("Healthy")
if starting_pos:
collision.set_position(starting_pos)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
# smoothly rotate
if self.rotation != self.desired_rotation:
self.rotation = lerp_angle(self.rotation, self.desired_rotation, clampf(4 * delta, 0, 1))
func _physics_process(delta: float) -> void:
pass
func set_position(pos: Vector2) -> void:
if collision:
collision.set_position(pos)
else:
starting_pos = pos
func move(motion: Vector3, mod: float = 1.0) -> void:
move_and_collide(Vector2(motion.x, motion.y).normalized() * self.speed * mod) # Moves along the given vector
self.desired_rotation = atan2(motion.y, motion.x)
# Apply boundary to new position
position = GameManager.get_boundaried_position(position)
collision.move(motion, mod)
func handle_damage(dmg: int, src: Node) -> void:
health = max(0, health-dmg)
@@ -40,7 +33,7 @@ func handle_damage(dmg: int, src: Node) -> void:
func die() -> void:
sprite.play("Dying")
wrapper.play_sprite("Dying")
GameManager.foodManager._spawn_food(position)
GameManager.foodManager._spawn_food(collision.position)
super.die()
func become_injured() -> void:

View File

@@ -1,10 +1,11 @@
[gd_scene format=3 uid="uid://c3iw2v3x6ngrb"]
[ext_resource type="PackedScene" uid="uid://bvsdg1v3ksixy" path="res://shared/npc/prey2D.tscn" id="1_qvulj"]
[ext_resource type="PackedScene" uid="uid://bvsdg1v3ksixy" path="res://shared/npc/abstractPrey.tscn" id="1_qvulj"]
[ext_resource type="Script" uid="uid://bgossk6xo31gi" path="res://molecular/prey/nucleotide_prey.gd" id="2_0227s"]
[ext_resource type="Texture2D" uid="uid://bhcb5g7g7um8" path="res://molecular/assets/prey/prey-dying-frame0.png" id="2_lkj7f"]
[ext_resource type="Script" uid="uid://bvbc0n0pslq7p" path="res://shared/wrapping_manager.gd" id="3_lecx4"]
[ext_resource type="Texture2D" uid="uid://bxn11avw7dykl" path="res://molecular/assets/prey/prey-dying-frame1.png" id="3_svqyr"]
[ext_resource type="Script" uid="uid://dcd4lhhq8pubb" path="res://molecular/prey/collision.gd" id="3_teu34"]
[ext_resource type="Texture2D" uid="uid://ctkehsavw6ghx" path="res://molecular/assets/prey/prey-healthy-frame0.png" id="4_ee1gb"]
[ext_resource type="Texture2D" uid="uid://uy28y3mkk6nt" path="res://molecular/assets/prey/prey-healthy-frame1.png" id="5_ae5nf"]
[ext_resource type="Texture2D" uid="uid://btnyajci8ptb2" path="res://molecular/assets/prey/prey-injured-frame0.png" id="6_0f87h"]
@@ -51,33 +52,45 @@ animations = [{
}]
[node name="NucleotidePrey" unique_id=740525631 groups=["prey"] instance=ExtResource("1_qvulj")]
collision_layer = 2
collision_mask = 5
motion_mode = 1
script = ExtResource("2_0227s")
speed = 0.5
maxHealth = 20
[node name="WrappingManager" type="Node" parent="." index="0" unique_id=407460873 node_paths=PackedStringArray("sprite", "shape")]
script = ExtResource("3_lecx4")
sprite = NodePath("../AnimatedSprite2D")
shape = NodePath("../CollisionPolygon2D")
metadata/_custom_type_script = "uid://bvbc0n0pslq7p"
[node name="Collision" type="CharacterBody2D" parent="." index="0" unique_id=331517910 groups=["prey"]]
scale = Vector2(0.2, 0.2)
collision_layer = 2
collision_mask = 5
script = ExtResource("3_teu34")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." index="1" unique_id=788182944]
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Collision" index="0" unique_id=1471691984]
light_mask = 2
visibility_layer = 2
position = Vector2(69, 28)
rotation = 0.47415397
scale = Vector2(10, 10)
polygon = PackedVector2Array(-8.700367, -2.2789505, -5.6133537, -2.1772134, -4.1979375, 0.58079255, -5.9151926, 3.1480935, -8.862037, 2.9326901, -10.268076, 0.28495264)
[node name="Sprite" type="AnimatedSprite2D" parent="Collision" index="1" unique_id=788182944]
rotation = 1.5707964
sprite_frames = SubResource("SpriteFrames_66x8p")
animation = &"Healthy"
[node name="CollisionPolygon2D" parent="." index="2"]
[node name="Sight" type="Area2D" parent="Collision" index="2" unique_id=1773478588]
scale = Vector2(0.4, 0.4)
collision_layer = 0
collision_mask = 7
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Collision/Sight" index="0" unique_id=338757598]
light_mask = 2
visibility_layer = 2
position = Vector2(69, 28)
rotation = 0.474154
rotation = 1.5707964
scale = Vector2(10, 10)
polygon = PackedVector2Array(-8.700367, -2.2789505, -5.6133537, -2.1772134, -4.1979375, 0.58079255, -5.9151926, 3.1480935, -8.862037, 2.9326901, -10.268076, 0.28495264)
polygon = PackedVector2Array(3.8686981, -6.2705374, 7.0000973, -0.08602524, 3.5555592, 5.6287766, -3.0986624, 5.589636, -6.1517763, 0.031402588, -2.942093, -6.0748243, -29.993027, -74.37026, -11.10141, -83.6233, 9.332382, -84.00884, 35.163773, -77.06906)
[node name="StateMachine" type="Node" parent="." index="3" unique_id=445822474 node_paths=PackedStringArray("initial_state")]
[node name="WrappingManager" type="Node" parent="." index="1" unique_id=407460873]
script = ExtResource("3_lecx4")
metadata/_custom_type_script = "uid://bvbc0n0pslq7p"
[node name="StateMachine" type="Node" parent="." index="2" unique_id=445822474 node_paths=PackedStringArray("initial_state")]
script = ExtResource("9_xxtgy")
initial_state = NodePath("Idle")
@@ -96,17 +109,6 @@ script = ExtResource("12_ubfhk")
[node name="Timer" type="Timer" parent="StateMachine/Idle" index="0" unique_id=1050348256]
one_shot = true
[node name="Sight" type="Area2D" parent="." index="4" unique_id=1773478588]
collision_layer = 0
collision_mask = 7
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Sight" index="0" unique_id=338757598]
light_mask = 2
visibility_layer = 2
rotation = 1.5707964
scale = Vector2(10, 10)
polygon = PackedVector2Array(3.8686981, -6.2705374, 7.0000973, -0.08602524, 3.5555592, 5.6287766, -3.0986624, 5.589636, -6.1517763, 0.031402588, -2.942093, -6.0748243, -29.993027, -74.37026, -11.10141, -83.6233, 9.332382, -84.00884, 35.163773, -77.06906)
[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"]
[connection signal="body_entered" from="Sight" to="." method="_on_sight_body_entered"]

View File

@@ -1,6 +1,6 @@
extends State
var threat: Node2D
var threat: Node
var threshold: float = 100
func enter(previous_state_path: String, data := {}) -> void:
@@ -11,13 +11,12 @@ func enter(previous_state_path: String, data := {}) -> void:
finished.emit(owner.fsm.States.IDLE, {})
func physics_update(_delta: float) -> void:
if not is_instance_valid(threat) or GameManager.calc_distance(owner.position, threat.position) > threshold:
if not is_instance_valid(threat) or GameManager.calc_distance(owner.collision.position, threat.position) > threshold:
finished.emit(owner.fsm.States.IDLE, {})
return
owner.move(flee_from(threat.position))
func flee_from(pos: Vector2) -> Vector3:
# FIXME: What is the argument "pos" and why is it unused?
var diff = threat.position - owner.position
var diff = pos - owner.collision.position
diff = diff.normalized() * -1
return Vector3(diff.x, diff.y ,0)

View File

@@ -1,5 +1,5 @@
extends CharacterBody2D
class_name NPC2D
extends Node
class_name NPC
@export var maxHealth: int = 0
var health: int = maxHealth

View File

@@ -0,0 +1,6 @@
[gd_scene format=3 uid="uid://biup0eej85fq2"]
[ext_resource type="Script" uid="uid://biu3sctw15ga" path="res://shared/npc/abstractNPC.gd" id="1_xlqdr"]
[node name="NPC" type="Node" unique_id=272773627]
script = ExtResource("1_xlqdr")

View File

@@ -1,5 +1,5 @@
extends NPC2D
class_name AbstractPredator2D
extends NPC
class_name AbstractPredator
# Called when the node enters the scene tree for the first time.
func _ready() -> void:

View File

@@ -1,7 +1,7 @@
[gd_scene format=3 uid="uid://b7wqd5owafn6g"]
[ext_resource type="PackedScene" uid="uid://biup0eej85fq2" path="res://shared/npc/npc2D.tscn" id="1_4llks"]
[ext_resource type="Script" uid="uid://dgfimmq53whll" path="res://shared/npc/predator2D.gd" id="2_rj1ok"]
[ext_resource type="PackedScene" uid="uid://biup0eej85fq2" path="res://shared/npc/abstractNPC.tscn" id="1_4llks"]
[ext_resource type="Script" uid="uid://dgfimmq53whll" path="res://shared/npc/abstractPredator.gd" id="2_rj1ok"]
[node name="AbstractPredator" unique_id=912624667 instance=ExtResource("1_4llks")]
script = ExtResource("2_rj1ok")

View File

@@ -1,5 +1,5 @@
extends NPC2D
class_name AbstractPrey2D
extends NPC
class_name AbstractPrey
# Called when the node enters the scene tree for the first time.

View File

@@ -0,0 +1,7 @@
[gd_scene format=3 uid="uid://bvsdg1v3ksixy"]
[ext_resource type="PackedScene" uid="uid://biup0eej85fq2" path="res://shared/npc/abstractNPC.tscn" id="1_fdrej"]
[ext_resource type="Script" uid="uid://76jxpubyd8wp" path="res://shared/npc/abstractPrey.gd" id="2_xkhwn"]
[node name="AbstractPrey" unique_id=1075345151 instance=ExtResource("1_fdrej")]
script = ExtResource("2_xkhwn")

View File

@@ -1,10 +0,0 @@
[gd_scene load_steps=2 format=3 uid="uid://biup0eej85fq2"]
[ext_resource type="Script" uid="uid://biu3sctw15ga" path="res://shared/npc/npc2D.gd" id="1_ucjfp"]
[node name="NPC" type="CharacterBody2D"]
script = ExtResource("1_ucjfp")
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."]
position = Vector2(7.215866, -0.5034294)
polygon = PackedVector2Array(-8.831272, -2.3390446, -5.7760534, -2.3993049, -4.0230684, 0.41277456, -5.8890305, 2.9948444, -8.862037, 2.9326901, -10.268076, 0.28495264)

View File

@@ -1,7 +0,0 @@
[gd_scene load_steps=3 format=3 uid="uid://bvsdg1v3ksixy"]
[ext_resource type="PackedScene" uid="uid://biup0eej85fq2" path="res://shared/npc/npc2D.tscn" id="1_2m1le"]
[ext_resource type="Script" uid="uid://76jxpubyd8wp" path="res://shared/npc/prey2D.gd" id="2_dny00"]
[node name="AbstractPrey" instance=ExtResource("1_2m1le")]
script = ExtResource("2_dny00")

View File

@@ -30,7 +30,7 @@ func _spawn_random() -> void:
func _spawn_creature(position: Vector2) -> void:
var instance = scene.instantiate()
instance.position = position
instance.set_position(position)
add_child(instance)
if instance.has_signal("died"):
#instance.died.connect(GameManager.foodManager._spawn_food_on_position)

View File

@@ -1,7 +1,6 @@
class_name WrappingManager extends Node
@export var sprite: AnimatedSprite2D
@export var shape: Node # FIXME (also in refactor see below) this is bad.
@export var dupFlags: int = 15
# Mirrored sprites for periodic boundary
var mirrors: Array
@@ -10,29 +9,22 @@ var mirrors: Array
func _ready() -> void:
await owner.ready
mirrors.append(Area2D.new())
mirrors.append(Area2D.new())
mirrors.append(Area2D.new())
# TODO: npc overhaul; make npc2d (and child classes) inherit from Node instead of Area2d.
# Each entity should have Area2d -> collisionshape2d + animatedsprite2d. We then duplicate this area2d instead of the bullshit thats happening here
# note taht the below bs also does not work, as the (freshly instantiated) area2ds have none of the signals connected. The above refactor will fix this.
for m in mirrors:
for i in owner.get_groups():
if not str(i).begins_with("_"):
m.add_to_group(i)
m.set_collision_layer(owner.get_collision_layer())
m.set_collision_mask(owner.get_collision_mask())
m.add_child(sprite.duplicate())
m.add_child(shape.duplicate())
owner.call_deferred("add_child", m)
# add mirrors
for _i in range(3):
var dup = owner.collision.duplicate(dupFlags)
mirrors.append(dup)
owner.call_deferred("add_child", dup)
#for i in owner.get_groups():
# if not str(i).begins_with("_"):
# m.add_to_group(i)
if dup.has_method("duplicate_init"):
dup.duplicate_init()
_handle_wrapping()
func play_sprite(anim: String) -> void:
mirrors[0].get_node("AnimatedSprite2D").play(anim)
mirrors[1].get_node("AnimatedSprite2D").play(anim)
mirrors[2].get_node("AnimatedSprite2D").play(anim)
for m in mirrors:
m.get_node("Sprite").play(anim)
func _process(delta: float) -> void:
_handle_wrapping()
@@ -52,39 +44,42 @@ func _process(delta: float) -> void:
# NOTE: For this to look correctly the camera size should be smaller than half the screen port (in
# any one dimension. Ideally, the difference between camera size and half the screen port is
# at least the size of the prey sprite)
func _handle_wrapping():
func _handle_wrapping():
for m in mirrors:
m.global_rotation = owner.collision.global_rotation
# TODO: Assume viewport size << screen size and only draw according to GameManager.viewport_size
# Find corresponding section of the screen
if owner.position.x < GameManager.screen_size.x/2 and owner.position.y < GameManager.screen_size.y/2:
if owner.collision.position.x < GameManager.screen_size.x/2 and owner.collision.position.y < GameManager.screen_size.y/2:
# Right
mirrors[0].global_position = owner.global_position + Vector2(GameManager.screen_size.x, 0)
mirrors[0].global_position = owner.collision.global_position + Vector2(GameManager.screen_size.x, 0)
# Diag
mirrors[2].global_position = owner.global_position + Vector2(GameManager.screen_size.x, GameManager.screen_size.y)
mirrors[2].global_position = owner.collision.global_position + Vector2(GameManager.screen_size.x, GameManager.screen_size.y)
# Bottom
mirrors[1].global_position = owner.global_position + Vector2(0, GameManager.screen_size.y)
mirrors[1].global_position = owner.collision.global_position + Vector2(0, GameManager.screen_size.y)
elif owner.position.x < GameManager.screen_size.x/2:
elif owner.collision.position.x < GameManager.screen_size.x/2:
# Top
mirrors[0].global_position = owner.global_position + Vector2(0, - GameManager.screen_size.y)
mirrors[0].global_position = owner.collision.global_position + Vector2(0, - GameManager.screen_size.y)
# Diag
mirrors[1].global_position = owner.global_position + Vector2(GameManager.screen_size.x, - GameManager.screen_size.y)
mirrors[1].global_position = owner.collision.global_position + Vector2(GameManager.screen_size.x, - GameManager.screen_size.y)
# Right
mirrors[2].global_position = owner.global_position + Vector2(GameManager.screen_size.x, 0)
mirrors[2].global_position = owner.collision.global_position + Vector2(GameManager.screen_size.x, 0)
elif owner.position.y < GameManager.screen_size.y/2:
elif owner.collision.position.y < GameManager.screen_size.y/2:
# Left
mirrors[0].global_position = owner.global_position + Vector2(- GameManager.screen_size.x, 0)
mirrors[0].global_position = owner.collision.global_position + Vector2(- GameManager.screen_size.x, 0)
# Bottom
mirrors[1].global_position = owner.global_position + Vector2(0, GameManager.screen_size.y)
mirrors[1].global_position = owner.collision.global_position + Vector2(0, GameManager.screen_size.y)
# Diag
mirrors[2].global_position = owner.global_position + Vector2(- GameManager.screen_size.x, GameManager.screen_size.y)
mirrors[2].global_position = owner.collision.global_position + Vector2(- GameManager.screen_size.x, GameManager.screen_size.y)
else:
# Left
mirrors[0].global_position = owner.global_position + Vector2(- GameManager.screen_size.x, 0)
mirrors[0].global_position = owner.collision.global_position + Vector2(- GameManager.screen_size.x, 0)
# Diag
mirrors[1].global_position = owner.global_position + Vector2(- GameManager.screen_size.x, - GameManager.screen_size.y)
mirrors[1].global_position = owner.collision.global_position + Vector2(- GameManager.screen_size.x, - GameManager.screen_size.y)
# Top
mirrors[2].global_position = owner.global_position + Vector2(0, - GameManager.screen_size.y)
mirrors[2].global_position = owner.collision.global_position + Vector2(0, - GameManager.screen_size.y)