(wip) First food commit

This commit is contained in:
2026-02-07 13:23:54 +01:00
parent 22ffa3dac1
commit 098348b329
7 changed files with 35 additions and 6 deletions

View File

@@ -2,14 +2,14 @@
class_name AbstractFood
extends Area2D
@export var val: int = 10
@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.is_in_group("player"):
if body.has_method("collect_resource"): # TODO: Define a "consumer" group instead?
eat(body)
func eat(consumer: Node2D) -> void:

View File

@@ -0,0 +1,7 @@
extends AbstractFood
class_name FoodMolecular
func apply_effect(consumer: Node2D) -> void:
if consumer.has_method("collect_resource"):
consumer.collect_resource(val) # val is from parent (default 1), override if required
# TODO: *Some cool effect here*

View File

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

View File

@@ -0,0 +1,14 @@
[gd_scene format=3 uid="uid://dmvmu218pc0pe"]
[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
[node name="FoodMol" type="Area2D" unique_id=595352294]
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=762721134]
shape = SubResource("CircleShape2D_0vfbj")
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=98693723]
texture = ExtResource("2_68e2u")

View File

@@ -14,6 +14,9 @@ var damage: int = 10
var can_attack: bool = true
var desired_rotation: float = 0
# Resources / money
var resources: int = 0
func _ready() -> void:
var screen_size = get_viewport_rect().size
GameManager.init_screen_size(screen_size.x, screen_size.y)
@@ -82,3 +85,7 @@ func _on_attack_hit(body: Node2D) -> void:
func handle_damage(dmg: int, src: Node) -> void:
# TODO: damage logic
pass
func collect_resource(damnt: int) -> void:
resources += damnt
print("Resource collected! Total: ", resources)

View File

@@ -1,7 +1,7 @@
[gd_scene load_steps=3 format=3 uid="uid://b7wqd5owafn6g"]
[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"]
[node name="AbstractPredator" instance=ExtResource("1_4llks")]
[node name="AbstractPredator" unique_id=912624667 instance=ExtResource("1_4llks")]
script = ExtResource("2_rj1ok")

View File

@@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://dje58m1cj34gn"]
[gd_scene format=3 uid="uid://dje58m1cj34gn"]
[ext_resource type="Script" uid="uid://coetidfssb80w" path="res://shared/npc/spawn_manager_2d.gd" id="1_624qc"]
[node name="SpawnManager2d" type="Node"]
[node name="SpawnManager2d" type="Node" unique_id=176104644]
script = ExtResource("1_624qc")