#22 développement du pourcentage de contamination

This commit is contained in:
Zacharie Guet 2025-08-19 09:44:59 +02:00
parent f5be43767a
commit b0efeff809
15 changed files with 101 additions and 97 deletions

View File

@ -2,12 +2,12 @@ extends Resource
class_name TerrainData
const TERRAIN_IMAGE_GAME_FACTOR = 50
const DEFAULT_CONTAMINATION_CENTRAL_ZONE_MAX_SIZE = 1000
const DEFAULT_CONTAMINATION_CENTRAL_ZONE_MIN_SIZE = 200
const DEFAULT_CONTAMINATION_CENTRAL_ZONE_MAX_SIZE = 500
const DEFAULT_CONTAMINATION_CENTRAL_ZONE_MIN_SIZE = 100
signal terrain_updated
@export var terrainSize : Vector2 = Vector2(2000,2000)
@export var terrainSize : Vector2 = Vector2(1500,1500)
@export var contamination : Image = null
@ -68,3 +68,6 @@ func get_contamination(point : Vector2) -> float:
int(round(pixel_point.x)),
int(round(pixel_point.y))
).r
func get_decontamination_coverage() -> float:
return ImageTools.get_color_coverage(contamination)

View File

@ -1,6 +1,6 @@
[gd_resource type="Resource" script_class="SeedItem" load_steps=3 format=3 uid="uid://lrl2okkhyxmx"]
[ext_resource type="Texture2D" uid="uid://dcgnamu7sb3ov" path="res://gui/player_info/assets/icons/bolt.svg" id="1_dy25s"]
[ext_resource type="Texture2D" uid="uid://dcgnamu7sb3ov" path="res://gui/assets/icons/bolt.svg" id="1_dy25s"]
[ext_resource type="Script" uid="uid://bypjcvlc15gsm" path="res://common/inventory/scripts/items/seed_item.gd" id="2_mgcdi"]
[resource]

View File

@ -1,5 +1,14 @@
class_name ImageTools
static func get_color_coverage(image: Image, color: Color = Color.WHITE):
var pixel_color_count = 0.
for x in range(image.get_width()):
for y in range(image.get_height()):
if image.get_pixel(x, y) == color:
pixel_color_count += 1.
return pixel_color_count/(image.get_width()*image.get_height())
static func draw_circle(image: Image, center: Vector2i, length: int, color: Color = Color.WHITE):
for x in range(image.get_width()):
for y in range(image.get_height()):

View File

@ -20,7 +20,7 @@ region = Rect2(1140, 345, 141, 128)
script = ExtResource("1_moyj3")
name = "Chardi"
description = "This plant can grow without water, and reduce contamination around when it becomes mature."
growing_time = 2
growing_time = 1
seed_texture = SubResource("AtlasTexture_ffarr")
planted_texture = ExtResource("4_2s6re")
growing_texture = ExtResource("1_fp5j6")

View File

Before

Width:  |  Height:  |  Size: 887 B

After

Width:  |  Height:  |  Size: 887 B

View File

@ -3,15 +3,15 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://dcgnamu7sb3ov"
path="res://.godot/imported/bolt.svg-346ec638bad7861a6c0a47abfe0480f6.ctex"
path="res://.godot/imported/bolt.svg-99699818681b1e0e18f4836dfd772b8c.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://gui/player_info/assets/icons/bolt.svg"
dest_files=["res://.godot/imported/bolt.svg-346ec638bad7861a6c0a47abfe0480f6.ctex"]
source_file="res://gui/assets/icons/bolt.svg"
dest_files=["res://.godot/imported/bolt.svg-99699818681b1e0e18f4836dfd772b8c.ctex"]
[params]

View File

Before

Width:  |  Height:  |  Size: 294 KiB

After

Width:  |  Height:  |  Size: 294 KiB

View File

@ -3,15 +3,15 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://cm3ehinvvj52i"
path="res://.godot/imported/Interface sans boutons.png-6f58a6b9570fde0ac2945334970770a8.ctex"
path="res://.godot/imported/Interface sans boutons.png-84e848a01e86bdad058d81d09d7731ba.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://gui/player_info/assets/texture/Interface sans boutons.png"
dest_files=["res://.godot/imported/Interface sans boutons.png-6f58a6b9570fde0ac2945334970770a8.ctex"]
source_file="res://gui/assets/texture/Interface sans boutons.png"
dest_files=["res://.godot/imported/Interface sans boutons.png-84e848a01e86bdad058d81d09d7731ba.ctex"]
[params]

View File

@ -1,68 +0,0 @@
[gd_scene load_steps=6 format=3 uid="uid://baqrmhsgqda6v"]
[ext_resource type="Script" uid="uid://bpqh8n0lbluf8" path="res://gui/player_info/scripts/player_info.gd" id="1_ghu0s"]
[ext_resource type="Texture2D" uid="uid://cm3ehinvvj52i" path="res://gui/player_info/assets/texture/Interface sans boutons.png" id="2_cgy6f"]
[ext_resource type="Texture2D" uid="uid://dcgnamu7sb3ov" path="res://gui/player_info/assets/icons/bolt.svg" id="3_s4ggy"]
[ext_resource type="Theme" uid="uid://bgcmd213j6gk1" path="res://gui/ressources/default_theme.tres" id="4_cgy6f"]
[ext_resource type="LabelSettings" uid="uid://dqwayi8yjwau2" path="res://gui/ressources/default_label_settings.tres" id="5_s4ggy"]
[node name="PlayerInfo" type="Control"]
custom_minimum_size = Vector2(337, 160)
layout_mode = 3
anchor_right = 0.293
anchor_bottom = 0.247
offset_right = -0.536011
offset_bottom = -0.0559998
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 0
size_flags_vertical = 0
script = ExtResource("1_ghu0s")
[node name="Background" type="TextureRect" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
texture = ExtResource("2_cgy6f")
expand_mode = 2
stretch_mode = 5
[node name="EnergyInfo" type="HBoxContainer" parent="."]
layout_mode = 1
anchors_preset = -1
anchor_left = 0.281899
anchor_top = 0.384375
anchor_right = 0.281899
anchor_bottom = 0.584375
offset_left = -44.0
offset_top = -12.5
offset_right = 44.0
offset_bottom = 12.5
grow_horizontal = 2
grow_vertical = 2
metadata/_edit_use_anchors_ = true
[node name="Icon" type="TextureRect" parent="EnergyInfo"]
custom_minimum_size = Vector2(36.64, 0)
layout_mode = 2
texture = ExtResource("3_s4ggy")
stretch_mode = 5
[node name="Label" type="Label" parent="EnergyInfo"]
layout_mode = 2
theme = ExtResource("4_cgy6f")
text = "0"
label_settings = ExtResource("5_s4ggy")
horizontal_alignment = 1
vertical_alignment = 1
[node name="Inventory" type="HBoxContainer" parent="."]
layout_mode = 0
offset_left = 157.0
offset_top = 86.0
offset_right = 291.0
offset_bottom = 126.0
alignment = 1

View File

@ -1,4 +0,0 @@
extends Control
func player_update(player: Player):
$EnergyInfo/Label.text = str(player.energy)

View File

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

View File

@ -1,9 +1,9 @@
[gd_scene load_steps=16 format=3 uid="uid://12nak7amd1uq"]
[ext_resource type="PackedScene" uid="uid://baqrmhsgqda6v" path="res://gui/player_info/player_info.tscn" id="1_8kw6x"]
[ext_resource type="Script" uid="uid://cqao7n800qy40" path="res://gui/scripts/root_gui.gd" id="1_udau0"]
[ext_resource type="Theme" uid="uid://bgcmd213j6gk1" path="res://gui/ressources/default_theme.tres" id="2_nq5i2"]
[ext_resource type="Texture2D" uid="uid://dcgnamu7sb3ov" path="res://gui/player_info/assets/icons/bolt.svg" id="4_k4juk"]
[ext_resource type="Texture2D" uid="uid://cm3ehinvvj52i" path="res://gui/assets/texture/Interface sans boutons.png" id="3_n4kem"]
[ext_resource type="Texture2D" uid="uid://dcgnamu7sb3ov" path="res://gui/assets/icons/bolt.svg" id="4_k4juk"]
[ext_resource type="LabelSettings" uid="uid://dqwayi8yjwau2" path="res://gui/ressources/default_label_settings.tres" id="4_ujg5r"]
[ext_resource type="Texture2D" uid="uid://c2pgaklnj5w3d" path="res://gui/assets/texture/Tablette info.png" id="6_fovlv"]
[ext_resource type="Texture2D" uid="uid://pltmnkqd5ut2" path="res://entities/plants/assets/sprites/seeds/grille_seeds.png" id="7_n4kem"]
@ -137,8 +137,64 @@ grow_vertical = 2
mouse_filter = 2
theme = ExtResource("2_nq5i2")
[node name="PlayerInfo" parent="MarginContainer" instance=ExtResource("1_8kw6x")]
[node name="PlayerInfo" type="Control" parent="MarginContainer"]
custom_minimum_size = Vector2(337, 160)
layout_mode = 2
size_flags_horizontal = 0
size_flags_vertical = 0
[node name="Background" type="TextureRect" parent="MarginContainer/PlayerInfo"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
texture = ExtResource("3_n4kem")
expand_mode = 2
stretch_mode = 5
[node name="EnergyInfo" type="HBoxContainer" parent="MarginContainer/PlayerInfo"]
layout_mode = 1
anchors_preset = -1
anchor_left = 0.281899
anchor_top = 0.384375
anchor_right = 0.281899
anchor_bottom = 0.584375
offset_left = -44.0
offset_top = -12.5
offset_right = 44.0
offset_bottom = 12.5
grow_horizontal = 2
grow_vertical = 2
metadata/_edit_use_anchors_ = true
[node name="Icon" type="TextureRect" parent="MarginContainer/PlayerInfo/EnergyInfo"]
custom_minimum_size = Vector2(36.64, 0)
layout_mode = 2
texture = ExtResource("4_k4juk")
stretch_mode = 5
[node name="EnergyCount" type="Label" parent="MarginContainer/PlayerInfo/EnergyInfo"]
unique_name_in_owner = true
layout_mode = 2
theme = ExtResource("2_nq5i2")
text = "0"
label_settings = ExtResource("4_ujg5r")
horizontal_alignment = 1
vertical_alignment = 1
[node name="DecontaminationCoverage" type="Label" parent="MarginContainer/PlayerInfo"]
unique_name_in_owner = true
layout_mode = 0
offset_left = 157.0
offset_top = 86.0
offset_right = 291.0
offset_bottom = 126.0
text = "100%"
label_settings = ExtResource("4_ujg5r")
horizontal_alignment = 1
vertical_alignment = 1
[node name="DayPass" type="Button" parent="MarginContainer"]
layout_mode = 2

View File

@ -7,7 +7,7 @@ signal day_pass_proceed
signal day_pass_finished
func _on_player_updated(player:Player):
$MarginContainer/PlayerInfo.player_update(player)
%EnergyCount.text = str(player.energy)
%AvailableActions/GetItem.visible = player.closest_interactable is ItemObject and player.inventory.lenght() == 0
%AvailableActions/SwapItem.visible = player.closest_interactable is ItemObject and player.inventory.lenght() > 0
@ -23,9 +23,6 @@ func _on_player_updated(player:Player):
%ItemName.text = item.name
%ItemDesc.text = item.description
func _on_planet_planet_stats_updated(day:int):
$MarginContainer/DayCount.text = "Day " + str(day)
func _on_day_pass_pressed():
day_pass_pressed.emit()
$AnimationPlayer.play("recharge_fade_in")
@ -37,3 +34,7 @@ func _on_day_pass_pressed():
func _on_game_action_button_down():
game_click.emit()
func _on_planet_updated(planet:Planet):
$MarginContainer/DayCount.text = "Day " + str(planet.day)
%DecontaminationCoverage.text = str(roundi(planet.decontamination_coverage * 100)) + "%"

View File

@ -54,8 +54,9 @@ position = Vector2(2.22, 0)
following = NodePath("../Entities/Player")
[connection signal="day_pass_finished" from="CanvasLayer/RootGui" to="Entities/Player" method="_on_root_gui_day_pass_finished"]
[connection signal="day_pass_finished" from="CanvasLayer/RootGui" to="Planet" method="_on_root_gui_day_pass_finished"]
[connection signal="day_pass_pressed" from="CanvasLayer/RootGui" to="Entities/Player" method="_on_root_gui_day_pass_pressed"]
[connection signal="day_pass_proceed" from="CanvasLayer/RootGui" to="Planet" method="_on_root_gui_day_pass_proceed"]
[connection signal="game_click" from="CanvasLayer/RootGui" to="Entities/Player" method="_on_root_gui_game_click"]
[connection signal="player_updated" from="Entities/Player" to="CanvasLayer/RootGui" method="_on_player_updated"]
[connection signal="planet_stats_updated" from="Planet" to="CanvasLayer/RootGui" method="_on_planet_planet_stats_updated"]
[connection signal="planet_updated" from="Planet" to="CanvasLayer/RootGui" method="_on_planet_updated"]

View File

@ -1,7 +1,7 @@
extends Terrain
class_name Planet
signal planet_stats_updated(day : int)
signal planet_updated(planet : Planet)
const PLANET_TEXTURE_SCALE : float = 5.0
@ -10,15 +10,19 @@ const PLANET_TEXTURE_SCALE : float = 5.0
@onready var background_sprite : Polygon2D = generate_background_sprite()
@onready var contamination_sprite : Polygon2D = generate_contamination_terrain_sprite()
@onready var decontamination_coverage : float = terrainData.get_decontamination_coverage() :
set(v):
decontamination_coverage = v
planet_updated.emit(self)
var contamination_texture : ImageTexture
var day : int = 0 :
set(v):
emit_signal("planet_stats_updated", v)
day = v
planet_updated.emit(self)
func _ready():
emit_signal("planet_stats_updated", day)
planet_updated.emit(self)
#region ------------------ Generation ------------------
@ -110,3 +114,6 @@ func pass_day():
func _on_root_gui_day_pass_proceed():
pass_day()
func _on_root_gui_day_pass_finished():
decontamination_coverage = terrainData.get_decontamination_coverage()