back end degat vie

This commit is contained in:
Elouan 2025-01-25 02:33:26 +01:00
parent c3d84f1e17
commit 7b66e219b2
8 changed files with 138 additions and 14 deletions

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=14 format=3 uid="uid://durhes43gex7a"]
[gd_scene load_steps=15 format=3 uid="uid://durhes43gex7a"]
[ext_resource type="PackedScene" uid="uid://c7bfiw54rvaq2" path="res://scenes/player_melodie.tscn" id="1_cl1wt"]
[ext_resource type="Script" path="res://scenes/room.gd" id="1_jh83c"]
@ -8,7 +8,8 @@
[ext_resource type="Texture2D" uid="uid://bge3nllk1bq5r" path="res://ressources/images/mur.svg" id="3_oi2tl"]
[ext_resource type="Texture2D" uid="uid://dhva3tivsvknl" path="res://ressources/images/mur_coin.svg" id="4_6a3f6"]
[ext_resource type="PackedScene" uid="uid://di4chlep1t1or" path="res://parametres/menu_parametres.tscn" id="6_6ubhx"]
[ext_resource type="PackedScene" uid="uid://cnd2a1x1smulq" path="res://scenes/interface.tscn" id="8_5s7tf"]
[ext_resource type="PackedScene" uid="uid://bndtclt51nsih" path="res://scenes/interface.tscn" id="8_5s7tf"]
[ext_resource type="PackedScene" uid="uid://cm5spgl8o4fam" path="res://scenes/enemies/robot.tscn" id="10_5qrsc"]
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_1c4te"]
normal = Vector2(0, 1)
@ -42,8 +43,9 @@ offset_bottom = 360.0
texture = ExtResource("2_torsx")
stretch_mode = 1
[node name="Player_Melodie" parent="." instance=ExtResource("1_cl1wt")]
[node name="Player_Melodie" parent="." node_paths=PackedStringArray("interface") groups=["Player"] instance=ExtResource("1_cl1wt")]
scale = Vector2(3, 3)
interface = NodePath("../Interface")
[node name="StaticBody2D" type="StaticBody2D" parent="." groups=["World_Border"]]
collision_layer = 3
@ -148,4 +150,7 @@ offset_top = -360.0
offset_right = -640.0
offset_bottom = -360.0
[node name="Robot" parent="." groups=["Enemies"] instance=ExtResource("10_5qrsc")]
position = Vector2(-428, 11)
[connection signal="finished" from="Musique" to="." method="_on_audio_stream_player_finished"]

48
scenes/enemies/robot.gd Normal file
View file

@ -0,0 +1,48 @@
extends CharacterBody2D
const SPEED = 50.0
@onready var player = get_parent().get_node("Player_Melodie")
var player_position = Vector2.ZERO
var target_position = Vector2.ZERO
var move_timer = 1
var vie = 3
var balle = null
var Balle = null
func _ready() -> void:
Balle = load("res://scenes/enemies/robotCercle.tscn")
func take_damage(dmg : int) :
vie -= dmg
if vie <= 0:
queue_free()
func _physics_process(delta: float) -> void:
player_position = player.position
target_position = (player_position - position).normalized()
move_and_slide()
func _process(delta: float) -> void:
var direction : Vector2
move_timer -= delta
if move_timer < 0:
attaquer_joueur()
move_timer = 1
$AnimatedSprite2D.play("Generic")
velocity = target_position * SPEED
func attaquer_joueur() -> void:
balle = Balle.instantiate()
balle.set_direction(target_position)
balle.position = position
get_parent().add_child(balle)

37
scenes/enemies/robot.tscn Normal file
View file

@ -0,0 +1,37 @@
[gd_scene load_steps=7 format=3 uid="uid://cm5spgl8o4fam"]
[ext_resource type="Texture2D" uid="uid://dwwe0eanmrcra" path="res://ressources/images/roby-idle-0.png" id="1_mo3hb"]
[ext_resource type="Script" path="res://scenes/enemies/robot.gd" id="1_tikkk"]
[ext_resource type="Texture2D" uid="uid://8m84oe4oes3u" path="res://ressources/images/roby-idle-1.png" id="2_4n77m"]
[ext_resource type="Texture2D" uid="uid://dcyf6teijpttj" path="res://ressources/images/roby-idle-2.png" id="3_8bmqk"]
[sub_resource type="SpriteFrames" id="SpriteFrames_vaeha"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": ExtResource("1_mo3hb")
}, {
"duration": 1.0,
"texture": ExtResource("2_4n77m")
}, {
"duration": 1.0,
"texture": ExtResource("3_8bmqk")
}],
"loop": true,
"name": &"Generic",
"speed": 5.0
}]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_utjf8"]
size = Vector2(126, 185)
[node name="Robot" type="CharacterBody2D"]
script = ExtResource("1_tikkk")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
sprite_frames = SubResource("SpriteFrames_vaeha")
animation = &"Generic"
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(-2, 6.5)
shape = SubResource("RectangleShape2D_utjf8")

View file

@ -0,0 +1,18 @@
[gd_scene load_steps=4 format=3 uid="uid://bevw5uqw42vfh"]
[ext_resource type="Script" path="res://scenes/enemies/robot_cercle.gd" id="1_3gn1u"]
[ext_resource type="Texture2D" uid="uid://b5ui24x0341jh" path="res://ressources/images/roby-cercle.png" id="2_j4tla"]
[sub_resource type="CircleShape2D" id="CircleShape2D_6j0u0"]
radius = 96.8762
[node name="Robotcercle" type="Area2D"]
script = ExtResource("1_3gn1u")
[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("2_j4tla")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_6j0u0")
[connection signal="body_entered" from="." to="." method="Collision"]

View file

@ -0,0 +1,19 @@
extends Area2D
var direction = Vector2.ZERO
var timer = 0.0
var cooldown = 0.7
func _process(delta: float) -> void:
timer += delta
if timer >= cooldown:
queue_free()
func set_direction(direction: Vector2) -> void:
self.direction = direction
func Collision(body: Node2D) -> void:
if body.is_in_group("Player"):
body.take_damage(3)

View file

@ -42,9 +42,3 @@ func _process(delta: float) -> void:
$AnimatedSprite2D.play("Generic")
velocity = direction * SPEED
func Collision(body: Node2D) -> void:
print(body)
if body.is_in_group("Player") :
body.take_damage(1)

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=4 format=3 uid="uid://cnd2a1x1smulq"]
[gd_scene load_steps=4 format=3 uid="uid://bndtclt51nsih"]
[ext_resource type="Script" path="res://scenes/interface.gd" id="1_5p24o"]
[ext_resource type="Texture2D" uid="uid://jyrl33rv1fnp" path="res://ressources/images/full_heart.svg" id="2_opn3r"]

View file

@ -1,5 +1,7 @@
extends CharacterBody2D
@export var interface : Control
const move_speed = 400
const acceleration = 0.25
const max_boost_speed = 800
@ -19,21 +21,22 @@ var flute_cooldown = 0.5
var tambour_cooldown = 3.0
var lyre_cooldown = 1
var slot = [null, null]
var slot = []
var slotstr = []
var vie = 10
func _ready() -> void:
flute = load("res://scripts/Instrument/Flute.gd").new()
flute.set_scene_parent(get_tree().get_root())
slot.append(flute)
tambour = load("res://scripts/Instrument/Tambour.gd").new()
tambour.set_scene_parent(get_tree().get_root())
lyre = load("res://scripts/Instrument/Lyre.gd").new()
lyre.set_scene_parent(get_tree().get_root())
slot.append(lyre)
func _physics_process(delta: float) -> void:
@ -103,6 +106,6 @@ func _process(delta: float) -> void:
func take_damage(dmg : int) :
vie -= dmg
print(vie)
interface.set_life(vie)
if vie <= 0:
queue_free()