Compare commits

...

2 Commits

31 changed files with 164 additions and 64 deletions

View File

@ -62,16 +62,16 @@ func impact_contamination(position : Vector2, impact_radius : int, to_value : fl
Color(1., 1., 1., to_value)
)
func get_contamination(point : Vector2) -> float:
var pixel_point : Vector2 = (
Vector2(point) / float(TERRAIN_IMAGE_GAME_FACTOR)
- Vector2.ONE / 2
)
if (
func is_in_image(pixel_point : Vector2, image : Image):
return (
pixel_point.x > 0
and pixel_point.y > 0
and pixel_point.x < contamination.get_width()
and pixel_point.y < contamination.get_height()):
and pixel_point.x < image.get_width()
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(
int(round(pixel_point.x)),
int(round(pixel_point.y))
@ -80,3 +80,9 @@ func get_contamination(point : Vector2) -> float:
func get_decontamination_coverage() -> float:
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
class_name ItemObject
@ -20,6 +19,9 @@ func _init(_item = null):
func _ready():
generate_collision(ITEM_AREA_WIDTH)
if item and object_sprite:
object_sprite.apply_texture_to_sprite(item.icon, ITEM_SPRITE_SIZE)
func inspected_text():
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"
type="CompressedTexture2D"
uid="uid://f2rte5jc0psp"
path="res://.godot/imported/compost.svg-503fc2423ba701b15edd51da5ab01164.ctex"
path="res://.godot/imported/compost.svg-f43ad0f7b40754d19aa7d5ea88e80cb8.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://entities/interactables/compost/assets/sprites/compost.svg"
dest_files=["res://.godot/imported/compost.svg-503fc2423ba701b15edd51da5ab01164.ctex"]
source_file="res://entities/interactables/machines/compost/assets/sprites/compost.svg"
dest_files=["res://.godot/imported/compost.svg-f43ad0f7b40754d19aa7d5ea88e80cb8.ctex"]
[params]

View File

@ -1,7 +1,7 @@
[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="Texture2D" uid="uid://f2rte5jc0psp" path="res://entities/interactables/compost/assets/sprites/compost.svg" id="2_r6435"]
[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/machines/compost/assets/sprites/compost.svg" id="2_r6435"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_etofw"]
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_left = 5
[sub_resource type="RectangleShape2D" id="RectangleShape2D_coj8m"]
size = Vector2(77, 92)
[sub_resource type="Animation" id="Animation_r6435"]
length = 0.001
tracks/0/type = "value"
@ -98,8 +95,11 @@ _data = {
&"fill": SubResource("Animation_etofw")
}
[sub_resource type="RectangleShape2D" id="RectangleShape2D_akkx7"]
size = Vector2(66, 84)
[node name="Compost" type="Area2D"]
script = ExtResource("1_1758a")
script = ExtResource("1_c0pig")
[node name="Compost" type="Sprite2D" parent="."]
modulate = Color(0.615686, 0.501961, 0.270588, 1)
@ -114,16 +114,13 @@ offset_right = 62.0
offset_bottom = 120.0
theme_override_styles/background = SubResource("StyleBoxFlat_etofw")
theme_override_styles/fill = SubResource("StyleBoxFlat_3ao1n")
value = 20.0
fill_mode = 3
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="."]
libraries = {
&"": 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
@export var value_per_seed : float = 0.5
@onready var fill_value : float = 0.
var value_per_seed : float = 0.5
var fill_value : float = 0.
func _process(_delta):
%ProgressBar.value = lerp(%ProgressBar.value, fill_value * 100, 0.5)
@ -13,7 +11,7 @@ func inspected_text():
return "Compost"
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:
return p.inventory.get_item() and p.inventory.get_item() is Seed

View File

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

View File

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

View File

@ -1,7 +1,7 @@
[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="Texture2D" uid="uid://c82ljr3in67am" path="res://entities/interactables/recharge_station/assets/sprites/recharge_station.svg" id="2_58ax0"]
[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/machines/recharge_station/assets/sprites/recharge_station.svg" id="2_58ax0"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_bjhct"]
radius = 15.0

View File

@ -1,4 +1,4 @@
extends Interactable
extends Machine
class_name RechargeStation
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:
return true
func interaction_cost(_p : Player) -> int:
return 0
func interact(_p : Player) -> bool:
printerr("Interact function called on abstract Interactable class")
return false
func generate_collision(area_width : float):
func generate_collision(area_width : float) -> CollisionShape2D:
var collision = CollisionShape2D.new()
var collision_shape = CircleShape2D.new()
collision_shape.radius = area_width
@ -18,5 +21,7 @@ func generate_collision(area_width : float):
collision.shape = collision_shape
add_child(collision)
return collision
func interact_text():
return ""

View File

@ -127,7 +127,6 @@ func can_use_item_on_zone(item : Item, zone: Area2D) -> bool:
)
func use_item(item : Item):
print(action_zone.get_overlapping_areas())
if can_use_item_on_zone(item, action_zone):
var is_item_used = item.use(self, action_zone)
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="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="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="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="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="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"]
[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="ShovelObject" type="Area2D" parent="Entities"]
position = Vector2(2, 72)
[node name="ItemObject" type="Area2D" parent="Entities"]
position = Vector2(0, 129)
script = ExtResource("3_215e1")
item = ExtResource("6_lc2xo")
metadata/_custom_type_script = "uid://dedg615xudpoq"
[node name="Compost" parent="Entities" instance=ExtResource("7_215e1")]
position = Vector2(3, 458)
[node name="ItemObject2" type="Area2D" parent="Entities"]
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")]
position = Vector2(0, -154)
position = Vector2(-1, -217)
[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")])

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

@ -1,9 +1,10 @@
[gd_scene load_steps=6 format=3 uid="uid://0yr6b2jtuttm"]
[gd_scene load_steps=7 format=3 uid="uid://0yr6b2jtuttm"]
[ext_resource type="Script" uid="uid://vhumsfntpqcl" path="res://gui/pointer/scripts/pointer.gd" id="1_1pe2k"]
[ext_resource type="Texture2D" uid="uid://bspffyprdywgc" path="res://gui/pointer/assets/cursors/pointer.svg" id="2_q4bvb"]
[ext_resource type="AudioStream" uid="uid://bym03qp4n6vep" path="res://gui/pointer/assets/sounds/click.wav" id="3_kj0cm"]
[ext_resource type="Texture2D" uid="uid://djb52fosgmv4j" path="res://gui/pointer/assets/icons/left_click.svg" id="3_pshoq"]
[ext_resource type="Texture2D" uid="uid://dcgnamu7sb3ov" path="res://gui/game/assets/icons/bolt.svg" id="4_b4uwv"]
[ext_resource type="Script" uid="uid://c2en2hc6a7ils" path="res://gui/pointer/scripts/action_zone.gd" id="4_pshoq"]
[node name="Pointer" type="Node"]
@ -42,10 +43,15 @@ unique_name_in_owner = true
modulate = Color(1, 1, 0.168627, 1)
layout_mode = 2
[node name="TextureRect" type="TextureRect" parent="CanvasLayer/Inspector/Container/Action"]
[node name="MouseImage" type="TextureRect" parent="CanvasLayer/Inspector/Container/Action"]
layout_mode = 2
texture = ExtResource("3_pshoq")
[node name="ActionEnergyImage" type="TextureRect" parent="CanvasLayer/Inspector/Container/Action"]
unique_name_in_owner = true
layout_mode = 2
texture = ExtResource("4_b4uwv")
[node name="ActionText" type="Label" parent="CanvasLayer/Inspector/Container/Action"]
unique_name_in_owner = true
z_index = 1

View File

@ -1,5 +1,8 @@
extends Node
const DEFAULT_ACTION_COLOR = Color.WHITE
const ENERGY_ACTION_COLOR = Color("ffff2b")
@export var default_cursor : Texture2D
var inspected_entity : InspectableEntity = null
@ -75,9 +78,13 @@ func update_inspector():
if can_interact and inspected_entity and inspected_entity is Interactable:
%Action.visible = true
%ActionText.text = inspected_entity.interact_text()
%Action.modulate = DEFAULT_ACTION_COLOR if inspected_entity.interaction_cost(player) == 0 else ENERGY_ACTION_COLOR
%ActionEnergyImage.visible = inspected_entity.interaction_cost(player) != 0
elif can_use_item and current_selected_item:
%Action.visible = true
%ActionText.text = current_selected_item.use_text()
%Action.modulate = DEFAULT_ACTION_COLOR if current_selected_item.use_energy == 0 else ENERGY_ACTION_COLOR
%ActionEnergyImage.visible = current_selected_item.use_energy != 0
else:
%Action.visible = false

View File

@ -40,6 +40,13 @@ func _ready():
#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):
if e.get_parent():
e.get_parent().remove_child(e)
@ -49,7 +56,6 @@ func add_entity(e : Node2D, container : Node2D = entityContainer):
container.add_child(e)
func generate_polygon_sprite(order : int = 0) -> Polygon2D:
var sprite = Polygon2D.new()
var size = terrainData.terrainSize
@ -115,6 +121,9 @@ func impact_contamination(impact_position : Vector2, impact_radius : int, contam
if contamination_texture:
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:
return terrainData.get_contamination(point) < 0.5