Compare commits
2 Commits
b60c445592
...
665e3d4928
| Author | SHA1 | Date | |
|---|---|---|---|
| 665e3d4928 | |||
| 4c089dddd6 |
BIN
entities/interactables/plants/assets/sprites/default_plant.png
Normal file
BIN
entities/interactables/plants/assets/sprites/default_plant.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 96 KiB |
@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://c6vby5r0pfni2"
|
||||
path="res://.godot/imported/default_plant.png-bbc4a8928e27ae5fc30489a97257bdb9.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"]
|
||||
|
||||
[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
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 169 KiB |
@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://b3wom2xu26g43"
|
||||
path="res://.godot/imported/default_plant_glowing.png-09ba534646a860193c36fa40d5f83142.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"]
|
||||
|
||||
[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
|
||||
40
entities/interactables/plants/default_plant.tscn
Normal file
40
entities/interactables/plants/default_plant.tscn
Normal file
@ -0,0 +1,40 @@
|
||||
[gd_scene load_steps=8 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"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_cdbrd"]
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_ocwgi"]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("4_dq24f")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"default",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("5_2gcie")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"watered",
|
||||
"speed": 5.0
|
||||
}]
|
||||
|
||||
[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)
|
||||
shape = SubResource("CircleShape2D_cdbrd")
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||
scale = Vector2(0.160462, 0.160462)
|
||||
sprite_frames = SubResource("SpriteFrames_ocwgi")
|
||||
8
entities/interactables/plants/scripts/plant.gd
Normal file
8
entities/interactables/plants/scripts/plant.gd
Normal file
@ -0,0 +1,8 @@
|
||||
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")
|
||||
1
entities/interactables/plants/scripts/plant.gd.uid
Normal file
1
entities/interactables/plants/scripts/plant.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://cega715smavh3
|
||||
@ -0,0 +1,7 @@
|
||||
[gd_resource type="Resource" script_class="WaterPlantAction" load_steps=2 format=3 uid="uid://bk0kop0m75pjy"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bb38yqsd072ws" path="res://entities/interactables/scripts/actions/water_plant.gd" id="1_ghdb0"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_ghdb0")
|
||||
metadata/_custom_type_script = "uid://bb38yqsd072ws"
|
||||
8
entities/interactables/scripts/actions/water_plant.gd
Normal file
8
entities/interactables/scripts/actions/water_plant.gd
Normal file
@ -0,0 +1,8 @@
|
||||
extends InteractableAction
|
||||
class_name WaterPlantAction
|
||||
|
||||
func action(_p: Player, _i : Interactable):
|
||||
if _i is Plant:
|
||||
_i.watered = true
|
||||
else :
|
||||
printerr("No plant selected or interactable is not a plant")
|
||||
@ -0,0 +1 @@
|
||||
uid://bb38yqsd072ws
|
||||
8
entities/interactables/scripts/interactable.gd
Normal file
8
entities/interactables/scripts/interactable.gd
Normal file
@ -0,0 +1,8 @@
|
||||
extends Area2D
|
||||
class_name Interactable
|
||||
|
||||
@export var actions : Array[InteractableAction] = [];
|
||||
|
||||
func interact(p : Player):
|
||||
for a in actions:
|
||||
a.action(p, self)
|
||||
1
entities/interactables/scripts/interactable.gd.uid
Normal file
1
entities/interactables/scripts/interactable.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://dyprcd68fjstf
|
||||
6
entities/interactables/scripts/interactable_action.gd
Normal file
6
entities/interactables/scripts/interactable_action.gd
Normal file
@ -0,0 +1,6 @@
|
||||
# Classe abstraite permettant de développer diverses actions
|
||||
extends Resource
|
||||
class_name InteractableAction
|
||||
|
||||
func action(_p: Player, _i : Interactable):
|
||||
printerr("Méthode action de la classe abstraite InteractableAction appelée")
|
||||
@ -0,0 +1 @@
|
||||
uid://yutflvdgdk04
|
||||
@ -1,10 +1,13 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://bgvbgeq46wee2"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://bgvbgeq46wee2"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://das7twcy5153p" path="res://entities/player/scripts/player.gd" id="1_abrql"]
|
||||
[ext_resource type="Texture2D" uid="uid://c7ff87jniga5m" path="res://entities/player/assets/sprites/robot.png" id="1_symyc"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_sglur"]
|
||||
radius = 38.0526
|
||||
radius = 27.0
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_abrql"]
|
||||
radius = 40.0
|
||||
|
||||
[node name="Player" type="CharacterBody2D"]
|
||||
script = ExtResource("1_abrql")
|
||||
@ -15,4 +18,11 @@ scale = Vector2(0.084375, 0.084375)
|
||||
texture = ExtResource("1_symyc")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(-2, 15)
|
||||
shape = SubResource("CircleShape2D_sglur")
|
||||
|
||||
[node name="InteractArea2D" type="Area2D" parent="."]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="InteractArea2D"]
|
||||
position = Vector2(0, 37)
|
||||
shape = SubResource("CircleShape2D_abrql")
|
||||
|
||||
@ -4,11 +4,33 @@ class_name Player
|
||||
@export var speed = 400
|
||||
|
||||
func get_input():
|
||||
calculate_direction()
|
||||
|
||||
if Input.is_action_just_pressed("interact"):
|
||||
try_interact()
|
||||
|
||||
func calculate_direction():
|
||||
var input_direction : Vector2 = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
velocity = input_direction * speed
|
||||
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)
|
||||
|
||||
if len(interactables):
|
||||
if len(interactables) > 1:
|
||||
# Sort them to the closer
|
||||
interactables.sort_custom(
|
||||
func (el : Interactable): return el.global_position.distance_to(global_position)
|
||||
)
|
||||
|
||||
interactables[0].interact(self)
|
||||
|
||||
func _physics_process(_delta):
|
||||
get_input()
|
||||
move_and_slide()
|
||||
move_and_slide()
|
||||
|
||||
@ -41,3 +41,8 @@ move_down={
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
interact={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(222, 14),"global_position":Vector2(231, 62),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
11
readme.md
11
readme.md
@ -93,6 +93,17 @@ Pour ajouter un ou plusieurs fichiers ou modifier du code dans le projet, suivez
|
||||
2. Après la modification conséquente, créer un commit. Les noms des commits sont écrits en français et peuvent commencer par l'identifiant du ticket concernant la modification (exemple: `#8 ajout des sprites des plantes`)
|
||||
3. Pousser votre modification (`git push` dans un terminal ou via interface git)
|
||||
|
||||
### Règle de developpement
|
||||
|
||||
#### Nommage
|
||||
|
||||
1. Les variables et les fonctions sont nommées en minuscule avec les mots séparé par un underscore "_" (en snake case)
|
||||
2. Les constantes sont nommées en majuscule avec les mots séparé par un underscore "_" (en upper snake case)
|
||||
3. Les classes commencent pas une majuscule avec les mots séparé par une majuscule (en pascal case)
|
||||
4. Les signaux sont nommés en snake case, et doivent avoir un verbe au participe passé (exemple: `energy_updated`)
|
||||
|
||||
> Dans Godot, les instances de nodes sont appelée en pascal case
|
||||
|
||||
## Troubleshoot
|
||||
|
||||
### Sur Godot, fenêtre "File have been modified outside Godot"
|
||||
|
||||
33
root.tscn
33
root.tscn
@ -1,8 +1,9 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://c5bruelvqbm1k"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://c5bruelvqbm1k"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://tsi5j1uxppa4" path="res://stages/planet/planet.tscn" id="1_pyidc"]
|
||||
[ext_resource type="PackedScene" uid="uid://bgvbgeq46wee2" path="res://entities/player/player.tscn" id="2_vvh5c"]
|
||||
[ext_resource type="PackedScene" uid="uid://dj7gp3crtg2yt" path="res://entities/camera/camera.tscn" id="3_vvh5c"]
|
||||
[ext_resource type="PackedScene" uid="uid://clpcqkdlj3d8e" path="res://entities/interactables/plants/default_plant.tscn" id="4_28aoi"]
|
||||
|
||||
[node name="Root" type="Node2D"]
|
||||
|
||||
@ -13,3 +14,33 @@
|
||||
[node name="Camera" parent="." node_paths=PackedStringArray("following") instance=ExtResource("3_vvh5c")]
|
||||
position = Vector2(2.22, 0)
|
||||
following = NodePath("../Player")
|
||||
|
||||
[node name="DefaultPlant" parent="." instance=ExtResource("4_28aoi")]
|
||||
position = Vector2(195, 37)
|
||||
|
||||
[node name="DefaultPlant2" parent="." instance=ExtResource("4_28aoi")]
|
||||
position = Vector2(114, -40)
|
||||
|
||||
[node name="DefaultPlant3" parent="." instance=ExtResource("4_28aoi")]
|
||||
position = Vector2(-222, 138)
|
||||
|
||||
[node name="DefaultPlant4" parent="." instance=ExtResource("4_28aoi")]
|
||||
position = Vector2(-186, -96)
|
||||
|
||||
[node name="DefaultPlant5" parent="." instance=ExtResource("4_28aoi")]
|
||||
position = Vector2(-7, 150)
|
||||
|
||||
[node name="DefaultPlant6" parent="." instance=ExtResource("4_28aoi")]
|
||||
position = Vector2(-19, -102)
|
||||
|
||||
[node name="DefaultPlant7" parent="." instance=ExtResource("4_28aoi")]
|
||||
position = Vector2(-115, 50)
|
||||
|
||||
[node name="DefaultPlant8" parent="." instance=ExtResource("4_28aoi")]
|
||||
position = Vector2(147, -173)
|
||||
|
||||
[node name="DefaultPlant9" parent="." instance=ExtResource("4_28aoi")]
|
||||
position = Vector2(98, 90)
|
||||
|
||||
[node name="DefaultPlant10" parent="." instance=ExtResource("4_28aoi")]
|
||||
position = Vector2(-269, 1)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user