(wip) Player food
This commit is contained in:
17
evolve-die-repeat/molecular/food/abstract_food.gd
Normal file
17
evolve-die-repeat/molecular/food/abstract_food.gd
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
@abstract
|
||||||
|
class_name AbstractFood
|
||||||
|
extends Area2D
|
||||||
|
|
||||||
|
@export var val: int = 1
|
||||||
|
@export var food_name: String = "Food"
|
||||||
|
|
||||||
|
signal consumed
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
pass
|
||||||
|
|
||||||
|
func _on_body_entered(body: Node2D) -> void:
|
||||||
|
pass
|
||||||
|
|
||||||
|
func eat(consumer: Node2D) -> void:
|
||||||
|
pass
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
@abstract
|
|
||||||
class_name AbstractFood
|
|
||||||
extends Area2D
|
|
||||||
|
|
||||||
@export var val: int = 1
|
|
||||||
@export var food_name: String = "Food"
|
|
||||||
|
|
||||||
func _ready() -> void:
|
|
||||||
body_entered.connect(_on_body_entered)
|
|
||||||
|
|
||||||
func _on_body_entered(body: Node2D) -> void:
|
|
||||||
if body.has_method("collect_resource"): # TODO: Define a "consumer" group instead?
|
|
||||||
eat(body)
|
|
||||||
|
|
||||||
func eat(consumer: Node2D) -> void:
|
|
||||||
print("Player ate: ", food_name)
|
|
||||||
apply_effect(consumer)
|
|
||||||
queue_free()
|
|
||||||
|
|
||||||
func apply_effect(consumer: Node2D) -> void:
|
|
||||||
pass
|
|
||||||
50
evolve-die-repeat/molecular/food/food_manager.gd
Normal file
50
evolve-die-repeat/molecular/food/food_manager.gd
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
extends Node
|
||||||
|
class_name FoodManager2D
|
||||||
|
|
||||||
|
var minCount: int = 20
|
||||||
|
var _currentCount: int = 0
|
||||||
|
|
||||||
|
var rng = RandomNumberGenerator.new()
|
||||||
|
|
||||||
|
@export var foodTypes: Array[PackedScene] = []
|
||||||
|
|
||||||
|
## The probabilities have to add up to 1.0
|
||||||
|
@export var foodProbs: Array[float] = []
|
||||||
|
|
||||||
|
@export var spawnRange: Rect2 = Rect2(0, 0, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready() -> void:
|
||||||
|
spawnRange = GameManager.extent
|
||||||
|
call_deferred("_spawn_minimum")
|
||||||
|
|
||||||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
|
func _process(delta: float) -> void:
|
||||||
|
pass
|
||||||
|
|
||||||
|
func _spawn_minimum() -> void:
|
||||||
|
while _currentCount < minCount:
|
||||||
|
_spawn_random()
|
||||||
|
|
||||||
|
func _random_pos() -> Vector2:
|
||||||
|
return Vector2(randf_range(spawnRange.position[0], spawnRange.size[0]), randf_range(spawnRange.position[1], spawnRange.size[1]))
|
||||||
|
|
||||||
|
func _spawn_random() -> void:
|
||||||
|
var pos = _random_pos()
|
||||||
|
_spawn_food(pos)
|
||||||
|
_currentCount += 1
|
||||||
|
|
||||||
|
func _spawn_food(position: Vector2) -> void:
|
||||||
|
var instance = foodTypes[rng.rand_weighted(foodProbs)].instantiate()
|
||||||
|
instance.position = position
|
||||||
|
add_child(instance)
|
||||||
|
if instance.has_signal("consumed"):
|
||||||
|
instance.consumed.connect(_on_entity_consumed)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_entity_consumed() -> void:
|
||||||
|
_currentCount = max(0, _currentCount-1)
|
||||||
|
call_deferred("_spawn_minimum")
|
||||||
|
|
||||||
|
# TODO: Spawn food when an entity (any) dies
|
||||||
1
evolve-die-repeat/molecular/food/food_manager.gd.uid
Normal file
1
evolve-die-repeat/molecular/food/food_manager.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://7ua0qgyhphao
|
||||||
7
evolve-die-repeat/molecular/food/food_manager.tscn
Normal file
7
evolve-die-repeat/molecular/food/food_manager.tscn
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
[gd_scene format=3 uid="uid://cuqw17010qgob"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://7ua0qgyhphao" path="res://molecular/food/food_manager.gd" id="1_7iais"]
|
||||||
|
|
||||||
|
[node name="FoodManager" type="Node2D" unique_id=858744014]
|
||||||
|
script = ExtResource("1_7iais")
|
||||||
|
metadata/_custom_type_script = "uid://7ua0qgyhphao"
|
||||||
@@ -1,6 +1,18 @@
|
|||||||
extends AbstractFood
|
extends AbstractFood
|
||||||
class_name FoodMolecular
|
class_name FoodMolecular
|
||||||
|
|
||||||
|
func _on_body_entered(body: Node2D) -> void:
|
||||||
|
if body.has_method("collect_resource"): # TODO: Define a "consumer" group instead?
|
||||||
|
eat(body)
|
||||||
|
|
||||||
|
func eat(consumer: Node2D) -> void:
|
||||||
|
print("Player ate: ", food_name)
|
||||||
|
consumed.emit()
|
||||||
|
|
||||||
|
apply_effect(consumer)
|
||||||
|
|
||||||
|
queue_free()
|
||||||
|
|
||||||
func apply_effect(consumer: Node2D) -> void:
|
func apply_effect(consumer: Node2D) -> void:
|
||||||
if consumer.has_method("collect_resource"):
|
if consumer.has_method("collect_resource"):
|
||||||
consumer.collect_resource(val) # val is from parent (default 1), override if required
|
consumer.collect_resource(val) # val is from parent (default 1), override if required
|
||||||
|
|||||||
@@ -1,14 +1,20 @@
|
|||||||
[gd_scene format=3 uid="uid://dmvmu218pc0pe"]
|
[gd_scene format=3 uid="uid://dmvmu218pc0pe"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://cayxffay17o0u" path="res://molecular/food/food_mol.gd" id="1_0vfbj"]
|
||||||
[ext_resource type="Texture2D" uid="uid://dcedkos6vgv51" path="res://molecular/assets/food/food-normal.png" id="2_68e2u"]
|
[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"]
|
[sub_resource type="CircleShape2D" id="CircleShape2D_0vfbj"]
|
||||||
radius = 5.0
|
radius = 5.0
|
||||||
|
|
||||||
[node name="FoodMol" type="Area2D" unique_id=595352294]
|
[node name="FoodMol" type="Area2D" unique_id=595352294]
|
||||||
|
collision_layer = 8
|
||||||
|
collision_mask = 7
|
||||||
|
script = ExtResource("1_0vfbj")
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=762721134]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=762721134]
|
||||||
shape = SubResource("CircleShape2D_0vfbj")
|
shape = SubResource("CircleShape2D_0vfbj")
|
||||||
|
|
||||||
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=98693723]
|
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=98693723]
|
||||||
texture = ExtResource("2_68e2u")
|
texture = ExtResource("2_68e2u")
|
||||||
|
|
||||||
|
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ radius = 191.95984
|
|||||||
height = 1295.8773
|
height = 1295.8773
|
||||||
|
|
||||||
[node name="player" type="CharacterBody2D" unique_id=2032508208]
|
[node name="player" type="CharacterBody2D" unique_id=2032508208]
|
||||||
collision_mask = 6
|
collision_mask = 14
|
||||||
script = ExtResource("1_0ix7k")
|
script = ExtResource("1_0ix7k")
|
||||||
|
|
||||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=1745800698]
|
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=1745800698]
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
[ext_resource type="Script" uid="uid://umx4w11edif" path="res://molecular/prey_manager.gd" id="5_cthuy"]
|
[ext_resource type="Script" uid="uid://umx4w11edif" path="res://molecular/prey_manager.gd" id="5_cthuy"]
|
||||||
[ext_resource type="PackedScene" uid="uid://c3iw2v3x6ngrb" path="res://molecular/prey/nucleotide_prey.tscn" id="6_a5cls"]
|
[ext_resource type="PackedScene" uid="uid://c3iw2v3x6ngrb" path="res://molecular/prey/nucleotide_prey.tscn" id="6_a5cls"]
|
||||||
[ext_resource type="PackedScene" uid="uid://s4s66oaexava" path="res://molecular/predator/hammerhead_predator.tscn" id="7_b1jr0"]
|
[ext_resource type="PackedScene" uid="uid://s4s66oaexava" path="res://molecular/predator/hammerhead_predator.tscn" id="7_b1jr0"]
|
||||||
|
[ext_resource type="Script" uid="uid://7ua0qgyhphao" path="res://molecular/food/food_manager.gd" id="8_mys4o"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://dmvmu218pc0pe" path="res://molecular/food/food_mol.tscn" id="9_ojt85"]
|
||||||
|
|
||||||
[sub_resource type="TileMapPattern" id="TileMapPattern_a5cls"]
|
[sub_resource type="TileMapPattern" id="TileMapPattern_a5cls"]
|
||||||
tile_data = PackedInt32Array(0, 65536, 2, 65536, 65536, 3, 1, 131072, 2, 65537, 131072, 3)
|
tile_data = PackedInt32Array(0, 65536, 2, 65536, 65536, 3, 1, 131072, 2, 65537, 131072, 3)
|
||||||
@@ -122,3 +124,9 @@ scene = ExtResource("7_b1jr0")
|
|||||||
minCount = 10
|
minCount = 10
|
||||||
maxCount = 20
|
maxCount = 20
|
||||||
metadata/_custom_type_script = "uid://coetidfssb80w"
|
metadata/_custom_type_script = "uid://coetidfssb80w"
|
||||||
|
|
||||||
|
[node name="FoodManager" type="Node" parent="." unique_id=449460585]
|
||||||
|
script = ExtResource("8_mys4o")
|
||||||
|
foodTypes = [ExtResource("9_ojt85")]
|
||||||
|
foodProbs = Array[float]([1.0])
|
||||||
|
metadata/_custom_type_script = "uid://7ua0qgyhphao"
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
[ext_resource type="Script" uid="uid://xbiqj7ubmj7d" path="res://molecular/prey/state_idle.gd" id="4_8a23j"]
|
[ext_resource type="Script" uid="uid://xbiqj7ubmj7d" path="res://molecular/prey/state_idle.gd" id="4_8a23j"]
|
||||||
[ext_resource type="Texture2D" uid="uid://jyuf4lgjo64" path="res://molecular/assets/predator/hammerheadRibozyme-hurt.png" id="4_shhro"]
|
[ext_resource type="Texture2D" uid="uid://jyuf4lgjo64" path="res://molecular/assets/predator/hammerheadRibozyme-hurt.png" id="4_shhro"]
|
||||||
[ext_resource type="Script" uid="uid://ubcu8fdfxxj1" path="res://molecular/prey/state_random_movement.gd" id="5_6rsu5"]
|
[ext_resource type="Script" uid="uid://ubcu8fdfxxj1" path="res://molecular/prey/state_random_movement.gd" id="5_6rsu5"]
|
||||||
[ext_resource type="Script" uid="uid://bc7apl71t0q04" path="res://molecular/predator/state_hunting.gd" id="8_7qt2q"]
|
[ext_resource type="Script" path="res://molecular/predator/state_hunting.gd" id="8_7qt2q"]
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_8a23j"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_8a23j"]
|
||||||
atlas = ExtResource("2_34kwa")
|
atlas = ExtResource("2_34kwa")
|
||||||
@@ -118,21 +118,18 @@ metadata/_custom_type_script = "uid://ck7k8ht54snsy"
|
|||||||
|
|
||||||
[node name="Idle" type="Node" parent="StateMachine" unique_id=265876039]
|
[node name="Idle" type="Node" parent="StateMachine" unique_id=265876039]
|
||||||
script = ExtResource("4_8a23j")
|
script = ExtResource("4_8a23j")
|
||||||
metadata/_custom_type_script = "uid://co2xp7gauamql"
|
|
||||||
|
|
||||||
[node name="Timer" type="Timer" parent="StateMachine/Idle" unique_id=1870665609]
|
[node name="Timer" type="Timer" parent="StateMachine/Idle" unique_id=1870665609]
|
||||||
one_shot = true
|
one_shot = true
|
||||||
|
|
||||||
[node name="RandomMovement" type="Node" parent="StateMachine" unique_id=105315122]
|
[node name="RandomMovement" type="Node" parent="StateMachine" unique_id=105315122]
|
||||||
script = ExtResource("5_6rsu5")
|
script = ExtResource("5_6rsu5")
|
||||||
metadata/_custom_type_script = "uid://co2xp7gauamql"
|
|
||||||
|
|
||||||
[node name="Timer" type="Timer" parent="StateMachine/RandomMovement" unique_id=447822526]
|
[node name="Timer" type="Timer" parent="StateMachine/RandomMovement" unique_id=447822526]
|
||||||
one_shot = true
|
one_shot = true
|
||||||
|
|
||||||
[node name="Hunting" type="Node" parent="StateMachine" unique_id=1569866955]
|
[node name="Hunting" type="Node" parent="StateMachine" unique_id=1569866955]
|
||||||
script = ExtResource("8_7qt2q")
|
script = ExtResource("8_7qt2q")
|
||||||
metadata/_custom_type_script = "uid://co2xp7gauamql"
|
|
||||||
|
|
||||||
[node name="Sight" type="Area2D" parent="." unique_id=1608385873]
|
[node name="Sight" type="Area2D" parent="." unique_id=1608385873]
|
||||||
collision_layer = 0
|
collision_layer = 0
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ try_attack={
|
|||||||
2d_physics/layer_1="Player"
|
2d_physics/layer_1="Player"
|
||||||
2d_physics/layer_2="Prey"
|
2d_physics/layer_2="Prey"
|
||||||
2d_physics/layer_3="Predator"
|
2d_physics/layer_3="Predator"
|
||||||
|
2d_physics/layer_4="Food"
|
||||||
|
|
||||||
[rendering]
|
[rendering]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user