diff --git a/Enemies/basic_enemy.gd b/Enemies/basic_enemy.gd index c80c7f3..7ca114e 100644 --- a/Enemies/basic_enemy.gd +++ b/Enemies/basic_enemy.gd @@ -5,19 +5,21 @@ extends CharacterBody2D @export var FRICTION = 1500.0; @export var HP = 100; @export var DAMAGE = 10; -@export var COOLDOWN = 2; +@export var COOLDOWN = 1; @onready var raycast = $RayCast2D; @onready var cooldown_timer = $CooldownTimer; +@onready var sprite = $AnimatedSprite2D; var player = null; var is_on_cooldown = false; +var attacking = false; func _ready(): add_to_group("enemies"); func _physics_process(delta): - if player == null: + if player == null || !attacking: return var vec_to_player = player.global_position - global_position; @@ -43,6 +45,7 @@ func take_damage(damage): kill(); func kill(): + emit_signal("is_killed"); queue_free(); func set_player(p): @@ -50,3 +53,9 @@ func set_player(p): func _on_cooldown_timer_timeout(): is_on_cooldown = false; + +func _on_area_2d_body_entered(body): + if body.name == "Player": + attacking = true; + +signal is_killed() diff --git a/Enemies/basic_enemy.tscn b/Enemies/basic_enemy.tscn index f232147..8e55507 100644 --- a/Enemies/basic_enemy.tscn +++ b/Enemies/basic_enemy.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=5 format=3 uid="uid://c661br4lh30r8"] +[gd_scene load_steps=6 format=3 uid="uid://c661br4lh30r8"] [ext_resource type="Script" path="res://Enemies/basic_enemy.gd" id="1_5vi5k"] [ext_resource type="Texture2D" uid="uid://ds4uvvrcxoay1" path="res://Sprites/placeholder_enemy.png" id="1_o8nfm"] @@ -17,6 +17,9 @@ animations = [{ [sub_resource type="RectangleShape2D" id="RectangleShape2D_47nt3"] size = Vector2(41, 64) +[sub_resource type="CircleShape2D" id="CircleShape2D_237ox"] +radius = 390.185 + [node name="BasicEnemy" type="CharacterBody2D"] script = ExtResource("1_5vi5k") @@ -38,4 +41,12 @@ default_color = Color(1, 0, 0, 0.392157) [node name="CooldownTimer" type="Timer" parent="."] +[node name="Area2D" type="Area2D" parent="."] +collision_layer = 2 +collision_mask = 2 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] +shape = SubResource("CircleShape2D_237ox") + [connection signal="timeout" from="CooldownTimer" to="." method="_on_cooldown_timer_timeout"] +[connection signal="body_entered" from="Area2D" to="." method="_on_area_2d_body_entered"] diff --git a/Levels/level.gd b/Levels/level.gd new file mode 100644 index 0000000..ce75911 --- /dev/null +++ b/Levels/level.gd @@ -0,0 +1,21 @@ +extends Node2D + +@onready var doors = $Doors; + +func _ready(): + pass + +func _process(delta): + pass + +func _on_pickable_t_shirt_picked(): + doors.remove_child($Doors/FrontDoor_Left); + doors.remove_child($Doors/FrontDoor_Right); + + +func _on_outside_enemy_is_killed(): + doors.remove_child($Doors/ClassDoor); + + +func _on_shoes_picked(): + doors.remove_child($Doors/Bathroom_Top); diff --git a/Levels/level.tscn b/Levels/level.tscn index 5fe1a3c..7ffe2dd 100644 --- a/Levels/level.tscn +++ b/Levels/level.tscn @@ -1,10 +1,22 @@ -[gd_scene load_steps=4 format=3 uid="uid://b8rvp5g0vj8q1"] +[gd_scene load_steps=11 format=3 uid="uid://b8rvp5g0vj8q1"] [ext_resource type="TileSet" uid="uid://bi3tupdxmgcim" path="res://TileSets/tiles.tres" id="1_8igly"] +[ext_resource type="Script" path="res://Levels/level.gd" id="1_x3isi"] [ext_resource type="PackedScene" uid="uid://xev8p1td1icx" path="res://Player/player.tscn" id="2_raadk"] [ext_resource type="AudioStream" uid="uid://dhuxf2eklsha5" path="res://Music/school.ogg" id="3_rnkol"] +[ext_resource type="PackedScene" uid="uid://chhokm3rf6pd3" path="res://OTHERS/door.tscn" id="4_oukel"] +[ext_resource type="PackedScene" uid="uid://bbg5x0apue0ei" path="res://PickableItems/pickable_t_shirt.tscn" id="5_kahe8"] +[ext_resource type="PackedScene" uid="uid://c661br4lh30r8" path="res://Enemies/basic_enemy.tscn" id="7_qt4sv"] +[ext_resource type="PackedScene" uid="uid://degce2jvx3sli" path="res://PickableItems/pickable_shoes.tscn" id="8_qnb3g"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_8jn25"] +size = Vector2(85, 5534.75) + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_5xvim"] +size = Vector2(4186, 55) [node name="Level" type="Node2D"] +script = ExtResource("1_x3isi") [node name="Floor1" type="TileMap" parent="."] tile_set = ExtResource("1_8igly") @@ -37,3 +49,97 @@ position = Vector2(3075, 488) stream = ExtResource("3_rnkol") volume_db = -6.0 autoplay = true + +[node name="Outside_Wall" type="Node2D" parent="."] + +[node name="StaticBody2D" type="StaticBody2D" parent="Outside_Wall"] +position = Vector2(1029, 0) + +[node name="CollisionShape2D2" type="CollisionShape2D" parent="Outside_Wall/StaticBody2D"] +position = Vector2(4094.5, 2720.63) +shape = SubResource("RectangleShape2D_8jn25") + +[node name="CollisionShape2D3" type="CollisionShape2D" parent="Outside_Wall/StaticBody2D"] +position = Vector2(0, 2770) +shape = SubResource("RectangleShape2D_8jn25") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Outside_Wall/StaticBody2D"] +position = Vector2(2023, -0.5) +shape = SubResource("RectangleShape2D_5xvim") + +[node name="CollisionShape2D4" type="CollisionShape2D" parent="Outside_Wall/StaticBody2D"] +position = Vector2(2023, 5393) +shape = SubResource("RectangleShape2D_5xvim") + +[node name="Doors" type="Node2D" parent="."] + +[node name="FrontDoor_Left" parent="Doors" instance=ExtResource("4_oukel")] +position = Vector2(2906, 758) +scale = Vector2(4.47547, 4.07547) + +[node name="FrontDoor_Right" parent="Doors" instance=ExtResource("4_oukel")] +position = Vector2(3239, 762) +rotation = -3.14159 +scale = Vector2(4.47547, 4.07547) + +[node name="ClassDoor" parent="Doors" instance=ExtResource("4_oukel")] +position = Vector2(2763, 1339) +rotation = 1.57079 +scale = Vector2(3.57152, 3.25231) + +[node name="Bathroom_Top" parent="Doors" instance=ExtResource("4_oukel")] +position = Vector2(3368, 1473) +rotation = 1.57079 +scale = Vector2(3.57152, 3.25231) + +[node name="Bathroom_Bottom" parent="Doors" instance=ExtResource("4_oukel")] +position = Vector2(3368, 1984) +rotation = 4.71238 +scale = Vector2(3.57152, 3.25231) + +[node name="Cafeteria" parent="Doors" instance=ExtResource("4_oukel")] +position = Vector2(2763, 2436) +rotation = 4.71238 +scale = Vector2(3.57152, 3.25231) + +[node name="Locker" parent="Doors" instance=ExtResource("4_oukel")] +position = Vector2(3388, 2494) +rotation = 4.71238 +scale = Vector2(3.57152, 3.25231) + +[node name="Gym" parent="Doors" instance=ExtResource("4_oukel")] +position = Vector2(3388, 3579) +rotation = 4.71238 +scale = Vector2(3.57152, 3.25231) + +[node name="BackDoor_Left" parent="Doors" instance=ExtResource("4_oukel")] +position = Vector2(2906, 4086) +scale = Vector2(4.47547, 4.07547) + +[node name="BackDoor_Right" parent="Doors" instance=ExtResource("4_oukel")] +position = Vector2(3239, 4090) +rotation = -3.14159 +scale = Vector2(4.47547, 4.07547) + +[node name="pickable_t_shirt" parent="." instance=ExtResource("5_kahe8")] +position = Vector2(3586, 650) +rotation = 0.286545 + +[node name="Outside_Enemy" parent="." instance=ExtResource("7_qt4sv")] +position = Vector2(3939, 657) + +[node name="Class_Enemy01" parent="." instance=ExtResource("7_qt4sv")] +position = Vector2(2248, 1257) + +[node name="Class_Enemy02" parent="." instance=ExtResource("7_qt4sv")] +position = Vector2(2310, 1138) + +[node name="Class_Enemy03" parent="." instance=ExtResource("7_qt4sv")] +position = Vector2(2367, 1350) + +[node name="shoes" parent="." instance=ExtResource("8_qnb3g")] +position = Vector2(2595, 969) + +[connection signal="picked" from="pickable_t_shirt" to="." method="_on_pickable_t_shirt_picked"] +[connection signal="is_killed" from="Outside_Enemy" to="." method="_on_outside_enemy_is_killed"] +[connection signal="picked" from="shoes" to="." method="_on_shoes_picked"] diff --git a/OTHERS/door.tscn b/OTHERS/door.tscn new file mode 100644 index 0000000..8aa6535 --- /dev/null +++ b/OTHERS/door.tscn @@ -0,0 +1,29 @@ +[gd_scene load_steps=3 format=3 uid="uid://chhokm3rf6pd3"] + +[ext_resource type="Texture2D" uid="uid://q82l3e6t4whv" path="res://Sprites/HAHAHAs.png" id="1_6fehd"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_76cdb"] +size = Vector2(63, 7) + +[node name="Door" type="StaticBody2D"] + +[node name="Sprite2D" type="Sprite2D" parent="."] +position = Vector2(0, 6) +scale = Vector2(0.279902, 0.279902) +texture = ExtResource("1_6fehd") + +[node name="Sprite2D2" type="Sprite2D" parent="."] +position = Vector2(-8, 3) +rotation = 0.0752773 +scale = Vector2(0.245176, 0.245176) +texture = ExtResource("1_6fehd") + +[node name="Sprite2D3" type="Sprite2D" parent="."] +position = Vector2(14, 11) +rotation = -0.215964 +scale = Vector2(0.222094, 0.310601) +texture = ExtResource("1_6fehd") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +position = Vector2(0.5, 0.5) +shape = SubResource("RectangleShape2D_76cdb") diff --git a/PickableItems/basic_item.gd b/PickableItems/basic_item.gd index 5c3c2b7..617dfae 100644 --- a/PickableItems/basic_item.gd +++ b/PickableItems/basic_item.gd @@ -9,4 +9,7 @@ func _on_body_entered(body): func pickup_routine(player): player.pickup(self); + emit_signal("picked"); queue_free(); + +signal picked(); diff --git a/Player/player.gd b/Player/player.gd index b638f9f..e8a8899 100644 --- a/Player/player.gd +++ b/Player/player.gd @@ -6,6 +6,10 @@ extends CharacterBody2D @export var HP = 100; @onready var raycast = $RayCast2D; +@onready var sprite = $AnimatedSprite2D; + +var animation_count = 0; + var current_weapon = null; var weapons = [null,null,null]; @@ -40,9 +44,11 @@ func attack(): current_weapon.fire(velocity); func take_damage(damage): - HP = HP - damage; - if HP <= 0: - kill(); + if sprite.animation != "damage": + HP = HP - damage; + sprite.play("damage"); + if HP <= 0: + kill(); func pickup(item): if item.Type == "weapon": @@ -87,3 +93,11 @@ func _on_area_2d_area_exited(area): $"../School_Bass".volume_db(-80); $"../School_Flute".volume_db(-80); $"../School_Brass".volume_db(-80); + + +func _on_animated_sprite_2d_animation_finished(): + if sprite.animation == "damage": + animation_count+=1; + if animation_count > 3: + animation_count = 0; + sprite.play("default"); diff --git a/Player/player.tscn b/Player/player.tscn index 46e87cd..6f51fb4 100644 --- a/Player/player.tscn +++ b/Player/player.tscn @@ -8,6 +8,17 @@ animations = [{ "frames": [{ "duration": 1.0, "texture": ExtResource("2_bqbmq") +}, { +"duration": 1.0, +"texture": null +}], +"loop": true, +"name": &"damage", +"speed": 5.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": ExtResource("2_bqbmq") }], "loop": true, "name": &"default", @@ -39,3 +50,5 @@ visible = false points = PackedVector2Array(0, 0, 2000, 0) width = 5.0 default_color = Color(1, 0, 0, 0.392157) + +[connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animated_sprite_2d_animation_finished"] diff --git a/Sprites/Door_1.png b/Sprites/Door_1.png new file mode 100644 index 0000000..1cc5657 Binary files /dev/null and b/Sprites/Door_1.png differ diff --git a/Sprites/Door_1.png.import b/Sprites/Door_1.png.import new file mode 100644 index 0000000..e52c6c8 --- /dev/null +++ b/Sprites/Door_1.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://de3lmcqcag5ay" +path="res://.godot/imported/Door_1.png-0b82fd4258b936d355687545c7459cb5.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Sprites/Door_1.png" +dest_files=["res://.godot/imported/Door_1.png-0b82fd4258b936d355687545c7459cb5.ctex"] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/bptc_ldr=0 +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 diff --git a/Sprites/HAHAHAs.png b/Sprites/HAHAHAs.png new file mode 100644 index 0000000..b91c94d Binary files /dev/null and b/Sprites/HAHAHAs.png differ diff --git a/Sprites/HAHAHAs.png.import b/Sprites/HAHAHAs.png.import new file mode 100644 index 0000000..4588b66 --- /dev/null +++ b/Sprites/HAHAHAs.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://q82l3e6t4whv" +path="res://.godot/imported/HAHAHAs.png-120240e91c027940086d629e54ae02e0.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Sprites/HAHAHAs.png" +dest_files=["res://.godot/imported/HAHAHAs.png-120240e91c027940086d629e54ae02e0.ctex"] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/bptc_ldr=0 +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