items/fromages: la princesse peut manger un fromage
En vrai, pour l'instant voilà ce qui est fait: - le fromage existe et est plaçable sur le niveau à convenance. Autant qu'on veut. - le fromage est une entité autonome dans ses animations et c'est lui qui va enoyer un signal à la princesse quand elle rentre en collision avec lui. Reste à mettre en place: - Un timer pour faire réaparaitre le fromage - Un affichager de jauge à prout pour la princesse
This commit is contained in:
@@ -5,12 +5,12 @@
|
||||
|
||||
[node name="game" type="Node"]
|
||||
|
||||
[node name="Node2D" parent="." instance=ExtResource("1_qv57y")]
|
||||
[node name="level" parent="." instance=ExtResource("1_qv57y")]
|
||||
light_mask = 1
|
||||
visibility_layer = 1
|
||||
position = Vector2(1, 10)
|
||||
|
||||
[node name="Princesse" parent="Node2D" instance=ExtResource("2_0ku48")]
|
||||
[node name="Princesse" parent="level" instance=ExtResource("2_0ku48")]
|
||||
position = Vector2(-137, -46)
|
||||
scale = Vector2(0.6, 0.6)
|
||||
collision_mask = 60
|
||||
collision_mask = 112
|
||||
|
||||
11
items/fromage_normal.gd
Normal file
11
items/fromage_normal.gd
Normal file
@@ -0,0 +1,11 @@
|
||||
class_name normal_cheese extends Area2D
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
131
items/fromage_normal.tscn
Normal file
131
items/fromage_normal.tscn
Normal file
@@ -0,0 +1,131 @@
|
||||
[gd_scene load_steps=9 format=3 uid="uid://bfff6uggijk4k"]
|
||||
|
||||
[ext_resource type="Script" path="res://items/normal_cheese.gd" id="1_2l3x1"]
|
||||
[ext_resource type="Texture2D" uid="uid://blh8aqj3ojadf" path="res://sprite/items.png" id="1_rx0yq"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_7rdb1"]
|
||||
atlas = ExtResource("1_rx0yq")
|
||||
region = Rect2(16, 0, 16, 16)
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_xry4i"]
|
||||
radius = 6.0
|
||||
|
||||
[sub_resource type="Animation" id="Animation_r46qo"]
|
||||
resource_name = "RESET"
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite2D:position")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Vector2(0, 0)]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = false
|
||||
tracks/1/path = NodePath("Sprite2D:modulate")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(),
|
||||
"transitions": PackedFloat32Array(),
|
||||
"update": 0,
|
||||
"values": []
|
||||
}
|
||||
tracks/2/type = "value"
|
||||
tracks/2/imported = false
|
||||
tracks/2/enabled = true
|
||||
tracks/2/path = NodePath("Sprite2D:self_modulate")
|
||||
tracks/2/interp = 1
|
||||
tracks/2/loop_wrap = true
|
||||
tracks/2/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Color(1, 1, 1, 1)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_fpj7j"]
|
||||
resource_name = "cheese"
|
||||
loop_mode = 1
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite2D:position")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0.1, 0.5, 1),
|
||||
"transitions": PackedFloat32Array(1, 1, 1),
|
||||
"update": 0,
|
||||
"values": [Vector2(0, 0), Vector2(0, -2), Vector2(0, 0)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_jemsl"]
|
||||
resource_name = "picked"
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite2D:position")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0.1, 1),
|
||||
"transitions": PackedFloat32Array(1, 2.2974),
|
||||
"update": 0,
|
||||
"values": [Vector2(0, 0), Vector2(0, -50)]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = false
|
||||
tracks/1/path = NodePath(".:modulate")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(),
|
||||
"transitions": PackedFloat32Array(),
|
||||
"update": 0,
|
||||
"values": []
|
||||
}
|
||||
tracks/2/type = "value"
|
||||
tracks/2/imported = false
|
||||
tracks/2/enabled = true
|
||||
tracks/2/path = NodePath("Sprite2D:self_modulate")
|
||||
tracks/2/interp = 1
|
||||
tracks/2/loop_wrap = true
|
||||
tracks/2/keys = {
|
||||
"times": PackedFloat32Array(0.1, 1),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 0,
|
||||
"values": [Color(1, 1, 1, 1), Color(1, 1, 1, 0)]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_4iwa0"]
|
||||
_data = {
|
||||
"RESET": SubResource("Animation_r46qo"),
|
||||
"cheese": SubResource("Animation_fpj7j"),
|
||||
"picked": SubResource("Animation_jemsl")
|
||||
}
|
||||
|
||||
[node name="Fromage normal" type="Area2D"]
|
||||
collision_layer = 64
|
||||
script = ExtResource("1_2l3x1")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture = SubResource("AtlasTexture_7rdb1")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("CircleShape2D_xry4i")
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
autoplay = "cheese"
|
||||
libraries = {
|
||||
"": SubResource("AnimationLibrary_4iwa0")
|
||||
}
|
||||
|
||||
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
||||
8
items/normal_cheese.gd
Normal file
8
items/normal_cheese.gd
Normal file
@@ -0,0 +1,8 @@
|
||||
class_name NormalCheese extends Area2D
|
||||
|
||||
|
||||
@onready var animation_player := $AnimationPlayer as AnimationPlayer
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
animation_player.play(&"picked")
|
||||
(body as Princess).cheese_collected.emit()
|
||||
File diff suppressed because one or more lines are too long
31
princesse.gd
31
princesse.gd
@@ -1,4 +1,4 @@
|
||||
extends CharacterBody2D
|
||||
class_name Princess extends CharacterBody2D
|
||||
|
||||
## The player listens for input actions appended with this suffix.[br]
|
||||
## Used to separate controls for multiple players in splitscreen.
|
||||
@@ -39,6 +39,7 @@ var gravity: int = ProjectSettings.get("physics/2d/default_gravity")
|
||||
@export var WALK_INCR_GROUND : int = 1
|
||||
@export var WALK_INCR_AIR : int = 3
|
||||
|
||||
signal cheese_collected()
|
||||
|
||||
################################################################################
|
||||
#
|
||||
@@ -348,21 +349,6 @@ func compute_state() -> void:
|
||||
# gestion de l'état de la pression au mur
|
||||
pressing_wall = not is_on_floor() and (wall_detect_left.is_colliding() or wall_detect_right.is_colliding())
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
compute_state()
|
||||
read_input()
|
||||
|
||||
velocity.y = jump()
|
||||
velocity.y = fall()
|
||||
velocity.x = walk(direction)
|
||||
kick()
|
||||
|
||||
move_and_handle_collisions()
|
||||
|
||||
play_animation()
|
||||
|
||||
|
||||
func get_new_animation() -> String:
|
||||
# Renvoie la bonne annimation en fonction de l'état de la princesse
|
||||
var animation_new: String
|
||||
@@ -384,3 +370,16 @@ func get_new_animation() -> String:
|
||||
else:
|
||||
animation_new = "jumping"
|
||||
return animation_new
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
compute_state()
|
||||
read_input()
|
||||
velocity.y = jump()
|
||||
velocity.y = fall()
|
||||
velocity.x = walk(direction)
|
||||
kick()
|
||||
move_and_handle_collisions()
|
||||
play_animation()
|
||||
|
||||
func reload_fart() -> void:
|
||||
print("pouet")
|
||||
|
||||
@@ -200,6 +200,7 @@ animations = [{
|
||||
height = 52.0
|
||||
|
||||
[node name="Princesse" type="CharacterBody2D"]
|
||||
collision_mask = 113
|
||||
slide_on_ceiling = false
|
||||
floor_constant_speed = true
|
||||
script = ExtResource("1_dkp7s")
|
||||
@@ -235,3 +236,5 @@ shape = SubResource("CapsuleShape2D_6r7th")
|
||||
[node name="ground_far_detect" type="RayCast2D" parent="."]
|
||||
target_position = Vector2(0, 38)
|
||||
collision_mask = 16
|
||||
|
||||
[connection signal="cheese_collected" from="." to="." method="reload_fart"]
|
||||
|
||||
Reference in New Issue
Block a user