feat: add enemy node; add player/enemy collision; add player hp to the scene manager; add hit by enemy logic;
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
[ext_resource type="PackedScene" uid="uid://orvnsdbeji56" path="res://Scenes/Block/block.tscn" id="8_n5fck"]
|
||||
[ext_resource type="PackedScene" uid="uid://cet4fk631cjyt" path="res://Scenes/Block/ice_block.tscn" id="10_u35dq"]
|
||||
[ext_resource type="PackedScene" uid="uid://bdu180bpjrn5h" path="res://Scenes/Switch/switch.tscn" id="12_g75ix"]
|
||||
[ext_resource type="AudioStream" uid="uid://w08sgqkkqa5p" path="res://Ninja Adventure - Asset Pack/Musics/2 - The Cave.ogg" id="13_x00t5"]
|
||||
|
||||
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_00mv7"]
|
||||
texture = ExtResource("5_102mq")
|
||||
@@ -710,6 +711,12 @@ position = Vector2(124, -21)
|
||||
[node name="Switch" parent="." unique_id=78052327 instance=ExtResource("12_g75ix")]
|
||||
position = Vector2(200, -24)
|
||||
|
||||
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="." unique_id=157733558]
|
||||
stream = ExtResource("13_x00t5")
|
||||
volume_db = -5.0
|
||||
autoplay = true
|
||||
parameters/looping = true
|
||||
|
||||
[connection signal="pressed" from="PuzzleButton" to="LockedDoor" method="_on_puzzle_button_pressed"]
|
||||
[connection signal="unpressed" from="PuzzleButton" to="LockedDoor" method="_on_puzzle_button_unpressed"]
|
||||
[connection signal="pressed" from="PuzzleButton2" to="LockedDoor" method="_on_puzzle_button_pressed"]
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
[gd_scene format=3 uid="uid://c1ehbmaja4lpg"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://cwejyda54idtw" path="res://Ninja Adventure - Asset Pack/Actor/Monsters/Slime/Slime.png" id="1_18say"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_3rdvi"]
|
||||
radius = 6.0827627
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_55qlh"]
|
||||
atlas = ExtResource("1_18say")
|
||||
region = Rect2(0, 0, 16, 16)
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_chgu2"]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_55qlh")
|
||||
}],
|
||||
"loop": 1,
|
||||
"name": &"default",
|
||||
"speed": 5.0
|
||||
}]
|
||||
|
||||
[node name="SlimeEnemy" type="CharacterBody2D" unique_id=384578683]
|
||||
collision_layer = 16
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=627034710]
|
||||
position = Vector2(0, 2)
|
||||
shape = SubResource("CircleShape2D_3rdvi")
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=1489783052]
|
||||
sprite_frames = SubResource("SpriteFrames_chgu2")
|
||||
@@ -13,6 +13,7 @@
|
||||
[ext_resource type="PackedScene" uid="uid://onpen57mc6i8" path="res://Scenes/PuzzleButton/puzzle_button.tscn" id="7_ohrk8"]
|
||||
[ext_resource type="PackedScene" uid="uid://bdu180bpjrn5h" path="res://Scenes/Switch/switch.tscn" id="8_njm7v"]
|
||||
[ext_resource type="PackedScene" uid="uid://bqcsg2t581j7b" path="res://Scenes/TreasureChest/treasure_chest.tscn" id="9_bkvnf"]
|
||||
[ext_resource type="PackedScene" uid="uid://c1ehbmaja4lpg" path="res://Scenes/Enemies/slime_enemy.tscn" id="10_6dkqd"]
|
||||
[ext_resource type="PackedScene" uid="uid://dsb83tlcapw8l" path="res://Scenes/NPC/npc.tscn" id="10_g3lhp"]
|
||||
[ext_resource type="AudioStream" uid="uid://bhl6upyji6aap" path="res://Ninja Adventure - Asset Pack/Musics/5 - Peaceful.ogg" id="15_rpdpv"]
|
||||
|
||||
@@ -833,6 +834,16 @@ text = "Green Ninja"
|
||||
[node name="Switch" parent="ObstacleLayer" unique_id=78052327 instance=ExtResource("8_njm7v")]
|
||||
position = Vector2(-8, -26)
|
||||
|
||||
[node name="Player" parent="ObstacleLayer" unique_id=1991398375 instance=ExtResource("1_2p8i2")]
|
||||
push_strength = 100
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="ObstacleLayer/Player" unique_id=1335060572]
|
||||
zoom = Vector2(5, 5)
|
||||
limit_left = -192
|
||||
limit_top = -144
|
||||
limit_right = 192
|
||||
limit_bottom = 160
|
||||
|
||||
[node name="TreasureChest" parent="ObstacleLayer" unique_id=2069908436 instance=ExtResource("9_bkvnf")]
|
||||
position = Vector2(-41, -19)
|
||||
|
||||
@@ -842,6 +853,9 @@ position = Vector2(15, -19)
|
||||
[node name="TreasureChest3" parent="ObstacleLayer" unique_id=267919049 instance=ExtResource("9_bkvnf")]
|
||||
position = Vector2(-79, -19)
|
||||
|
||||
[node name="SlimeEnemy" parent="ObstacleLayer" unique_id=384578683 instance=ExtResource("10_6dkqd")]
|
||||
position = Vector2(-26, 4)
|
||||
|
||||
[node name="SceneEntrance" parent="." unique_id=1734357035 instance=ExtResource("5_oi8ly")]
|
||||
position = Vector2(137, -107)
|
||||
collision_mask = 1
|
||||
@@ -854,16 +868,6 @@ script = ExtResource("7_nr542")
|
||||
position = Vector2(163, -75)
|
||||
lock_rotation = true
|
||||
|
||||
[node name="Player" parent="." unique_id=1991398375 instance=ExtResource("1_2p8i2")]
|
||||
push_strength = 100
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="Player" unique_id=1335060572]
|
||||
zoom = Vector2(5, 5)
|
||||
limit_left = -192
|
||||
limit_top = -144
|
||||
limit_right = 192
|
||||
limit_bottom = 160
|
||||
|
||||
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="." unique_id=1027726927]
|
||||
process_mode = 3
|
||||
stream = ExtResource("15_rpdpv")
|
||||
|
||||
+17
-4
@@ -8,6 +8,7 @@ class_name Player
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
update_scrolls()
|
||||
print("HP: ", SceneManager.player_hp)
|
||||
var damage: float = 2
|
||||
if SceneManager.player_next_scene_spawn_pos != Vector2(0, 0):
|
||||
position = SceneManager.player_next_scene_spawn_pos
|
||||
@@ -26,16 +27,16 @@ func move_player():
|
||||
|
||||
if velocity.x > 0:
|
||||
$AnimatedSprite2D.play("move_right")
|
||||
$Area2D.position = Vector2(5, 2)
|
||||
$InteractArea2D.position = Vector2(5, 2)
|
||||
elif velocity.x < 0:
|
||||
$AnimatedSprite2D.play("move_left")
|
||||
$Area2D.position = Vector2(-5, 2)
|
||||
$InteractArea2D.position = Vector2(-5, 2)
|
||||
elif velocity.y > 0:
|
||||
$AnimatedSprite2D.play("move_down")
|
||||
$Area2D.position = Vector2(0, 8)
|
||||
$InteractArea2D.position = Vector2(0, 8)
|
||||
elif velocity.y < 0:
|
||||
$AnimatedSprite2D.play("move_up")
|
||||
$Area2D.position = Vector2(0, -4)
|
||||
$InteractArea2D.position = Vector2(0, -4)
|
||||
else:
|
||||
$AnimatedSprite2D.stop()
|
||||
|
||||
@@ -59,3 +60,15 @@ func _on_area_2d_body_entered(body: Node2D) -> void:
|
||||
func _on_area_2d_body_exited(body: Node2D) -> void:
|
||||
if body.is_in_group("interactable"):
|
||||
body.can_interact = false
|
||||
|
||||
|
||||
func _on_hit_box_area_2d_body_entered(body: Node2D) -> void:
|
||||
SceneManager.player_hp -= 1
|
||||
print("HP: ", SceneManager.player_hp)
|
||||
if SceneManager.player_hp <= 0:
|
||||
die()
|
||||
|
||||
func die():
|
||||
print("DED")
|
||||
get_tree().call_deferred("reload_current_scene")
|
||||
SceneManager.player_hp = 3
|
||||
|
||||
@@ -143,6 +143,9 @@ animations = [{
|
||||
radius = 5.0
|
||||
height = 10.0
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_chgu2"]
|
||||
radius = 4.0
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_chgu2"]
|
||||
size = Vector2(8, 8)
|
||||
|
||||
@@ -162,10 +165,19 @@ animation = &"move_down"
|
||||
position = Vector2(0, 3)
|
||||
shape = SubResource("CapsuleShape2D_bqpwv")
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="." unique_id=145023444]
|
||||
[node name="HitBoxArea2D" type="Area2D" parent="." unique_id=1052547818]
|
||||
collision_layer = 2
|
||||
collision_mask = 16
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="HitBoxArea2D" unique_id=206980179]
|
||||
position = Vector2(0, 2)
|
||||
shape = SubResource("CircleShape2D_chgu2")
|
||||
debug_color = Color(0.99152297, 0, 0.27048782, 0.41960785)
|
||||
|
||||
[node name="InteractArea2D" type="Area2D" parent="." unique_id=145023444]
|
||||
collision_layer = 2
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D" unique_id=775673729]
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="InteractArea2D" unique_id=775673729]
|
||||
shape = SubResource("RectangleShape2D_chgu2")
|
||||
debug_color = Color(0.9427947, 0.09120729, 0.5535774, 0.41960785)
|
||||
|
||||
@@ -194,5 +206,6 @@ offset_right = 63.0
|
||||
offset_bottom = 62.0
|
||||
texture = ExtResource("3_xpcdj")
|
||||
|
||||
[connection signal="body_entered" from="Area2D" to="." method="_on_area_2d_body_entered"]
|
||||
[connection signal="body_exited" from="Area2D" to="." method="_on_area_2d_body_exited"]
|
||||
[connection signal="body_entered" from="HitBoxArea2D" to="." method="_on_hit_box_area_2d_body_entered"]
|
||||
[connection signal="body_entered" from="InteractArea2D" to="." method="_on_area_2d_body_entered"]
|
||||
[connection signal="body_exited" from="InteractArea2D" to="." method="_on_area_2d_body_exited"]
|
||||
|
||||
@@ -2,3 +2,4 @@ extends Node2D
|
||||
|
||||
var player_next_scene_spawn_pos: Vector2
|
||||
var opened_chests: Array[String] = []
|
||||
var player_hp: int = 3
|
||||
|
||||
@@ -44,6 +44,7 @@ Interact={
|
||||
2d_physics/layer_2="Player"
|
||||
2d_physics/layer_3="Puzzle Elements"
|
||||
2d_physics/layer_4="Puzzle Walls"
|
||||
2d_physics/layer_5="Enemies"
|
||||
|
||||
[physics]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user