#18 ajout de la classe UndergroundLoot et aparition de loot par jour

This commit is contained in:
Zacharie Guet 2025-08-20 10:25:50 +02:00
parent 9de869b7af
commit 3021567ecb
11 changed files with 182 additions and 23 deletions

View File

@ -2,8 +2,8 @@ extends Resource
class_name TerrainData class_name TerrainData
const TERRAIN_IMAGE_GAME_FACTOR = 50 const TERRAIN_IMAGE_GAME_FACTOR = 50
const DEFAULT_CONTAMINATION_CENTRAL_ZONE_MAX_SIZE = 500 const DEFAULT_CONTAMINATION_CENTRAL_ZONE_MAX_SIZE = 300
const DEFAULT_CONTAMINATION_CENTRAL_ZONE_MIN_SIZE = 100 const DEFAULT_CONTAMINATION_CENTRAL_ZONE_MIN_SIZE = 50
signal terrain_updated signal terrain_updated

View File

@ -4,7 +4,7 @@ class_name Shovel
func can_use(player : Player) -> bool: func can_use(player : Player) -> bool:
var areas = player.action_area.get_overlapping_areas() var areas = player.action_area.get_overlapping_areas()
for area in areas : for area in areas :
if area is Plant: if area is Plant or area is UndergroundLoot:
return true return true
return false return false
@ -16,4 +16,6 @@ func use(player : Player) -> bool:
for area in areas : for area in areas :
if area is Plant: if area is Plant:
area.harvest() area.harvest()
if area is UndergroundLoot:
area.dig()
return true return true

View File

@ -12,7 +12,7 @@ const SPRITE_SCENE : PackedScene = preload("res://entities/plants/plant_sprite.t
enum State {PLANTED, GROWING, MATURE} enum State {PLANTED, GROWING, MATURE}
@export var plant_type: PlantType @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 var state: State = State.PLANTED: set = change_state
@export var day: int = 0 : set = set_day @export var day: int = 0 : set = set_day

View File

@ -9,7 +9,7 @@ var planet : Planet # mis à jour par la classe Planet
@onready var inventory : Inventory = Inventory.new() @onready var inventory : Inventory = Inventory.new()
var max_energy : int = 5 var max_energy : int = 3
var controlling_player : bool = true : var controlling_player : bool = true :
set(v): set(v):

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="121.41377mm"
height="49.165478mm"
viewBox="0 0 121.41377 49.165478"
version="1.1"
id="svg1"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview1"
pagecolor="#505050"
bordercolor="#ffffff"
borderopacity="1"
inkscape:showpageshadow="0"
inkscape:pageopacity="0"
inkscape:pagecheckerboard="1"
inkscape:deskcolor="#505050"
inkscape:document-units="mm" />
<defs
id="defs1" />
<g
inkscape:label="Calque 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-77.923929,-55.520125)">
<path
id="path1"
style="fill:#ffffff;fill-opacity:1;stroke-width:0.264583;stroke-linecap:square"
d="M 141.47612,55.520125 A 35.11824,35.11824 0 0 0 107.53969,81.850818 26.422297,26.422297 0 0 0 104.01691,81.607939 26.422297,26.422297 0 0 0 77.923926,104.6856 H 199.239 a 28.094591,28.094591 0 0 0 0.0987,-1.00304 28.094591,28.094591 0 0 0 -26.09504,-28.015344 35.11824,35.11824 0 0 0 -31.76654,-20.147091 z" />
<path
id="path2"
style="fill:#c9c9c9;fill-opacity:1;stroke-width:0.264583;stroke-linecap:square"
d="M 149.00176,77.594747 A 22.241554,22.241554 0 0 0 127.96997,92.741626 22.241554,22.241554 0 0 0 117.22799,89.969702 22.241554,22.241554 0 0 0 96.380164,104.6856 h 95.746606 a 22.241554,22.241554 0 0 0 -21.05091,-15.385108 22.241554,22.241554 0 0 0 -2.3983,0.171566 22.241554,22.241554 0 0 0 -19.6758,-11.877311 z" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -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

View File

@ -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()

View File

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

View File

@ -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")

View File

@ -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://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"] [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="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://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="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"] [sub_resource type="Resource" id="Resource_qt76e"]
script = ExtResource("5_qw60f") script = ExtResource("5_qw60f")
@ -32,23 +33,31 @@ description = ""
icon = ExtResource("6_gd4vy") icon = ExtResource("6_gd4vy")
metadata/_custom_type_script = "uid://jom8ulyopso" metadata/_custom_type_script = "uid://jom8ulyopso"
[sub_resource type="AtlasTexture" id="AtlasTexture_ffarr"] [sub_resource type="AtlasTexture" id="AtlasTexture_qt76e"]
atlas = ExtResource("6_tw3kd") atlas = ExtResource("6_tw3kd")
region = Rect2(1140, 345, 141, 128) region = Rect2(1140, 345, 141, 128)
[sub_resource type="Resource" id="Resource_qwhpj"] [sub_resource type="Resource" id="Resource_sq7yr"]
script = ExtResource("9_gd4vy") script = ExtResource("9_gd4vy")
plant_type = ExtResource("9_qw60f") plant_type = ExtResource("9_qw60f")
name = "Chardi" name = "Chardi"
description = "This plant can grow without water, and reduce contamination around when it becomes mature." 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" metadata/_custom_type_script = "uid://bypjcvlc15gsm"
[sub_resource type="AtlasTexture" id="AtlasTexture_sri3b"] [sub_resource type="AtlasTexture" id="AtlasTexture_sri3b"]
atlas = ExtResource("6_tw3kd") atlas = ExtResource("6_tw3kd")
region = Rect2(1697, 331, 125, 158) region = Rect2(1697, 331, 125, 158)
[sub_resource type="Resource" id="Resource_sq7yr"] [sub_resource type="Resource" id="Resource_50g4q"]
script = ExtResource("9_gd4vy") script = ExtResource("9_gd4vy")
plant_type = ExtResource("11_eji0w") plant_type = ExtResource("11_eji0w")
name = "Maias" name = "Maias"
@ -79,19 +88,8 @@ script = ExtResource("3_bf3um")
item = SubResource("Resource_eji0w") item = SubResource("Resource_eji0w")
metadata/_custom_type_script = "uid://dedg615xudpoq" 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")] [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") import_entities_from_node = NodePath("../Entities")
[node name="Camera" parent="." node_paths=PackedStringArray("following") instance=ExtResource("3_vvh5c")] [node name="Camera" parent="." node_paths=PackedStringArray("following") instance=ExtResource("3_vvh5c")]

View File

@ -5,6 +5,13 @@ signal planet_updated(planet : Planet)
const PLANET_TEXTURE_SCALE : float = 5.0 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 background_texture : Texture2D
@export var contamination_material : ShaderMaterial @export var contamination_material : ShaderMaterial
@ -23,6 +30,7 @@ var day : int = 0 :
func _ready(): func _ready():
planet_updated.emit(self) planet_updated.emit(self)
generate_loot(first_loot_number)
#region ------------------ Generation ------------------ #region ------------------ Generation ------------------
@ -30,7 +38,7 @@ func add_entity(e : Node2D, container : Node2D = entityContainer):
if e.get_parent(): if e.get_parent():
e.get_parent().remove_child(e) e.get_parent().remove_child(e)
if e is Player: if "planet" in e:
e.planet = self e.planet = self
container.add_child(e) container.add_child(e)
@ -105,10 +113,25 @@ func is_there_contamination(point : Vector2) -> bool:
return terrainData.get_contamination(point) < 0.5 return terrainData.get_contamination(point) < 0.5
func pass_day(): func pass_day():
for e : Node2D in entityContainer.get_children(): for e : Node2D in entityContainer.get_children():
if e.has_method("pass_day"): if e.has_method("pass_day"):
e.pass_day() e.pass_day()
day += 1 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 #endregion