#58 ajout d'un item package servant à déployer des machines

This commit is contained in:
Zacharie Guet 2025-09-05 17:01:59 +02:00
parent 165a4d129b
commit 18b48f5320
29 changed files with 149 additions and 62 deletions

View File

@ -62,16 +62,16 @@ func impact_contamination(position : Vector2, impact_radius : int, to_value : fl
Color(1., 1., 1., to_value) Color(1., 1., 1., to_value)
) )
func get_contamination(point : Vector2) -> float: func is_in_image(pixel_point : Vector2, image : Image):
var pixel_point : Vector2 = ( return (
Vector2(point) / float(TERRAIN_IMAGE_GAME_FACTOR)
- Vector2.ONE / 2
)
if (
pixel_point.x > 0 pixel_point.x > 0
and pixel_point.y > 0 and pixel_point.y > 0
and pixel_point.x < contamination.get_width() and pixel_point.x < image.get_width()
and pixel_point.y < contamination.get_height()): and pixel_point.y < image.get_height())
func get_contamination(point : Vector2) -> float:
var pixel_point : Vector2 = get_pixel_point(point)
if (is_in_image(pixel_point, contamination)):
return contamination.get_pixel( return contamination.get_pixel(
int(round(pixel_point.x)), int(round(pixel_point.x)),
int(round(pixel_point.y)) int(round(pixel_point.y))
@ -80,3 +80,9 @@ func get_contamination(point : Vector2) -> float:
func get_decontamination_coverage() -> float: func get_decontamination_coverage() -> float:
return ImageTools.get_color_coverage(contamination) return ImageTools.get_color_coverage(contamination)
func get_pixel_point(point : Vector2) -> Vector2:
return (
Vector2(point) / float(TERRAIN_IMAGE_GAME_FACTOR)
- Vector2.ONE / 2
)

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-package"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M12 3l8 4.5l0 9l-8 4.5l-8 -4.5l0 -9l8 -4.5" /><path d="M12 12l8 -4.5" /><path d="M12 12l0 9" /><path d="M12 12l-8 -4.5" /><path d="M16 5.25l-8 4.5" /></svg>

After

Width:  |  Height:  |  Size: 468 B

View File

@ -0,0 +1,37 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://0xg54agef5gh"
path="res://.godot/imported/package.svg-a9602fd424cfb199cd9405d02663e7df.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://common/inventory/assets/icons/package.svg"
dest_files=["res://.godot/imported/package.svg-a9602fd424cfb199cd9405d02663e7df.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,15 @@
[gd_resource type="Resource" script_class="Package" load_steps=4 format=3 uid="uid://bya8sm6rm6747"]
[ext_resource type="Texture2D" uid="uid://0xg54agef5gh" path="res://common/inventory/assets/icons/package.svg" id="1_lhhdv"]
[ext_resource type="Script" uid="uid://b6kubqgq0k7vj" path="res://common/inventory/scripts/items/package.gd" id="1_x02bb"]
[ext_resource type="PackedScene" uid="uid://bkwh1ntvgkkrt" path="res://entities/interactables/machines/compost/compost.tscn" id="2_uulso"]
[resource]
script = ExtResource("1_x02bb")
scene = ExtResource("2_uulso")
name = "Compost"
description = "Compost"
icon = ExtResource("1_lhhdv")
use_zone_radius = 5
use_energy = 1
metadata/_custom_type_script = "uid://b6kubqgq0k7vj"

View File

@ -0,0 +1,22 @@
extends Item
class_name Package
@export var scene: PackedScene
func _init(_scene : PackedScene = null):
scene = _scene
func use_text() -> String:
return "Build " + name
func is_one_time_use():
return true
func can_use(player : Player, zone : Area2D) -> bool:
print(zone.global_position)
return player.planet.is_in_zone(zone.global_position)
func use(player : Player, zone : Area2D) -> bool:
print(zone.global_position)
player.planet.instantiate_entity(scene, zone.global_position)
return true

View File

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

View File

@ -1,4 +1,3 @@
@tool
extends Interactable extends Interactable
class_name ItemObject class_name ItemObject
@ -20,6 +19,9 @@ func _init(_item = null):
func _ready(): func _ready():
generate_collision(ITEM_AREA_WIDTH) generate_collision(ITEM_AREA_WIDTH)
if item and object_sprite:
object_sprite.apply_texture_to_sprite(item.icon, ITEM_SPRITE_SIZE)
func inspected_text(): func inspected_text():
return item.name + (" Seed" if item is Seed else "") return item.name + (" Seed" if item is Seed else "")

View File

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -3,15 +3,15 @@
importer="texture" importer="texture"
type="CompressedTexture2D" type="CompressedTexture2D"
uid="uid://f2rte5jc0psp" uid="uid://f2rte5jc0psp"
path="res://.godot/imported/compost.svg-503fc2423ba701b15edd51da5ab01164.ctex" path="res://.godot/imported/compost.svg-f43ad0f7b40754d19aa7d5ea88e80cb8.ctex"
metadata={ metadata={
"vram_texture": false "vram_texture": false
} }
[deps] [deps]
source_file="res://entities/interactables/compost/assets/sprites/compost.svg" source_file="res://entities/interactables/machines/compost/assets/sprites/compost.svg"
dest_files=["res://.godot/imported/compost.svg-503fc2423ba701b15edd51da5ab01164.ctex"] dest_files=["res://.godot/imported/compost.svg-f43ad0f7b40754d19aa7d5ea88e80cb8.ctex"]
[params] [params]

View File

@ -1,7 +1,7 @@
[gd_scene load_steps=10 format=3 uid="uid://bkwh1ntvgkkrt"] [gd_scene load_steps=10 format=3 uid="uid://bkwh1ntvgkkrt"]
[ext_resource type="Script" uid="uid://dw6jgsasb2fe1" path="res://entities/interactables/compost/scripts/compost.gd" id="1_1758a"] [ext_resource type="Script" uid="uid://dw6jgsasb2fe1" path="res://entities/interactables/machines/compost/scripts/compost.gd" id="1_c0pig"]
[ext_resource type="Texture2D" uid="uid://f2rte5jc0psp" path="res://entities/interactables/compost/assets/sprites/compost.svg" id="2_r6435"] [ext_resource type="Texture2D" uid="uid://f2rte5jc0psp" path="res://entities/interactables/machines/compost/assets/sprites/compost.svg" id="2_r6435"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_etofw"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_etofw"]
bg_color = Color(0.260098, 0.11665, 0.0419712, 0.231373) bg_color = Color(0.260098, 0.11665, 0.0419712, 0.231373)
@ -17,9 +17,6 @@ corner_radius_top_right = 5
corner_radius_bottom_right = 5 corner_radius_bottom_right = 5
corner_radius_bottom_left = 5 corner_radius_bottom_left = 5
[sub_resource type="RectangleShape2D" id="RectangleShape2D_coj8m"]
size = Vector2(77, 92)
[sub_resource type="Animation" id="Animation_r6435"] [sub_resource type="Animation" id="Animation_r6435"]
length = 0.001 length = 0.001
tracks/0/type = "value" tracks/0/type = "value"
@ -98,8 +95,11 @@ _data = {
&"fill": SubResource("Animation_etofw") &"fill": SubResource("Animation_etofw")
} }
[sub_resource type="RectangleShape2D" id="RectangleShape2D_akkx7"]
size = Vector2(66, 84)
[node name="Compost" type="Area2D"] [node name="Compost" type="Area2D"]
script = ExtResource("1_1758a") script = ExtResource("1_c0pig")
[node name="Compost" type="Sprite2D" parent="."] [node name="Compost" type="Sprite2D" parent="."]
modulate = Color(0.615686, 0.501961, 0.270588, 1) modulate = Color(0.615686, 0.501961, 0.270588, 1)
@ -114,16 +114,13 @@ offset_right = 62.0
offset_bottom = 120.0 offset_bottom = 120.0
theme_override_styles/background = SubResource("StyleBoxFlat_etofw") theme_override_styles/background = SubResource("StyleBoxFlat_etofw")
theme_override_styles/fill = SubResource("StyleBoxFlat_3ao1n") theme_override_styles/fill = SubResource("StyleBoxFlat_3ao1n")
value = 20.0
fill_mode = 3 fill_mode = 3
show_percentage = false show_percentage = false
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
visible = false
position = Vector2(-0.5, 2)
shape = SubResource("RectangleShape2D_coj8m")
[node name="AnimationPlayer" type="AnimationPlayer" parent="."] [node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = { libraries = {
&"": SubResource("AnimationLibrary_etofw") &"": SubResource("AnimationLibrary_etofw")
} }
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_akkx7")

View File

@ -1,10 +1,8 @@
extends Interactable extends Machine
class_name Compost class_name Compost
var value_per_seed : float = 0.5
@export var value_per_seed : float = 0.5 var fill_value : float = 0.
@onready var fill_value : float = 0.
func _process(_delta): func _process(_delta):
%ProgressBar.value = lerp(%ProgressBar.value, fill_value * 100, 0.5) %ProgressBar.value = lerp(%ProgressBar.value, fill_value * 100, 0.5)
@ -13,7 +11,7 @@ func inspected_text():
return "Compost" return "Compost"
func interact_text(): func interact_text():
return "Put a seed" return "Put a seed ("+str(roundi((1-fill_value)/value_per_seed))+" left)"
func can_interact(p : Player) -> bool: func can_interact(p : Player) -> bool:
return p.inventory.get_item() and p.inventory.get_item() is Seed return p.inventory.get_item() and p.inventory.get_item() is Seed

View File

@ -3,12 +3,12 @@
importer="wav" importer="wav"
type="AudioStreamWAV" type="AudioStreamWAV"
uid="uid://cjo6ea86rfqbe" uid="uid://cjo6ea86rfqbe"
path="res://.godot/imported/compost_level_up.wav-d796efae9b651b45ecdda95fd157999a.sample" path="res://.godot/imported/compost_level_up.wav-18f25f0720265f21705081af070ef8cd.sample"
[deps] [deps]
source_file="res://entities/interactables/compost/sounds/compost_level_up.wav" source_file="res://entities/interactables/machines/compost/sounds/compost_level_up.wav"
dest_files=["res://.godot/imported/compost_level_up.wav-d796efae9b651b45ecdda95fd157999a.sample"] dest_files=["res://.godot/imported/compost_level_up.wav-18f25f0720265f21705081af070ef8cd.sample"]
[params] [params]

View File

@ -3,15 +3,15 @@
importer="texture" importer="texture"
type="CompressedTexture2D" type="CompressedTexture2D"
uid="uid://c82ljr3in67am" uid="uid://c82ljr3in67am"
path="res://.godot/imported/recharge_station.svg-e388da7bbc5335a093731cd3d5c6eb67.ctex" path="res://.godot/imported/recharge_station.svg-b4dbe96f287bff2995b6160acd3f32ff.ctex"
metadata={ metadata={
"vram_texture": false "vram_texture": false
} }
[deps] [deps]
source_file="res://entities/interactables/recharge_station/assets/sprites/recharge_station.svg" source_file="res://entities/interactables/machines/recharge_station/assets/sprites/recharge_station.svg"
dest_files=["res://.godot/imported/recharge_station.svg-e388da7bbc5335a093731cd3d5c6eb67.ctex"] dest_files=["res://.godot/imported/recharge_station.svg-b4dbe96f287bff2995b6160acd3f32ff.ctex"]
[params] [params]

View File

@ -1,7 +1,7 @@
[gd_scene load_steps=4 format=3 uid="uid://d324mlmgls4fs"] [gd_scene load_steps=4 format=3 uid="uid://d324mlmgls4fs"]
[ext_resource type="Script" uid="uid://bsrn3gd2a532q" path="res://entities/interactables/recharge_station/scripts/recharge_station.gd" id="1_2ffjo"] [ext_resource type="Script" uid="uid://bsrn3gd2a532q" path="res://entities/interactables/machines/recharge_station/scripts/recharge_station.gd" id="1_2ffjo"]
[ext_resource type="Texture2D" uid="uid://c82ljr3in67am" path="res://entities/interactables/recharge_station/assets/sprites/recharge_station.svg" id="2_58ax0"] [ext_resource type="Texture2D" uid="uid://c82ljr3in67am" path="res://entities/interactables/machines/recharge_station/assets/sprites/recharge_station.svg" id="2_58ax0"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_bjhct"] [sub_resource type="CapsuleShape2D" id="CapsuleShape2D_bjhct"]
radius = 15.0 radius = 15.0

View File

@ -1,4 +1,4 @@
extends Interactable extends Machine
class_name RechargeStation class_name RechargeStation
var planet : Planet # mis à jour par la classe Planet var planet : Planet # mis à jour par la classe Planet

View File

@ -0,0 +1,2 @@
extends Interactable
class_name Machine

View File

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

View File

@ -6,11 +6,14 @@ var available : bool = true
func can_interact(_p : Player) -> bool: func can_interact(_p : Player) -> bool:
return true return true
func interaction_cost(_p : Player) -> int:
return 0
func interact(_p : Player) -> bool: func interact(_p : Player) -> bool:
printerr("Interact function called on abstract Interactable class") printerr("Interact function called on abstract Interactable class")
return false return false
func generate_collision(area_width : float): func generate_collision(area_width : float) -> CollisionShape2D:
var collision = CollisionShape2D.new() var collision = CollisionShape2D.new()
var collision_shape = CircleShape2D.new() var collision_shape = CircleShape2D.new()
collision_shape.radius = area_width collision_shape.radius = area_width
@ -18,5 +21,7 @@ func generate_collision(area_width : float):
collision.shape = collision_shape collision.shape = collision_shape
add_child(collision) add_child(collision)
return collision
func interact_text(): func interact_text():
return "" return ""

View File

@ -127,7 +127,6 @@ func can_use_item_on_zone(item : Item, zone: Area2D) -> bool:
) )
func use_item(item : Item): func use_item(item : Item):
print(action_zone.get_overlapping_areas())
if can_use_item_on_zone(item, action_zone): if can_use_item_on_zone(item, action_zone):
var is_item_used = item.use(self, action_zone) var is_item_used = item.use(self, action_zone)
if is_item_used: if is_item_used:

View File

@ -7,13 +7,13 @@
[ext_resource type="Script" uid="uid://dedg615xudpoq" path="res://entities/interactables/item_object/script/item_object.gd" id="3_215e1"] [ext_resource type="Script" uid="uid://dedg615xudpoq" path="res://entities/interactables/item_object/script/item_object.gd" id="3_215e1"]
[ext_resource type="PackedScene" uid="uid://tsi5j1uxppa4" path="res://stages/terrain/planet/planet.tscn" id="6_e8heu"] [ext_resource type="PackedScene" uid="uid://tsi5j1uxppa4" path="res://stages/terrain/planet/planet.tscn" id="6_e8heu"]
[ext_resource type="Resource" uid="uid://ddqalo1k30i5x" path="res://common/inventory/resources/items/default_shovel.tres" id="6_lc2xo"] [ext_resource type="Resource" uid="uid://ddqalo1k30i5x" path="res://common/inventory/resources/items/default_shovel.tres" id="6_lc2xo"]
[ext_resource type="PackedScene" uid="uid://bkwh1ntvgkkrt" path="res://entities/interactables/compost/compost.tscn" id="7_215e1"] [ext_resource type="Resource" uid="uid://bya8sm6rm6747" path="res://common/inventory/resources/items/compost.tres" id="7_215e1"]
[ext_resource type="Script" uid="uid://bq7admu4ahs5r" path="res://common/inventory/scripts/item.gd" id="7_rvswv"] [ext_resource type="Script" uid="uid://bq7admu4ahs5r" path="res://common/inventory/scripts/item.gd" id="7_rvswv"]
[ext_resource type="PackedScene" uid="uid://d324mlmgls4fs" path="res://entities/interactables/recharge_station/recharge_station.tscn" id="8_7sc4i"] [ext_resource type="PackedScene" uid="uid://d324mlmgls4fs" path="res://entities/interactables/machines/recharge_station/recharge_station.tscn" id="8_7sc4i"]
[ext_resource type="Texture2D" uid="uid://pltmnkqd5ut2" path="res://entities/plants/assets/sprites/seeds/grille_seeds.png" id="8_boyg6"] [ext_resource type="Texture2D" uid="uid://pltmnkqd5ut2" path="res://entities/plants/assets/sprites/seeds/grille_seeds.png" id="8_boyg6"]
[ext_resource type="Resource" uid="uid://b04vho33bl52b" path="res://entities/plants/resources/plants/default.tres" id="9_e36ub"] [ext_resource type="Resource" uid="uid://b04vho33bl52b" path="res://entities/plants/resources/plant_types/default.tres" id="9_e36ub"]
[ext_resource type="Script" uid="uid://bypjcvlc15gsm" path="res://common/inventory/scripts/items/seed.gd" id="10_hb5m1"] [ext_resource type="Script" uid="uid://bypjcvlc15gsm" path="res://common/inventory/scripts/items/seed.gd" id="10_hb5m1"]
[ext_resource type="Resource" uid="uid://dsctivn1vrem2" path="res://entities/plants/resources/plants/maias.tres" id="11_x5p1p"] [ext_resource type="Resource" uid="uid://dsctivn1vrem2" path="res://entities/plants/resources/plant_types/maias.tres" id="11_x5p1p"]
[ext_resource type="PackedScene" uid="uid://dj7gp3crtg2yt" path="res://entities/camera/camera.tscn" id="12_qhcbd"] [ext_resource type="PackedScene" uid="uid://dj7gp3crtg2yt" path="res://entities/camera/camera.tscn" id="12_qhcbd"]
[sub_resource type="AtlasTexture" id="AtlasTexture_qt76e"] [sub_resource type="AtlasTexture" id="AtlasTexture_qt76e"]
@ -74,17 +74,20 @@ y_sort_enabled = true
[node name="Player" parent="Entities" instance=ExtResource("2_lc2xo")] [node name="Player" parent="Entities" instance=ExtResource("2_lc2xo")]
[node name="ShovelObject" type="Area2D" parent="Entities"] [node name="ItemObject" type="Area2D" parent="Entities"]
position = Vector2(2, 72) position = Vector2(0, 129)
script = ExtResource("3_215e1") script = ExtResource("3_215e1")
item = ExtResource("6_lc2xo") item = ExtResource("6_lc2xo")
metadata/_custom_type_script = "uid://dedg615xudpoq" metadata/_custom_type_script = "uid://dedg615xudpoq"
[node name="Compost" parent="Entities" instance=ExtResource("7_215e1")] [node name="ItemObject2" type="Area2D" parent="Entities"]
position = Vector2(3, 458) position = Vector2(-162, 23)
script = ExtResource("3_215e1")
item = ExtResource("7_215e1")
metadata/_custom_type_script = "uid://dedg615xudpoq"
[node name="RechargeStation" parent="Entities" instance=ExtResource("8_7sc4i")] [node name="RechargeStation" parent="Entities" instance=ExtResource("8_7sc4i")]
position = Vector2(0, -154) position = Vector2(-1, -217)
[node name="Planet" parent="." node_paths=PackedStringArray("import_entities_from_node") instance=ExtResource("6_e8heu")] [node name="Planet" parent="." node_paths=PackedStringArray("import_entities_from_node") instance=ExtResource("6_e8heu")]
loot_items = Array[ExtResource("7_rvswv")]([SubResource("Resource_7sc4i"), SubResource("Resource_80cx4"), SubResource("Resource_e8heu")]) loot_items = Array[ExtResource("7_rvswv")]([SubResource("Resource_7sc4i"), SubResource("Resource_80cx4"), SubResource("Resource_e8heu")])

View File

@ -1,10 +0,0 @@
extends Control
class_name Mouse
@export var default_cursor : Texture2D
func _ready():
Input.set_custom_mouse_cursor(default_cursor)
func _process(_delta):
position = get_viewport().get_mouse_position()

View File

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

View File

@ -40,6 +40,13 @@ func _ready():
#region ------------------ Generation ------------------ #region ------------------ Generation ------------------
func instantiate_entity(s: PackedScene, entity_position : Vector2):
var entity = s.instantiate() as Node2D
add_entity(entity)
entity.global_position = entity_position
func add_entity(e : Node2D, container : Node2D = entityContainer): 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)
@ -49,7 +56,6 @@ func add_entity(e : Node2D, container : Node2D = entityContainer):
container.add_child(e) container.add_child(e)
func generate_polygon_sprite(order : int = 0) -> Polygon2D: func generate_polygon_sprite(order : int = 0) -> Polygon2D:
var sprite = Polygon2D.new() var sprite = Polygon2D.new()
var size = terrainData.terrainSize var size = terrainData.terrainSize
@ -115,6 +121,9 @@ func impact_contamination(impact_position : Vector2, impact_radius : int, contam
if contamination_texture: if contamination_texture:
contamination_texture.update(terrainData.contamination) contamination_texture.update(terrainData.contamination)
func is_in_zone(point : Vector2) -> bool:
return terrainData.is_in_image(terrainData.get_pixel_point(point), terrainData.contamination)
func is_there_contamination(point : Vector2) -> bool: func is_there_contamination(point : Vector2) -> bool:
return terrainData.get_contamination(point) < 0.5 return terrainData.get_contamination(point) < 0.5