#24 et #21 ajout d'une plante générique, et d'un cycle de recharge du robot avec croissance des plantes
@@ -1,8 +0,0 @@
|
||||
extends Interactable
|
||||
class_name Plant
|
||||
|
||||
var watered : bool = false : set = set_watered
|
||||
|
||||
func set_watered(_watered):
|
||||
watered = _watered
|
||||
$AnimatedSprite2D.play("watered" if watered else "default")
|
||||
BIN
entities/plants/assets/sprites/default/growing.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
34
entities/plants/assets/sprites/default/growing.png.import
Normal file
@@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://c7mp7tkkkk6o5"
|
||||
path="res://.godot/imported/growing.png-3f6fb3171589f3a22ebfeda1a4575199.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://entities/plants/assets/sprites/default/growing.png"
|
||||
dest_files=["res://.godot/imported/growing.png-3f6fb3171589f3a22ebfeda1a4575199.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
|
||||
BIN
entities/plants/assets/sprites/default/mature.png
Normal file
|
After Width: | Height: | Size: 149 KiB |
34
entities/plants/assets/sprites/default/mature.png.import
Normal file
@@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://bupl1y0cfj21q"
|
||||
path="res://.godot/imported/mature.png-f8b2b72a84e90cfc6bf925d1d48f7f7e.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://entities/plants/assets/sprites/default/mature.png"
|
||||
dest_files=["res://.godot/imported/mature.png-f8b2b72a84e90cfc6bf925d1d48f7f7e.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
|
||||
BIN
entities/plants/assets/sprites/default/planted.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
34
entities/plants/assets/sprites/default/planted.png.import
Normal file
@@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://ba413oun7ry78"
|
||||
path="res://.godot/imported/planted.png-2c23372e71d0997d310374f47bb48594.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://entities/plants/assets/sprites/default/planted.png"
|
||||
dest_files=["res://.godot/imported/planted.png-2c23372e71d0997d310374f47bb48594.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
|
||||
|
Before Width: | Height: | Size: 96 KiB After Width: | Height: | Size: 96 KiB |
@@ -3,15 +3,15 @@
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://c6vby5r0pfni2"
|
||||
path="res://.godot/imported/default_plant.png-bbc4a8928e27ae5fc30489a97257bdb9.ctex"
|
||||
path="res://.godot/imported/default_plant.png-0e29f01fe7666058a9a8c53076d3ea4d.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://entities/interactables/plants/assets/sprites/default_plant.png"
|
||||
dest_files=["res://.godot/imported/default_plant.png-bbc4a8928e27ae5fc30489a97257bdb9.ctex"]
|
||||
source_file="res://entities/plants/assets/sprites/default_plant.png"
|
||||
dest_files=["res://.godot/imported/default_plant.png-0e29f01fe7666058a9a8c53076d3ea4d.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
|
Before Width: | Height: | Size: 169 KiB After Width: | Height: | Size: 169 KiB |
@@ -3,15 +3,15 @@
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://b3wom2xu26g43"
|
||||
path="res://.godot/imported/default_plant_glowing.png-09ba534646a860193c36fa40d5f83142.ctex"
|
||||
path="res://.godot/imported/default_plant_glowing.png-1922303555901146cff9778bc5fe2dcb.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://entities/interactables/plants/assets/sprites/default_plant_glowing.png"
|
||||
dest_files=["res://.godot/imported/default_plant_glowing.png-09ba534646a860193c36fa40d5f83142.ctex"]
|
||||
source_file="res://entities/plants/assets/sprites/default_plant_glowing.png"
|
||||
dest_files=["res://.godot/imported/default_plant_glowing.png-1922303555901146cff9778bc5fe2dcb.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
[gd_scene load_steps=8 format=3 uid="uid://clpcqkdlj3d8e"]
|
||||
[gd_scene load_steps=6 format=3 uid="uid://clpcqkdlj3d8e"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cega715smavh3" path="res://entities/interactables/plants/scripts/plant.gd" id="1_d8u7e"]
|
||||
[ext_resource type="Script" uid="uid://yutflvdgdk04" path="res://entities/interactables/scripts/interactable_action.gd" id="2_rs46h"]
|
||||
[ext_resource type="Resource" uid="uid://bk0kop0m75pjy" path="res://entities/interactables/resources/actions/default_water_plant.tres" id="3_5foug"]
|
||||
[ext_resource type="Texture2D" uid="uid://c6vby5r0pfni2" path="res://entities/interactables/plants/assets/sprites/default_plant.png" id="4_dq24f"]
|
||||
[ext_resource type="Texture2D" uid="uid://b3wom2xu26g43" path="res://entities/interactables/plants/assets/sprites/default_plant_glowing.png" id="5_2gcie"]
|
||||
[ext_resource type="Script" uid="uid://cega715smavh3" path="res://entities/plants/scripts/plant.gd" id="1_d8u7e"]
|
||||
[ext_resource type="Texture2D" uid="uid://c6vby5r0pfni2" path="res://entities/plants/assets/sprites/default_plant.png" id="4_dq24f"]
|
||||
[ext_resource type="Texture2D" uid="uid://b3wom2xu26g43" path="res://entities/plants/assets/sprites/default_plant_glowing.png" id="5_2gcie"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_cdbrd"]
|
||||
|
||||
@@ -29,7 +27,6 @@ animations = [{
|
||||
|
||||
[node name="DefaultPlant" type="Area2D"]
|
||||
script = ExtResource("1_d8u7e")
|
||||
actions = Array[ExtResource("2_rs46h")]([ExtResource("3_5foug")])
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
scale = Vector2(4.01154, 4.01154)
|
||||
@@ -0,0 +1,8 @@
|
||||
[gd_resource type="Resource" script_class="DecontaminateTerrainEffect" load_steps=2 format=3 uid="uid://bdddlia6qxgf2"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cgscbuxe4dawb" path="res://entities/plants/scripts/plant_effects/decontaminate_terrain_effect.gd" id="1_8l07v"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_8l07v")
|
||||
impact_radius = 50
|
||||
metadata/_custom_type_script = "uid://cgscbuxe4dawb"
|
||||
21
entities/plants/resources/plants/default.tres
Normal file
@@ -0,0 +1,21 @@
|
||||
[gd_resource type="Resource" script_class="PlantType" load_steps=7 format=3 uid="uid://dmbu538b3utec"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://c7mp7tkkkk6o5" path="res://entities/plants/assets/sprites/default/growing.png" id="1_fp5j6"]
|
||||
[ext_resource type="Script" uid="uid://jnye5pe1bgqw" path="res://entities/plants/scripts/plant_type.gd" id="1_moyj3"]
|
||||
[ext_resource type="Script" uid="uid://cgscbuxe4dawb" path="res://entities/plants/scripts/plant_effects/decontaminate_terrain_effect.gd" id="2_cky1j"]
|
||||
[ext_resource type="Texture2D" uid="uid://bupl1y0cfj21q" path="res://entities/plants/assets/sprites/default/mature.png" id="3_ffarr"]
|
||||
[ext_resource type="Texture2D" uid="uid://ba413oun7ry78" path="res://entities/plants/assets/sprites/default/planted.png" id="4_2s6re"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_q68uy"]
|
||||
script = ExtResource("2_cky1j")
|
||||
impact_radius = 100
|
||||
metadata/_custom_type_script = "uid://cgscbuxe4dawb"
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_moyj3")
|
||||
growing_time = 2
|
||||
planted_texture = ExtResource("4_2s6re")
|
||||
growing_texture = ExtResource("1_fp5j6")
|
||||
mature_texture = ExtResource("3_ffarr")
|
||||
mature_effect = SubResource("Resource_q68uy")
|
||||
metadata/_custom_type_script = "uid://jnye5pe1bgqw"
|
||||
66
entities/plants/scripts/plant.gd
Normal file
@@ -0,0 +1,66 @@
|
||||
extends Node2D
|
||||
class_name Plant
|
||||
|
||||
const PLANT_AREA_WIDTH = 10
|
||||
const PLANT_SPRITE_SCALE = 0.15
|
||||
|
||||
enum State {PLANTED, GROWING, MATURE}
|
||||
|
||||
var plant_type : PlantType
|
||||
var planet : Planet
|
||||
|
||||
var state : State = State.PLANTED : set = change_state
|
||||
var day : int = 0
|
||||
|
||||
@onready var plant_sprite : Sprite2D = generate_sprite()
|
||||
@onready var plant_area : Area2D = generate_area()
|
||||
|
||||
func _init(_plant_type, _planet):
|
||||
plant_type = _plant_type
|
||||
planet = _planet
|
||||
|
||||
func generate_sprite() -> Sprite2D:
|
||||
var sprite = Sprite2D.new()
|
||||
|
||||
add_child(sprite)
|
||||
sprite.texture = get_state_texture(state)
|
||||
sprite.scale = Vector2.ONE * PLANT_SPRITE_SCALE
|
||||
sprite.offset
|
||||
|
||||
return sprite
|
||||
|
||||
func generate_area() -> Area2D:
|
||||
var area = Area2D.new()
|
||||
var collision = CollisionShape2D.new()
|
||||
var collision_shape = CircleShape2D.new()
|
||||
collision_shape.radius = PLANT_AREA_WIDTH
|
||||
|
||||
collision.shape = collision_shape
|
||||
area.add_child(collision)
|
||||
add_child(area)
|
||||
|
||||
return area
|
||||
|
||||
func pass_day():
|
||||
day += 1
|
||||
if day > plant_type.growing_time:
|
||||
change_state(State.MATURE)
|
||||
else:
|
||||
change_state(State.GROWING)
|
||||
|
||||
func change_state(_state : State):
|
||||
state = _state
|
||||
plant_sprite.texture = get_state_texture(state)
|
||||
|
||||
if state == State.MATURE and plant_type.mature_effect:
|
||||
plant_type.mature_effect.effect(self)
|
||||
|
||||
func get_state_texture(s : State) -> Texture2D:
|
||||
match s:
|
||||
State.PLANTED:
|
||||
return plant_type.planted_texture
|
||||
State.GROWING:
|
||||
return plant_type.growing_texture
|
||||
State.MATURE:
|
||||
return plant_type.mature_texture
|
||||
return null
|
||||
7
entities/plants/scripts/plant_effect.gd
Normal file
@@ -0,0 +1,7 @@
|
||||
# Classe abstraite permettant de développer divers effets de plantes
|
||||
extends Resource
|
||||
class_name PlantEffect
|
||||
|
||||
func effect(plant):
|
||||
printerr("Classe abstraite PlantEffect appelée")
|
||||
|
||||
1
entities/plants/scripts/plant_effect.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bpycohqas4hff
|
||||
@@ -0,0 +1,10 @@
|
||||
extends PlantEffect
|
||||
class_name DecontaminateTerrainEffect
|
||||
|
||||
@export var impact_radius = 50
|
||||
|
||||
func effect(plant):
|
||||
plant.planet.impact_contamination(
|
||||
plant.global_position,
|
||||
impact_radius
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
uid://cgscbuxe4dawb
|
||||
11
entities/plants/scripts/plant_type.gd
Normal file
@@ -0,0 +1,11 @@
|
||||
extends Resource
|
||||
class_name PlantType
|
||||
|
||||
@export var growing_time : int
|
||||
|
||||
@export var seed_texture : Texture
|
||||
@export var planted_texture : Texture
|
||||
@export var growing_texture : Texture
|
||||
@export var mature_texture : Texture
|
||||
|
||||
@export var mature_effect : PlantEffect
|
||||
1
entities/plants/scripts/plant_type.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://jnye5pe1bgqw
|
||||
@@ -3,10 +3,15 @@ class_name Player
|
||||
|
||||
signal player_stats_updated(player : Player)
|
||||
|
||||
var controlling_player : bool = true
|
||||
var planet : Planet # mis à jour par la classe Planet
|
||||
@export var speed = 400
|
||||
|
||||
var energy : int = 10 :
|
||||
@export var testPlantType : PlantType
|
||||
|
||||
var max_energy : int = 10
|
||||
|
||||
var energy : int = max_energy :
|
||||
set(v):
|
||||
energy = v
|
||||
emit_signal("player_stats_updated", self)
|
||||
@@ -15,10 +20,11 @@ func _ready():
|
||||
emit_signal("player_stats_updated", self)
|
||||
|
||||
func get_input():
|
||||
calculate_direction()
|
||||
if controlling_player:
|
||||
calculate_direction()
|
||||
|
||||
if Input.is_action_just_pressed("interact") and energy > 0:
|
||||
try_interact()
|
||||
if Input.is_action_just_pressed("action") and energy > 0:
|
||||
action()
|
||||
|
||||
func calculate_direction():
|
||||
var input_direction : Vector2 = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
@@ -26,24 +32,25 @@ func calculate_direction():
|
||||
if input_direction.x:
|
||||
$Sprite.flip_h = (input_direction.x < 0)
|
||||
|
||||
func try_interact():
|
||||
var interactables : Array[Interactable]
|
||||
|
||||
for area2D in $InteractArea2D.get_overlapping_areas():
|
||||
if area2D is Interactable:
|
||||
interactables.push_front(area2D)
|
||||
func action():
|
||||
if planet:
|
||||
planet.plant(
|
||||
testPlantType,
|
||||
global_position
|
||||
)
|
||||
|
||||
if len(interactables):
|
||||
if len(interactables) > 1:
|
||||
# Sort them to the closer
|
||||
interactables.sort_custom(
|
||||
func (el1 : Interactable, el2 : Interactable):
|
||||
return el1.global_position.distance_to(global_position) > el2.global_position.distance_to(global_position)
|
||||
)
|
||||
|
||||
interactables[0].interact(self)
|
||||
energy -= 1
|
||||
func pass_day():
|
||||
energy = max_energy
|
||||
|
||||
func _physics_process(_delta):
|
||||
get_input()
|
||||
move_and_slide()
|
||||
|
||||
func _on_root_gui_day_pass_pressed():
|
||||
controlling_player = false
|
||||
|
||||
func _on_root_gui_day_pass_finished():
|
||||
controlling_player = true
|
||||
|
||||
func _on_root_gui_game_click():
|
||||
action()
|
||||
|
||||