From 48209c62efda256030adb157c81b58067924fe33 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 24 Mar 2026 19:40:21 +0100 Subject: [PATCH] level up --- Objects/battler.gd | 10 +++++----- Objects/dump.gd | 23 +++++++++++++++++++++++ Objects/dump.gd.uid | 1 + Objects/dump.tscn | 11 +++++++++++ Objects/floating_text.gd | 1 - Objects/plant.gd | 33 +++++++++++++++++++++++++++++++++ Objects/plant.gd.uid | 1 + Objects/plant.tscn | 19 +++++++++++++++++++ Objects/trash.gd | 22 ++++++++++++++++++++++ Objects/trash.gd.uid | 1 + Objects/trash.tscn | 14 ++++++++++++++ game.tscn | 20 +++++--------------- 12 files changed, 135 insertions(+), 21 deletions(-) create mode 100644 Objects/dump.gd create mode 100644 Objects/dump.gd.uid create mode 100644 Objects/dump.tscn create mode 100644 Objects/plant.gd create mode 100644 Objects/plant.gd.uid create mode 100644 Objects/plant.tscn create mode 100644 Objects/trash.gd create mode 100644 Objects/trash.gd.uid create mode 100644 Objects/trash.tscn diff --git a/Objects/battler.gd b/Objects/battler.gd index 1b8032e..2fb40b7 100644 --- a/Objects/battler.gd +++ b/Objects/battler.gd @@ -1,7 +1,6 @@ extends Node2D class_name Battler -@export var sprite_texture : Texture @export var battler_stats : BattlerStats @export_enum("Plant", "Pollution") var side = 0 @@ -9,10 +8,9 @@ class_name Battler @onready var floating_text_packed : PackedScene = load("res://Objects/floating_text.tscn") -var life : int = 1 : +var life : int = 1 : set(value): life = value - print(name, " life : ", life) if life <= 0: death() @@ -27,12 +25,14 @@ var _attack_ready : bool = false func _ready() -> void: - $Sprite2D.texture = sprite_texture set_side() set_battler_stats() _attack_ready = true + printerr(name) - +#Fonction virtuelle +func apply_progression() -> void: + pass func _process(_delta: float) -> void: if target: diff --git a/Objects/dump.gd b/Objects/dump.gd new file mode 100644 index 0000000..427dd6a --- /dev/null +++ b/Objects/dump.gd @@ -0,0 +1,23 @@ +extends Node2D +class_name Dump + +var level = 0 + +@export var spawn_trash_wait_time := 3.0 +@onready var trash_packed : PackedScene = load("res://Objects/trash.tscn") +var trash_battler : Battler + + +func _process(delta: float) -> void: + if trash_battler == null && $SpawnCooldown.is_stopped(): + $SpawnCooldown.start(spawn_trash_wait_time) + + +func spawn_trash() -> void: + level += 1 + trash_battler = trash_packed.instantiate() + trash_battler.level = level + add_child(trash_battler) + +func _on_spawn_cooldown_timeout() -> void: + spawn_trash() diff --git a/Objects/dump.gd.uid b/Objects/dump.gd.uid new file mode 100644 index 0000000..6cf505e --- /dev/null +++ b/Objects/dump.gd.uid @@ -0,0 +1 @@ +uid://c5dqyafu3h8xl diff --git a/Objects/dump.tscn b/Objects/dump.tscn new file mode 100644 index 0000000..dcb6539 --- /dev/null +++ b/Objects/dump.tscn @@ -0,0 +1,11 @@ +[gd_scene format=3 uid="uid://c6vyscw4nhckx"] + +[ext_resource type="Script" uid="uid://c5dqyafu3h8xl" path="res://Objects/dump.gd" id="1_yhoaw"] + +[node name="Dump" type="Node2D" unique_id=1287085357] +script = ExtResource("1_yhoaw") + +[node name="SpawnCooldown" type="Timer" parent="." unique_id=262648708] +one_shot = true + +[connection signal="timeout" from="SpawnCooldown" to="." method="_on_spawn_cooldown_timeout"] diff --git a/Objects/floating_text.gd b/Objects/floating_text.gd index def6932..bf59c20 100644 --- a/Objects/floating_text.gd +++ b/Objects/floating_text.gd @@ -3,7 +3,6 @@ var text : String = "-1" : set(value): text = str(value) $Label.text = text - print("Text :", $Label.text) func _ready() -> void: _animate() diff --git a/Objects/plant.gd b/Objects/plant.gd new file mode 100644 index 0000000..7923fae --- /dev/null +++ b/Objects/plant.gd @@ -0,0 +1,33 @@ +extends Battler +class_name Plant + +var level : int = 1: + set(value): + level = value + apply_progression() + + +@export var xp_curve : Curve +var xp_points = 0 : + set(value): + xp_points = value + print(xp_curve.sample(level)) + if xp_points >= xp_curve.sample(level): + level +=1 + + +func get_new_target() -> void: + super() + if not target: + return + target = target as Trash + target.trash_cleaned.connect(_on_Trash_trash_cleaned) + + +func apply_progression() -> void: + life += 10 + damage += 2 + + +func _on_Trash_trash_cleaned(xp_worth)-> void: + xp_points += xp_worth diff --git a/Objects/plant.gd.uid b/Objects/plant.gd.uid new file mode 100644 index 0000000..e3a0320 --- /dev/null +++ b/Objects/plant.gd.uid @@ -0,0 +1 @@ +uid://5l3g5qcjh5gy diff --git a/Objects/plant.tscn b/Objects/plant.tscn new file mode 100644 index 0000000..8b4a35d --- /dev/null +++ b/Objects/plant.tscn @@ -0,0 +1,19 @@ +[gd_scene format=3 uid="uid://d1ivgsboj1got"] + +[ext_resource type="PackedScene" uid="uid://cndfpjgyfttdr" path="res://Objects/Battler.tscn" id="1_qws6r"] +[ext_resource type="Script" uid="uid://5l3g5qcjh5gy" path="res://Objects/plant.gd" id="2_8p83i"] +[ext_resource type="Texture2D" uid="uid://cs0k1ofdlayvr" path="res://Assets/Flowers/Flower 2/Flower 2 - TEAL.png" id="2_ms33i"] +[ext_resource type="Resource" uid="uid://te1aq7i3mahk" path="res://Resources/plant_stats.tres" id="3_8p83i"] + +[sub_resource type="Curve" id="Curve_ms33i"] +_limits = [0.0, 100.0, 0.0, 10.0] +_data = [Vector2(0, 0), 0.0, 10.0, 0, 1, Vector2(10, 100), 10.0, 0.0, 1, 0] +point_count = 2 + +[node name="Plant" unique_id=1265041863 instance=ExtResource("1_qws6r")] +script = ExtResource("2_8p83i") +xp_curve = SubResource("Curve_ms33i") +battler_stats = ExtResource("3_8p83i") + +[node name="Sprite2D" parent="." index="0" unique_id=763052965] +texture = ExtResource("2_ms33i") diff --git a/Objects/trash.gd b/Objects/trash.gd new file mode 100644 index 0000000..a9807dc --- /dev/null +++ b/Objects/trash.gd @@ -0,0 +1,22 @@ +extends Battler +class_name Trash + +signal trash_cleaned + + +var level : int = 1 +var xp_worth = 10 + +func _ready() -> void: + super() + apply_progression() + +func apply_progression() -> void: + life *= level + damage *= level + armor *= level + + +func death() -> void: + super() + trash_cleaned.emit(xp_worth) diff --git a/Objects/trash.gd.uid b/Objects/trash.gd.uid new file mode 100644 index 0000000..cfa94de --- /dev/null +++ b/Objects/trash.gd.uid @@ -0,0 +1 @@ +uid://5fptimht81p1 diff --git a/Objects/trash.tscn b/Objects/trash.tscn new file mode 100644 index 0000000..795a4a0 --- /dev/null +++ b/Objects/trash.tscn @@ -0,0 +1,14 @@ +[gd_scene format=3 uid="uid://3h0q7h8pdrt4"] + +[ext_resource type="PackedScene" uid="uid://cndfpjgyfttdr" path="res://Objects/Battler.tscn" id="1_6dsr2"] +[ext_resource type="Script" uid="uid://5fptimht81p1" path="res://Objects/trash.gd" id="2_6dsr2"] +[ext_resource type="Texture2D" uid="uid://cdhk55d5d05di" path="res://Assets/Trashes/recycling 2.png" id="2_ouqvo"] +[ext_resource type="Resource" uid="uid://7rv28rbuxt2p" path="res://Resources/trash_stats.tres" id="3_tplsk"] + +[node name="Trash" unique_id=1265041863 instance=ExtResource("1_6dsr2")] +script = ExtResource("2_6dsr2") +battler_stats = ExtResource("3_tplsk") +side = 1 + +[node name="Sprite2D" parent="." index="0" unique_id=763052965] +texture = ExtResource("2_ouqvo") diff --git a/game.tscn b/game.tscn index 62ec6bd..b060d31 100644 --- a/game.tscn +++ b/game.tscn @@ -1,27 +1,17 @@ [gd_scene format=3 uid="uid://vkh2dbrct7vh"] -[ext_resource type="PackedScene" uid="uid://cndfpjgyfttdr" path="res://Objects/Battler.tscn" id="1_feb5d"] -[ext_resource type="Texture2D" uid="uid://drwi73l0d04vj" path="res://Assets/Flowers/Flower Pot 5/Flower Pot 5 - LILAC.png" id="2_ryrav"] -[ext_resource type="Resource" uid="uid://te1aq7i3mahk" path="res://Resources/plant_stats.tres" id="3_7jktm"] -[ext_resource type="Texture2D" uid="uid://cdhk55d5d05di" path="res://Assets/Trashes/recycling 2.png" id="3_feb5d"] -[ext_resource type="Resource" uid="uid://7rv28rbuxt2p" path="res://Resources/trash_stats.tres" id="5_ryrav"] +[ext_resource type="PackedScene" uid="uid://d1ivgsboj1got" path="res://Objects/plant.tscn" id="1_feb5d"] +[ext_resource type="PackedScene" uid="uid://c6vyscw4nhckx" path="res://Objects/dump.tscn" id="4_fc0e3"] [node name="Game" type="Node2D" unique_id=2069582450] [node name="Garden" type="Node2D" parent="." unique_id=491593255] +position = Vector2(188, 171) [node name="Plant" parent="Garden" unique_id=1265041863 instance=ExtResource("1_feb5d")] -position = Vector2(189, 183) -sprite_texture = ExtResource("2_ryrav") -battler_stats = ExtResource("3_7jktm") -[node name="Dump" type="Node2D" parent="." unique_id=608611995] - -[node name="Trash" parent="Dump" unique_id=1865311551 instance=ExtResource("1_feb5d")] -position = Vector2(330, 181) -sprite_texture = ExtResource("3_feb5d") -battler_stats = ExtResource("5_ryrav") -side = 1 +[node name="Dump" parent="." unique_id=1287085357 instance=ExtResource("4_fc0e3")] +position = Vector2(341, 175) [node name="Camera2D" type="Camera2D" parent="." unique_id=1468251961] position = Vector2(259, 155)