refactor du code et ajouts des quotas, avec des récompense entre chaque quota #68

This commit is contained in:
2025-09-14 19:35:43 +02:00
parent 85cd832864
commit 43bdbc3581
44 changed files with 918 additions and 339 deletions

View File

@@ -1,11 +1,15 @@
extends Resource
class_name GameData
@export var current_terrain_data : TerrainData
@export var current_planet_data : PlanetData
@export var unlocked_plant_types_path : Array[PlantType] = [
preload("res://entities/plants/resources/plant_types/champ.tres"),
preload("res://entities/plants/resources/plant_types/chardi.tres"),
preload("res://entities/plants/resources/plant_types/maias.tres"),
preload("res://entities/plants/resources/plant_types/pili.tres"),
]
@export var unlocked_machines : Array[MachineType] = [
preload("res://entities/interactables/machines/compost/compost.tres")
]

View File

@@ -0,0 +1,81 @@
extends Resource
class_name PlanetData
const DEFAULT_CONTAMINATION_CENTRAL_ZONE_MAX_SIZE = 400.
const DEFAULT_CONTAMINATION_CENTRAL_ZONE_MIN_SIZE = 100.
const DEFAULT_BASE_SIZE = Vector2(2000,2000)
@export var base_size : Vector2 = Vector2(2000,2000)
@export var contamination : TerrainData
@export var quota_number : int = 0
func _init(_base_size : Vector2 = DEFAULT_BASE_SIZE):
base_size = _base_size
contamination = TerrainData.new(base_size)
contamination.draw_random_zone(
DEFAULT_CONTAMINATION_CENTRAL_ZONE_MAX_SIZE,
DEFAULT_CONTAMINATION_CENTRAL_ZONE_MIN_SIZE,
base_size/2
)
func impact_contamination(position : Vector2, impact_radius : float, to_value : float = 1.):
contamination.draw_circle(
position,
impact_radius,
to_value
)
func is_in_base(point):
return (
point.x > 0
and point.y > 0
and point.x < base_size.x
and point.y < base_size.y)
func get_contamination(point : Vector2) -> float:
return contamination.get_value(point)
func get_decontamination_coverage() -> float:
return contamination.get_value_coverage()
func get_decontamination_surface() -> float:
return contamination.get_value_surface() * 10
#endregion
#region ------------------ Objectives ------------------
func generate_objective_rewards(level = 1) -> Array[ObjectiveReward]:
var amount = level + 1
var possible_objective_rewards_path : Array[ObjectiveReward] = [
IncreaseDayLimitReward.new(randi_range(level + 1, level + 3)),
UpgradePlayerMaxEnergyReward.new(),
]
var objectives_reward : Array[ObjectiveReward] = []
var i = 0
while i < amount and len(possible_objective_rewards_path) > 0:
var r = possible_objective_rewards_path.pick_random()
possible_objective_rewards_path.erase(r)
objectives_reward.append(r)
i += 1
return objectives_reward
#endregion
#region ------------------ Quotas ------------------
func get_quota(n = 0) -> int:
var first_quota = 50
var quota_adding = n * 50
if n == 0:
return first_quota
elif n < 0:
return 0
return get_quota(n - 1) + quota_adding
#endregion

View File

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

View File

@@ -1,116 +1,98 @@
extends Resource
class_name TerrainData
const TERRAIN_IMAGE_GAME_FACTOR = 40.
const DEFAULT_CONTAMINATION_CENTRAL_ZONE_MAX_SIZE = 400.
const DEFAULT_CONTAMINATION_CENTRAL_ZONE_MIN_SIZE = 100.
const DEFAULT_TERRAIN_SIZE = Vector2(2000,2000)
const UNIT_PER_PIXEL = 30
@export var terrain_size : Vector2
@export var image : Image
@export var image_size : Vector2i
func _init(size : Vector2 = DEFAULT_TERRAIN_SIZE):
terrain_size = size
generate_default_contamination()
#region ------------------ Contamination ------------------
@export var contamination : Image = null
func generate_default_contamination(
central_zone_max_size : float = DEFAULT_CONTAMINATION_CENTRAL_ZONE_MAX_SIZE,
central_zone_min_size : float = DEFAULT_CONTAMINATION_CENTRAL_ZONE_MIN_SIZE,
):
var noise: Noise = FastNoiseLite.new()
noise.seed = randi()
noise.noise_type = FastNoiseLite.TYPE_CELLULAR
noise.frequency = 0.005 * TERRAIN_IMAGE_GAME_FACTOR
var imageSize = terrain_size / TERRAIN_IMAGE_GAME_FACTOR;
var noise_image = noise.get_image(
imageSize.x,
imageSize.y,
1.0
)
ImageTools.draw_gradient(
noise_image,
imageSize/2,
central_zone_min_size / TERRAIN_IMAGE_GAME_FACTOR
)
ImageTools.draw_gradient(
noise_image,
imageSize/2,
central_zone_max_size / TERRAIN_IMAGE_GAME_FACTOR,
Color.BLACK,
true
)
ImageTools.flatten(noise_image, 0.5)
contamination = Image.create(
imageSize.x,
imageSize.y,
func _init(terrain_size : Vector2):
image_size = terrain_size / UNIT_PER_PIXEL
image = Image.create(
image_size.x,
image_size.y,
false,
Image.Format.FORMAT_L8
)
contamination.copy_from(noise_image)
func draw_random_zone(
zone_max_size : float,
zone_min_size : float,
zone_position : Vector2i
):
var noise: Noise = FastNoiseLite.new()
noise.seed = randi()
noise.noise_type = FastNoiseLite.TYPE_CELLULAR
noise.frequency = 0.001 / UNIT_PER_PIXEL
func impact_contamination(position : Vector2, impact_radius : int, to_value : float = 1.):
var noise_image_size : Vector2i = Vector2i.ONE * zone_max_size / UNIT_PER_PIXEL
var noise_image_center = noise_image_size / 2
var noise_image = noise.get_image(
noise_image_size.x,
noise_image_size.y,
1.0,
)
ImageTools.draw_gradient(
noise_image,
noise_image_center,
roundi(zone_min_size / UNIT_PER_PIXEL)
)
ImageTools.draw_gradient(
noise_image,
noise_image_center,
roundi(zone_max_size / UNIT_PER_PIXEL),
Color.BLACK,
true
)
ImageTools.flatten(noise_image, 0.5)
image.blit_rect(
noise_image,
Rect2i(
Vector2i.ZERO,
noise_image_size
),
Vector2i(zone_position / UNIT_PER_PIXEL) - noise_image_size/2
)
func draw_circle(position : Vector2, impact_radius : float, to_value : float = 1.):
ImageTools.draw_circle(
contamination,
position / TERRAIN_IMAGE_GAME_FACTOR,
impact_radius / TERRAIN_IMAGE_GAME_FACTOR,
image,
position / UNIT_PER_PIXEL,
roundi(impact_radius / UNIT_PER_PIXEL),
Color(1., 1., 1., to_value)
)
func is_in_image(pixel_point : Vector2, image : Image):
func is_in_image(pixel_point : Vector2i):
return (
pixel_point.x > 0
and pixel_point.y > 0
and pixel_point.x < image.get_width()
and pixel_point.y < image.get_height())
func get_contamination(point : Vector2) -> float:
func is_in_terrain(point : Vector2):
return is_in_image(get_pixel_point(point))
func get_value(point : Vector2) -> float:
var pixel_point : Vector2i = get_pixel_point(point)
if (is_in_image(pixel_point, contamination)):
return contamination.get_pixel(
if (is_in_image(pixel_point)):
return image.get_pixel(
pixel_point.x,
pixel_point.y
).r
return 0
func get_decontamination_coverage() -> float:
return ImageTools.get_color_coverage(contamination)
func get_value_coverage() -> float:
return ImageTools.get_color_coverage(image)
func get_decontamination_surface() -> float:
return ImageTools.get_color_pixel_count(contamination)/TERRAIN_IMAGE_GAME_FACTOR * 10
func get_value_surface() -> float:
return float(ImageTools.get_color_pixel_count(image)) / UNIT_PER_PIXEL
func get_pixel_point(point : Vector2) -> Vector2i:
return Vector2i(
Vector2(point) / float(TERRAIN_IMAGE_GAME_FACTOR)
Vector2(point) / UNIT_PER_PIXEL
)
#endregion
#region ------------------ Objectives ------------------
func generate_objective_rewards(level = 1, amount = 1) -> Array[ObjectiveReward]:
var possible_objective_rewards_path : Array[ObjectiveReward] = [
IncreaseDayLimitReward.new(randi_range(level + 1, level + 3)),
LootItemReward.new(load("res://common/inventory/resources/items/compost.tres")),
UpgradePlayerMaxEnergyReward.new(),
]
var objectives_reward : Array[ObjectiveReward] = []
var i = 0
while i < amount and len(possible_objective_rewards_path) > 0:
var r = possible_objective_rewards_path.pick_random()
possible_objective_rewards_path.erase(r)
objectives_reward.append(r)
i += 1
return objectives_reward

View File

@@ -1 +1 @@
uid://cx30nvq8b34lj
uid://we5pyyr1n06v

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-cube-3d-sphere"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M6 17.6l-2 -1.1v-2.5" /><path d="M4 10v-2.5l2 -1.1" /><path d="M10 4.1l2 -1.1l2 1.1" /><path d="M18 6.4l2 1.1v2.5" /><path d="M20 14v2.5l-2 1.12" /><path d="M14 19.9l-2 1.1l-2 -1.1" /><path d="M12 12l2 -1.1" /><path d="M18 8.6l2 -1.1" /><path d="M12 12l0 2.5" /><path d="M12 18.5l0 2.5" /><path d="M12 12l-2 -1.12" /><path d="M6 8.6l-2 -1.1" /></svg>

After

Width:  |  Height:  |  Size: 669 B

View File

@@ -0,0 +1,37 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bsvxhafoxwmw0"
path="res://.godot/imported/cube-3d-sphere.svg-f86899fe00f38af995e1752e193f1d54.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://common/icons/cube-3d-sphere.svg"
dest_files=["res://.godot/imported/cube-3d-sphere.svg-f86899fe00f38af995e1752e193f1d54.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=2.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false

View File

@@ -1,15 +0,0 @@
[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/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 = "The compost allow you to generate one energy for a certain amount of seeds."
icon = ExtResource("1_lhhdv")
use_zone_radius = 5
use_energy = 1
metadata/_custom_type_script = "uid://b6kubqgq0k7vj"

View File

@@ -1,13 +0,0 @@
[gd_resource type="Resource" script_class="Seed" load_steps=3 format=3 uid="uid://lrl2okkhyxmx"]
[ext_resource type="Texture2D" uid="uid://dcgnamu7sb3ov" path="res://common/icons/bolt.svg" id="1_dy25s"]
[ext_resource type="Script" uid="uid://bypjcvlc15gsm" path="res://common/inventory/scripts/items/seed.gd" id="2_mgcdi"]
[resource]
script = ExtResource("2_mgcdi")
name = "Boule"
description = ""
icon = ExtResource("1_dy25s")
use_zone_radius = 5
use_energy = 1
metadata/_custom_type_script = "uid://bypjcvlc15gsm"

View File

@@ -1,13 +0,0 @@
[gd_resource type="Resource" script_class="Shovel" load_steps=3 format=3 uid="uid://ddqalo1k30i5x"]
[ext_resource type="Texture2D" uid="uid://bf6nw4onkhavr" path="res://common/icons/shovel.svg" id="1_7g3xd"]
[ext_resource type="Script" uid="uid://dya38x1h1uiyg" path="res://common/inventory/scripts/items/shovel.gd" id="1_28h2r"]
[resource]
script = ExtResource("1_28h2r")
name = "Shovel"
description = "Can dig burried seed, and transform mature plants to seeds."
icon = ExtResource("1_7g3xd")
use_zone_radius = 50
use_energy = 1
metadata/_custom_type_script = "uid://dya38x1h1uiyg"

View File

@@ -1,11 +0,0 @@
[gd_resource type="Resource" script_class="Item" load_steps=3 format=3 uid="uid://dbja8xm7ehw1v"]
[ext_resource type="Texture2D" uid="uid://bo3o2qf3i20ke" path="res://common/icons/scuba-diving-tank.svg" id="1_sy4rh"]
[ext_resource type="Script" uid="uid://bq7admu4ahs5r" path="res://common/inventory/scripts/item.gd" id="2_aikyk"]
[resource]
script = ExtResource("2_aikyk")
name = "Water Can"
description = "Water all plants"
icon = ExtResource("1_sy4rh")
metadata/_custom_type_script = "uid://bq7admu4ahs5r"

View File

@@ -1,11 +1,26 @@
extends Resource
class_name Item
@export var name: String
@export_multiline var description: String
@export var icon: Texture2D
@export var use_zone_radius: int = 5
@export var use_energy: int = 1
var name: String : get = get_item_name
var description: String : get = get_description
var icon: Texture2D : get = get_icon
var usage_zone_radius: int = 5 : get = get_usage_zone_radius
var energy_usage : int = 1 : get = get_energy_used
func get_item_name() -> String:
return name
func get_description() -> String:
return description
func get_icon() -> Texture2D:
return icon
func get_energy_used() -> int:
return energy_usage
func get_usage_zone_radius() -> int:
return usage_zone_radius
func is_one_time_use():
return false
@@ -16,8 +31,5 @@ func can_use(_player : Player, zone: Area2D) -> bool:
func use_text() -> String:
return ""
func use_requirement_text() -> String:
return ""
func use(_player : Player, zone: Area2D):
return false

View File

@@ -0,0 +1,39 @@
extends Item
class_name Blueprint
@export var machine_type: MachineType
@export var machine_level: int = 1
func _init(_machine_type : MachineType = null, _machine_level : int = 1):
machine_type = _machine_type
machine_level = _machine_level
func get_item_name() -> String:
if machine_type:
return machine_type.name + " level " + str(machine_level)
return ""
func get_description() -> String:
if machine_type:
return machine_type.description
return ""
func get_icon() -> Texture2D:
return preload("res://common/icons/cube-3d-sphere.svg")
func use_text() -> String:
if machine_type:
return "Build " + machine_type.name
return ""
func is_one_time_use():
return true
func can_use(player : Player, zone : Area2D) -> bool:
return player.planet.is_in_base(zone.global_position)
func use(player : Player, zone : Area2D) -> bool:
if machine_type and machine_level:
player.planet.instantiate_machine(machine_type, machine_level, zone.global_position)
return true
return false

View File

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

View File

@@ -2,18 +2,30 @@ extends Item
class_name Package
@export var scene: PackedScene
@export var package_name : String
@export_multiline var package_description : String
func _init(_scene : PackedScene = null):
scene = _scene
func get_item_name() -> String:
return package_name
func get_description() -> String:
return package_description
func get_icon() -> Texture2D:
return preload("res://common/icons/package.svg")
func use_text() -> String:
return "Build " + name
return "Open"
func is_one_time_use():
return true
func can_use(player : Player, zone : Area2D) -> bool:
return player.planet.is_in_zone(zone.global_position)
return true
func use(player : Player, zone : Area2D) -> bool:
player.planet.instantiate_entity(scene, zone.global_position)

View File

@@ -1,14 +1,19 @@
@tool
extends Item
class_name Seed
@export var plant_type: PlantType :
set(v):
plant_type = v
if plant_type:
name = plant_type.name
description = plant_type.description
icon = plant_type.seed_texture
@export var plant_type: PlantType
func get_item_name() -> String:
return plant_type.name
func get_description() -> String:
return plant_type.description
func get_icon() -> Texture2D:
return plant_type.seed_texture
func get_energy_used() -> int:
return 1
func _init(_plant_type : PlantType = null):
plant_type = _plant_type

View File

@@ -2,6 +2,22 @@ extends Item
class_name Shovel
const USE_INTERVAL = 0.15
const SHOVEL_ZONE_RADIUS = 50
func get_item_name() -> String:
return "Shovel"
func get_description() -> String:
return "Can dig up buried seeds and can be used to harvest mature plants."
func get_icon() -> Texture2D:
return preload("res://common/icons/shovel.svg")
func get_energy_used() -> int:
return 1
func get_usage_zone_radius() -> int:
return SHOVEL_ZONE_RADIUS
func use_text() -> String:
return "Dig"

View File

@@ -4,11 +4,11 @@
[ext_resource type="AudioStream" uid="uid://d1fyd5o331360" path="res://common/music/assets/vent.ogg" id="2_n52pk"]
[node name="Music" type="Node"]
process_mode = 3
[node name="AudioStreamPlayer_music" type="AudioStreamPlayer" parent="."]
stream = ExtResource("1_stre8")
autoplay = true
stream_paused = true
parameters/looping = false
[node name="AudioStreamPlayer2_ambient" type="AudioStreamPlayer" parent="."]

View File

@@ -1,63 +1,63 @@
class_name ImageTools
static func get_color_coverage(image: Image, color: Color = Color.WHITE) -> float:
return float(get_color_pixel_count(image, color))/(image.get_width()*image.get_height())
return float(get_color_pixel_count(image, color))/(image.get_width()*image.get_height())
static func get_color_pixel_count(image: Image, color: Color = Color.WHITE) -> int:
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
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
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()):
var center_distance = Vector2i(x, y).distance_to(center)
for x in range(image.get_width()):
for y in range(image.get_height()):
var center_distance = Vector2i(x, y).distance_to(center)
if (center_distance <= length):
image.set_pixel(x, y, color)
if (center_distance <= length):
image.set_pixel(x, y, color)
static func draw_gradient(image: Image, center: Vector2i, length: int, color: Color = Color.WHITE, inverse := false):
for x in range(image.get_width()):
for y in range(image.get_height()):
var original_pixel_color = image.get_pixel(x, y)
var center_distance = Vector2i(x, y).distance_to(center)
for x in range(image.get_width()):
for y in range(image.get_height()):
var original_pixel_color = image.get_pixel(x, y)
var center_distance = Vector2i(x, y).distance_to(center)
if (center_distance == 0):
if not inverse:
image.set_pixel(x, y, original_pixel_color.blend(color))
else:
var color_to_add = Color(color, 1 / (center_distance / length)) if not inverse else Color(color, center_distance / length)
image.set_pixel(
x,
y,
original_pixel_color.blend(color_to_add)
)
if (center_distance == 0):
if not inverse:
image.set_pixel(x, y, original_pixel_color.blend(color))
else:
var color_to_add = Color(color, 1 / (center_distance / length)) if not inverse else Color(color, center_distance / length)
image.set_pixel(
x,
y,
original_pixel_color.blend(color_to_add)
)
static func flatten(image: Image, threshold := 0.5):
for x in range(image.get_width()):
for y in range(image.get_height()):
var original_pixel_color = image.get_pixel(x, y)
for x in range(image.get_width()):
for y in range(image.get_height()):
var original_pixel_color = image.get_pixel(x, y)
if original_pixel_color.r > threshold:
image.set_pixel(
x,
y,
Color.WHITE
)
else:
image.set_pixel(
x,
y,
Color.BLACK
)
if original_pixel_color.r > threshold:
image.set_pixel(
x,
y,
Color.WHITE
)
else:
image.set_pixel(
x,
y,
Color.BLACK
)
static func copy(from: Image, to : Image):
for x in range(from.get_width()):
for y in range(from.get_height()):
to.set_pixel(x, y, from.get_pixel(x, y))
for x in range(from.get_width()):
for y in range(from.get_height()):
to.set_pixel(x, y, from.get_pixel(x, y))