diff --git a/common/game_data/scripts/terrain_data.gd b/common/game_data/scripts/terrain_data.gd index 5173086..805d54d 100644 --- a/common/game_data/scripts/terrain_data.gd +++ b/common/game_data/scripts/terrain_data.gd @@ -2,8 +2,8 @@ extends Resource class_name TerrainData const TERRAIN_IMAGE_GAME_FACTOR = 50 -const DEFAULT_CONTAMINATION_CENTRAL_ZONE_MAX_SIZE = 500 -const DEFAULT_CONTAMINATION_CENTRAL_ZONE_MIN_SIZE = 100 +const DEFAULT_CONTAMINATION_CENTRAL_ZONE_MAX_SIZE = 300 +const DEFAULT_CONTAMINATION_CENTRAL_ZONE_MIN_SIZE = 50 signal terrain_updated diff --git a/common/inventory/scripts/items/shovel.gd b/common/inventory/scripts/items/shovel.gd index 56c7abb..a8afa9d 100644 --- a/common/inventory/scripts/items/shovel.gd +++ b/common/inventory/scripts/items/shovel.gd @@ -4,7 +4,7 @@ class_name Shovel func can_use(player : Player) -> bool: var areas = player.action_area.get_overlapping_areas() for area in areas : - if area is Plant: + if area is Plant or area is UndergroundLoot: return true return false @@ -16,4 +16,6 @@ func use(player : Player) -> bool: for area in areas : if area is Plant: area.harvest() + if area is UndergroundLoot: + area.dig() return true \ No newline at end of file diff --git a/entities/plants/scripts/plant.gd b/entities/plants/scripts/plant.gd index 44e1555..8411593 100644 --- a/entities/plants/scripts/plant.gd +++ b/entities/plants/scripts/plant.gd @@ -12,7 +12,7 @@ const SPRITE_SCENE : PackedScene = preload("res://entities/plants/plant_sprite.t enum State {PLANTED, GROWING, MATURE} @export var plant_type: PlantType -@export var planet: Planet +var planet: Planet # mis à jour par la classe Planet var state: State = State.PLANTED: set = change_state @export var day: int = 0 : set = set_day diff --git a/entities/player/scripts/player.gd b/entities/player/scripts/player.gd index 792c776..3ce55f5 100644 --- a/entities/player/scripts/player.gd +++ b/entities/player/scripts/player.gd @@ -9,7 +9,7 @@ var planet : Planet # mis à jour par la classe Planet @onready var inventory : Inventory = Inventory.new() -var max_energy : int = 5 +var max_energy : int = 3 var controlling_player : bool = true : set(v): diff --git a/entities/underground_loot/assets/sprites/underground_loot.svg b/entities/underground_loot/assets/sprites/underground_loot.svg new file mode 100644 index 0000000..0be5a5e --- /dev/null +++ b/entities/underground_loot/assets/sprites/underground_loot.svg @@ -0,0 +1,40 @@ + + + + + + + + + + + diff --git a/entities/underground_loot/assets/sprites/underground_loot.svg.import b/entities/underground_loot/assets/sprites/underground_loot.svg.import new file mode 100644 index 0000000..068af1b --- /dev/null +++ b/entities/underground_loot/assets/sprites/underground_loot.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://bu26h0iqutnky" +path="res://.godot/imported/underground_loot.svg-94513f7cc11df7cda1992e530bcff786.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://entities/underground_loot/assets/sprites/underground_loot.svg" +dest_files=["res://.godot/imported/underground_loot.svg-94513f7cc11df7cda1992e530bcff786.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/entities/underground_loot/scripts/underground_loot.gd b/entities/underground_loot/scripts/underground_loot.gd new file mode 100644 index 0000000..ee05360 --- /dev/null +++ b/entities/underground_loot/scripts/underground_loot.gd @@ -0,0 +1,48 @@ +extends Area2D +class_name UndergroundLoot + +const AREA_WIDTH = 10 +const LOOTED_ITEM_RANDOM_RANGE = 100 + +const SPRITE_SCENE : PackedScene = preload("res://entities/underground_loot/underground_loot_sprite.tscn") + +@export var loot : Array[Item] +var planet : Planet # mis à jour par la classe Planet + +@onready var sprite_object: Node2D = generate_sprite() +@onready var collision_shape: CollisionShape2D = generate_collision_shape() + +func _init(_planet = null): + planet = _planet + +func generate_sprite() -> Node2D: + var object = SPRITE_SCENE.instantiate() + + add_child(object) + + return object + +func generate_collision_shape() -> CollisionShape2D: + var collision = CollisionShape2D.new() + var shape = CircleShape2D.new() + shape.radius = AREA_WIDTH + + collision.shape = shape + add_child(collision) + + return collision + +func dig(): + for item in loot: + var item_object = planet.drop_item(item, global_position) + var tween : Tween = get_tree().create_tween() + tween.tween_property( + item_object, + "position", + Vector2( + item_object.position.x + randi()%LOOTED_ITEM_RANDOM_RANGE, + item_object.position.y + randi()%LOOTED_ITEM_RANDOM_RANGE + ), + 0.2 + ) + queue_free() diff --git a/entities/underground_loot/scripts/underground_loot.gd.uid b/entities/underground_loot/scripts/underground_loot.gd.uid new file mode 100644 index 0000000..b566683 --- /dev/null +++ b/entities/underground_loot/scripts/underground_loot.gd.uid @@ -0,0 +1 @@ +uid://dfd2hh12155lo diff --git a/entities/underground_loot/underground_loot_sprite.tscn b/entities/underground_loot/underground_loot_sprite.tscn new file mode 100644 index 0000000..d6002af --- /dev/null +++ b/entities/underground_loot/underground_loot_sprite.tscn @@ -0,0 +1,10 @@ +[gd_scene load_steps=2 format=3 uid="uid://dxjud7bti0na0"] + +[ext_resource type="Texture2D" uid="uid://bu26h0iqutnky" path="res://entities/underground_loot/assets/sprites/underground_loot.svg" id="1_t1xxm"] + +[node name="UndergroundLootSprites" type="Node2D"] + +[node name="Sprite2D" type="Sprite2D" parent="."] +modulate = Color(0.286275, 0.219608, 0.313726, 1) +scale = Vector2(0.0806452, 0.0806452) +texture = ExtResource("1_t1xxm") diff --git a/root.tscn b/root.tscn index 5017ae5..fb95eee 100644 --- a/root.tscn +++ b/root.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=20 format=3 uid="uid://c5bruelvqbm1k"] +[gd_scene load_steps=22 format=3 uid="uid://c5bruelvqbm1k"] [ext_resource type="PackedScene" uid="uid://12nak7amd1uq" path="res://gui/root_gui.tscn" id="1_jnlp7"] [ext_resource type="PackedScene" uid="uid://tsi5j1uxppa4" path="res://stages/terrain/planet/planet.tscn" id="1_pyidc"] @@ -13,6 +13,7 @@ [ext_resource type="Script" uid="uid://bypjcvlc15gsm" path="res://common/inventory/scripts/items/seed.gd" id="9_gd4vy"] [ext_resource type="Resource" uid="uid://b04vho33bl52b" path="res://entities/plants/resources/plants/default.tres" id="9_qw60f"] [ext_resource type="Resource" uid="uid://dsctivn1vrem2" path="res://entities/plants/resources/plants/maias.tres" id="11_eji0w"] +[ext_resource type="Script" uid="uid://bq7admu4ahs5r" path="res://common/inventory/scripts/item.gd" id="12_sq7yr"] [sub_resource type="Resource" id="Resource_qt76e"] script = ExtResource("5_qw60f") @@ -32,23 +33,31 @@ description = "" icon = ExtResource("6_gd4vy") metadata/_custom_type_script = "uid://jom8ulyopso" -[sub_resource type="AtlasTexture" id="AtlasTexture_ffarr"] +[sub_resource type="AtlasTexture" id="AtlasTexture_qt76e"] atlas = ExtResource("6_tw3kd") region = Rect2(1140, 345, 141, 128) -[sub_resource type="Resource" id="Resource_qwhpj"] +[sub_resource type="Resource" id="Resource_sq7yr"] script = ExtResource("9_gd4vy") plant_type = ExtResource("9_qw60f") name = "Chardi" description = "This plant can grow without water, and reduce contamination around when it becomes mature." -icon = SubResource("AtlasTexture_ffarr") +icon = SubResource("AtlasTexture_qt76e") +metadata/_custom_type_script = "uid://bypjcvlc15gsm" + +[sub_resource type="Resource" id="Resource_blcw0"] +script = ExtResource("9_gd4vy") +plant_type = ExtResource("9_qw60f") +name = "Chardi" +description = "This plant can grow without water, and reduce contamination around when it becomes mature." +icon = SubResource("AtlasTexture_qt76e") metadata/_custom_type_script = "uid://bypjcvlc15gsm" [sub_resource type="AtlasTexture" id="AtlasTexture_sri3b"] atlas = ExtResource("6_tw3kd") region = Rect2(1697, 331, 125, 158) -[sub_resource type="Resource" id="Resource_sq7yr"] +[sub_resource type="Resource" id="Resource_50g4q"] script = ExtResource("9_gd4vy") plant_type = ExtResource("11_eji0w") name = "Maias" @@ -79,19 +88,8 @@ script = ExtResource("3_bf3um") item = SubResource("Resource_eji0w") metadata/_custom_type_script = "uid://dedg615xudpoq" -[node name="ItemObject3" type="Area2D" parent="Entities"] -position = Vector2(228, -103) -script = ExtResource("3_bf3um") -item = SubResource("Resource_qwhpj") -metadata/_custom_type_script = "uid://dedg615xudpoq" - -[node name="ItemObject4" type="Area2D" parent="Entities"] -position = Vector2(489, -84) -script = ExtResource("3_bf3um") -item = SubResource("Resource_sq7yr") -metadata/_custom_type_script = "uid://dedg615xudpoq" - [node name="Planet" parent="." node_paths=PackedStringArray("import_entities_from_node") instance=ExtResource("1_pyidc")] +loot_items = Array[ExtResource("12_sq7yr")]([SubResource("Resource_sq7yr"), SubResource("Resource_blcw0"), SubResource("Resource_50g4q")]) import_entities_from_node = NodePath("../Entities") [node name="Camera" parent="." node_paths=PackedStringArray("following") instance=ExtResource("3_vvh5c")] diff --git a/stages/terrain/planet/scripts/planet.gd b/stages/terrain/planet/scripts/planet.gd index 41c2879..533d5ee 100644 --- a/stages/terrain/planet/scripts/planet.gd +++ b/stages/terrain/planet/scripts/planet.gd @@ -5,6 +5,13 @@ signal planet_updated(planet : Planet) const PLANET_TEXTURE_SCALE : float = 5.0 +@export_group("Loot") +@export var first_loot_number : int = 3 +@export var loot_number : Array[int] = [0,1,2] +@export var loot_item_number : Array[int] = [1,2] +@export var loot_items : Array[Item] = [] + +@export_group("Textures") @export var background_texture : Texture2D @export var contamination_material : ShaderMaterial @@ -23,6 +30,7 @@ var day : int = 0 : func _ready(): planet_updated.emit(self) + generate_loot(first_loot_number) #region ------------------ Generation ------------------ @@ -30,7 +38,7 @@ func add_entity(e : Node2D, container : Node2D = entityContainer): if e.get_parent(): e.get_parent().remove_child(e) - if e is Player: + if "planet" in e: e.planet = self container.add_child(e) @@ -105,10 +113,25 @@ func is_there_contamination(point : Vector2) -> bool: return terrainData.get_contamination(point) < 0.5 func pass_day(): + for e : Node2D in entityContainer.get_children(): if e.has_method("pass_day"): e.pass_day() day += 1 + generate_loot() + +func generate_loot(number : int = loot_number.pick_random()): + for i in range(number): + var loot = UndergroundLoot.new(self) + for j in range(loot_item_number.pick_random()): + loot.loot.append(loot_items.pick_random()) + + add_entity(loot) + + loot.global_position = Vector2( + randf_range(0, terrainData.terrainSize.x), + randf_range(0, terrainData.terrainSize.y) + ) #endregion