diff --git a/Enemies/Bat.gd b/Enemies/Bat.gd new file mode 100644 index 0000000..04a66de --- /dev/null +++ b/Enemies/Bat.gd @@ -0,0 +1,10 @@ +extends KinematicBody2D + +var knockback = Vector2.ZERO + +func _physics_process(delta): + knockback = knockback.move_toward(Vector2.ZERO, 200 * delta) + knockback = move_and_slide(knockback) + +func _on_HurtBox_area_entered(area): + knockback = area.knockback_vector * 120 diff --git a/Enemies/Bat.tscn b/Enemies/Bat.tscn new file mode 100644 index 0000000..a9459e9 --- /dev/null +++ b/Enemies/Bat.tscn @@ -0,0 +1,68 @@ +[gd_scene load_steps=13 format=2] + +[ext_resource path="res://Shadows/SmallShadow.png" type="Texture" id=1] +[ext_resource path="res://Enemies/Bat.png" type="Texture" id=2] +[ext_resource path="res://AI/HurtBox.tscn" type="PackedScene" id=3] +[ext_resource path="res://Enemies/Bat.gd" type="Script" id=4] + +[sub_resource type="AtlasTexture" id=1] +atlas = ExtResource( 2 ) +region = Rect2( 0, 0, 16, 24 ) + +[sub_resource type="AtlasTexture" id=2] +atlas = ExtResource( 2 ) +region = Rect2( 16, 0, 16, 24 ) + +[sub_resource type="AtlasTexture" id=3] +atlas = ExtResource( 2 ) +region = Rect2( 32, 0, 16, 24 ) + +[sub_resource type="AtlasTexture" id=4] +atlas = ExtResource( 2 ) +region = Rect2( 48, 0, 16, 24 ) + +[sub_resource type="AtlasTexture" id=5] +atlas = ExtResource( 2 ) +region = Rect2( 64, 0, 16, 24 ) + +[sub_resource type="SpriteFrames" id=6] +animations = [ { +"frames": [ SubResource( 1 ), SubResource( 2 ), SubResource( 3 ), SubResource( 4 ), SubResource( 5 ) ], +"loop": true, +"name": "Fly", +"speed": 10.0 +} ] + +[sub_resource type="CircleShape2D" id=7] +radius = 3.92309 + +[sub_resource type="CapsuleShape2D" id=8] +radius = 5.875 +height = 0.75 + +[node name="Bat" type="KinematicBody2D"] +collision_layer = 16 +script = ExtResource( 4 ) + +[node name="AnimatedSprite" type="AnimatedSprite" parent="."] +frames = SubResource( 6 ) +animation = "Fly" +playing = true +offset = Vector2( 0, -12 ) + +[node name="Shadow" type="Sprite" parent="."] +texture = ExtResource( 1 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource( 7 ) + +[node name="HurtBox" parent="." instance=ExtResource( 3 )] +collision_layer = 8 +collision_mask = 0 + +[node name="CollisionShape2D" parent="HurtBox" index="0"] +position = Vector2( 0, -15 ) +shape = SubResource( 8 ) +[connection signal="area_entered" from="HurtBox" to="." method="_on_HurtBox_area_entered"] + +[editable path="HurtBox"] diff --git a/Player/player.gd b/Player/player.gd index 9b9b2c5..a64c558 100644 --- a/Player/player.gd +++ b/Player/player.gd @@ -19,13 +19,14 @@ var roll_vector = Vector2.LEFT onready var animation_tree = $AnimationTree onready var animation_state = animation_tree.get("parameters/playback") +onready var sword_hitbox = $HitBoxPosition/SwordHitBox func move(): velocity = move_and_slide(velocity) func _ready(): animation_tree.active = true - + sword_hitbox.knockback_vector = roll_vector func _physics_process(delta): match state: @@ -71,6 +72,9 @@ func move_state(delta): # We want to roll in direction of our movement and rememebr which direction was it roll_vector = input_velocity + # Saving the direction of hits + sword_hitbox.knockback_vector = input_velocity + animation_tree.set("parameters/Idle/blend_position", input_velocity) animation_tree.set("parameters/Run/blend_position", input_velocity) animation_tree.set("parameters/Attack/blend_position", input_velocity) diff --git a/Player/player.tscn b/Player/player.tscn index d8ec374..cd18e95 100644 --- a/Player/player.tscn +++ b/Player/player.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=50 format=2] +[gd_scene load_steps=51 format=2] [ext_resource path="res://Player/player.gd" type="Script" id=1] [ext_resource path="res://Player/Player.png" type="Texture" id=2] [ext_resource path="res://AI/HitBox.tscn" type="PackedScene" id=3] +[ext_resource path="res://Player/sword.gd" type="Script" id=4] [sub_resource type="CapsuleShape2D" id=1] radius = 3.21513 @@ -287,7 +288,7 @@ tracks/0/keys = { "values": [ 6 ] } -[sub_resource type="Animation" id=36] +[sub_resource type="Animation" id=10] resource_name = "RollDown" length = 0.5 tracks/0/type = "value" @@ -317,7 +318,7 @@ tracks/1/keys = { } ] } -[sub_resource type="Animation" id=39] +[sub_resource type="Animation" id=11] resource_name = "RollLeft" length = 0.5 tracks/0/type = "value" @@ -347,7 +348,7 @@ tracks/1/keys = { } ] } -[sub_resource type="Animation" id=37] +[sub_resource type="Animation" id=12] resource_name = "RollRight" length = 0.5 tracks/0/type = "value" @@ -377,7 +378,7 @@ tracks/1/keys = { } ] } -[sub_resource type="Animation" id=38] +[sub_resource type="Animation" id=13] resource_name = "RollUp" length = 0.5 tracks/0/type = "value" @@ -407,7 +408,7 @@ tracks/1/keys = { } ] } -[sub_resource type="Animation" id=10] +[sub_resource type="Animation" id=14] length = 0.6 loop = true tracks/0/type = "value" @@ -423,7 +424,7 @@ tracks/0/keys = { "values": [ 19, 20, 21, 22, 23, 18 ] } -[sub_resource type="Animation" id=11] +[sub_resource type="Animation" id=15] length = 0.6 loop = true tracks/0/type = "value" @@ -439,7 +440,7 @@ tracks/0/keys = { "values": [ 13, 14, 15, 16, 17, 12 ] } -[sub_resource type="Animation" id=12] +[sub_resource type="Animation" id=16] length = 0.6 loop = true tracks/0/type = "value" @@ -455,7 +456,7 @@ tracks/0/keys = { "values": [ 1, 2, 3, 4, 5, 0 ] } -[sub_resource type="Animation" id=13] +[sub_resource type="Animation" id=17] length = 0.6 loop = true tracks/0/type = "value" @@ -471,133 +472,133 @@ tracks/0/keys = { "values": [ 7, 8, 9, 10, 11, 6 ] } -[sub_resource type="AnimationNodeAnimation" id=14] +[sub_resource type="AnimationNodeAnimation" id=18] animation = "AttackLeft" -[sub_resource type="AnimationNodeAnimation" id=15] +[sub_resource type="AnimationNodeAnimation" id=19] animation = "AttackDown" -[sub_resource type="AnimationNodeAnimation" id=16] +[sub_resource type="AnimationNodeAnimation" id=20] animation = "AttackRight" -[sub_resource type="AnimationNodeAnimation" id=17] +[sub_resource type="AnimationNodeAnimation" id=21] animation = "AttackUp" -[sub_resource type="AnimationNodeBlendSpace2D" id=18] -blend_point_0/node = SubResource( 14 ) +[sub_resource type="AnimationNodeBlendSpace2D" id=22] +blend_point_0/node = SubResource( 18 ) blend_point_0/pos = Vector2( -1, 0 ) -blend_point_1/node = SubResource( 15 ) +blend_point_1/node = SubResource( 19 ) blend_point_1/pos = Vector2( 0, 1.1 ) -blend_point_2/node = SubResource( 16 ) +blend_point_2/node = SubResource( 20 ) blend_point_2/pos = Vector2( 1, 0 ) -blend_point_3/node = SubResource( 17 ) +blend_point_3/node = SubResource( 21 ) blend_point_3/pos = Vector2( 0, -1.1 ) min_space = Vector2( -1, -1.1 ) max_space = Vector2( 1, 1.1 ) blend_mode = 1 -[sub_resource type="AnimationNodeAnimation" id=19] +[sub_resource type="AnimationNodeAnimation" id=23] animation = "IdleLeft" -[sub_resource type="AnimationNodeAnimation" id=20] +[sub_resource type="AnimationNodeAnimation" id=24] animation = "IdleDown" -[sub_resource type="AnimationNodeAnimation" id=21] +[sub_resource type="AnimationNodeAnimation" id=25] animation = "IdleRight" -[sub_resource type="AnimationNodeAnimation" id=22] +[sub_resource type="AnimationNodeAnimation" id=26] animation = "IdleUp" -[sub_resource type="AnimationNodeBlendSpace2D" id=23] -blend_point_0/node = SubResource( 19 ) +[sub_resource type="AnimationNodeBlendSpace2D" id=27] +blend_point_0/node = SubResource( 23 ) blend_point_0/pos = Vector2( -1, 0 ) -blend_point_1/node = SubResource( 20 ) +blend_point_1/node = SubResource( 24 ) blend_point_1/pos = Vector2( 0, 1.1 ) -blend_point_2/node = SubResource( 21 ) +blend_point_2/node = SubResource( 25 ) blend_point_2/pos = Vector2( 1, 0 ) -blend_point_3/node = SubResource( 22 ) +blend_point_3/node = SubResource( 26 ) blend_point_3/pos = Vector2( 0, -1.1 ) min_space = Vector2( -1, -1.1 ) max_space = Vector2( 1, 1.1 ) blend_mode = 1 -[sub_resource type="AnimationNodeAnimation" id=40] +[sub_resource type="AnimationNodeAnimation" id=28] animation = "RollLeft" -[sub_resource type="AnimationNodeAnimation" id=41] +[sub_resource type="AnimationNodeAnimation" id=29] animation = "RollDown" -[sub_resource type="AnimationNodeAnimation" id=42] +[sub_resource type="AnimationNodeAnimation" id=30] animation = "RollRight" -[sub_resource type="AnimationNodeAnimation" id=43] +[sub_resource type="AnimationNodeAnimation" id=31] animation = "RollUp" -[sub_resource type="AnimationNodeBlendSpace2D" id=44] -blend_point_0/node = SubResource( 40 ) +[sub_resource type="AnimationNodeBlendSpace2D" id=32] +blend_point_0/node = SubResource( 28 ) blend_point_0/pos = Vector2( -1, 0 ) -blend_point_1/node = SubResource( 41 ) +blend_point_1/node = SubResource( 29 ) blend_point_1/pos = Vector2( 0, 1.1 ) -blend_point_2/node = SubResource( 42 ) +blend_point_2/node = SubResource( 30 ) blend_point_2/pos = Vector2( 1, 0 ) -blend_point_3/node = SubResource( 43 ) +blend_point_3/node = SubResource( 31 ) blend_point_3/pos = Vector2( 0, -1.1 ) min_space = Vector2( -1, -1.1 ) max_space = Vector2( 1, 1.1 ) blend_mode = 1 -[sub_resource type="AnimationNodeAnimation" id=24] +[sub_resource type="AnimationNodeAnimation" id=33] animation = "RunLeft" -[sub_resource type="AnimationNodeAnimation" id=25] +[sub_resource type="AnimationNodeAnimation" id=34] animation = "RunDown" -[sub_resource type="AnimationNodeAnimation" id=26] +[sub_resource type="AnimationNodeAnimation" id=35] animation = "RunRight" -[sub_resource type="AnimationNodeAnimation" id=27] +[sub_resource type="AnimationNodeAnimation" id=36] animation = "RunUp" -[sub_resource type="AnimationNodeBlendSpace2D" id=28] -blend_point_0/node = SubResource( 24 ) +[sub_resource type="AnimationNodeBlendSpace2D" id=37] +blend_point_0/node = SubResource( 33 ) blend_point_0/pos = Vector2( -1, 0 ) -blend_point_1/node = SubResource( 25 ) +blend_point_1/node = SubResource( 34 ) blend_point_1/pos = Vector2( 0, 1.1 ) -blend_point_2/node = SubResource( 26 ) +blend_point_2/node = SubResource( 35 ) blend_point_2/pos = Vector2( 1, 0 ) -blend_point_3/node = SubResource( 27 ) +blend_point_3/node = SubResource( 36 ) blend_point_3/pos = Vector2( 0, -1.1 ) min_space = Vector2( -1, -1.1 ) max_space = Vector2( 1, 1.1 ) blend_mode = 1 -[sub_resource type="AnimationNodeStateMachineTransition" id=29] +[sub_resource type="AnimationNodeStateMachineTransition" id=38] -[sub_resource type="AnimationNodeStateMachineTransition" id=30] +[sub_resource type="AnimationNodeStateMachineTransition" id=39] -[sub_resource type="AnimationNodeStateMachineTransition" id=31] +[sub_resource type="AnimationNodeStateMachineTransition" id=40] -[sub_resource type="AnimationNodeStateMachineTransition" id=32] +[sub_resource type="AnimationNodeStateMachineTransition" id=41] -[sub_resource type="AnimationNodeStateMachineTransition" id=45] +[sub_resource type="AnimationNodeStateMachineTransition" id=42] -[sub_resource type="AnimationNodeStateMachineTransition" id=46] +[sub_resource type="AnimationNodeStateMachineTransition" id=43] -[sub_resource type="AnimationNodeStateMachine" id=33] -states/Attack/node = SubResource( 18 ) +[sub_resource type="AnimationNodeStateMachine" id=44] +states/Attack/node = SubResource( 22 ) states/Attack/position = Vector2( 285, 201 ) -states/Idle/node = SubResource( 23 ) +states/Idle/node = SubResource( 27 ) states/Idle/position = Vector2( 285, 91 ) -states/Roll/node = SubResource( 44 ) +states/Roll/node = SubResource( 32 ) states/Roll/position = Vector2( 75, 91 ) -states/Run/node = SubResource( 28 ) +states/Run/node = SubResource( 37 ) states/Run/position = Vector2( 544, 91 ) -transitions = [ "Idle", "Run", SubResource( 29 ), "Run", "Idle", SubResource( 30 ), "Attack", "Idle", SubResource( 31 ), "Idle", "Attack", SubResource( 32 ), "Roll", "Idle", SubResource( 45 ), "Idle", "Roll", SubResource( 46 ) ] +transitions = [ "Idle", "Run", SubResource( 38 ), "Run", "Idle", SubResource( 39 ), "Attack", "Idle", SubResource( 40 ), "Idle", "Attack", SubResource( 41 ), "Roll", "Idle", SubResource( 42 ), "Idle", "Roll", SubResource( 43 ) ] start_node = "Idle" -[sub_resource type="AnimationNodeStateMachinePlayback" id=34] +[sub_resource type="AnimationNodeStateMachinePlayback" id=45] -[sub_resource type="CapsuleShape2D" id=35] +[sub_resource type="CapsuleShape2D" id=46] height = 12.0 [node name="player" type="KinematicBody2D"] @@ -622,19 +623,19 @@ anims/IdleDown = SubResource( 6 ) anims/IdleLeft = SubResource( 7 ) anims/IdleRight = SubResource( 8 ) anims/IdleUp = SubResource( 9 ) -anims/RollDown = SubResource( 36 ) -anims/RollLeft = SubResource( 39 ) -anims/RollRight = SubResource( 37 ) -anims/RollUp = SubResource( 38 ) -anims/RunDown = SubResource( 10 ) -anims/RunLeft = SubResource( 11 ) -anims/RunRight = SubResource( 12 ) -anims/RunUp = SubResource( 13 ) +anims/RollDown = SubResource( 10 ) +anims/RollLeft = SubResource( 11 ) +anims/RollRight = SubResource( 12 ) +anims/RollUp = SubResource( 13 ) +anims/RunDown = SubResource( 14 ) +anims/RunLeft = SubResource( 15 ) +anims/RunRight = SubResource( 16 ) +anims/RunUp = SubResource( 17 ) [node name="AnimationTree" type="AnimationTree" parent="."] -tree_root = SubResource( 33 ) +tree_root = SubResource( 44 ) anim_player = NodePath("../AnimationPlayer") -parameters/playback = SubResource( 34 ) +parameters/playback = SubResource( 45 ) parameters/Attack/blend_position = Vector2( 0, 0 ) parameters/Idle/blend_position = Vector2( 0, 0 ) parameters/Roll/blend_position = Vector2( 0, 0 ) @@ -647,9 +648,10 @@ position = Vector2( 0, -5 ) position = Vector2( 16, 0 ) collision_layer = 0 collision_mask = 8 +script = ExtResource( 4 ) [node name="CollisionShape2D" parent="HitBoxPosition/SwordHitBox" index="0"] -shape = SubResource( 35 ) +shape = SubResource( 46 ) disabled = true [editable path="HitBoxPosition/SwordHitBox"] diff --git a/Player/sword.gd b/Player/sword.gd new file mode 100644 index 0000000..fe06184 --- /dev/null +++ b/Player/sword.gd @@ -0,0 +1,3 @@ +extends Area2D + +var knockback_vector = Vector2.ZERO diff --git a/project.godot b/project.godot index c17714a..2d54bfe 100644 --- a/project.godot +++ b/project.godot @@ -69,6 +69,7 @@ ui_roll={ 2d_physics/layer_2="Player" 2d_physics/layer_3="PlayerHurtBox" 2d_physics/layer_4="EnemyHurtBox" +2d_physics/layer_5="Enemy" [rendering] diff --git a/world.tscn b/world.tscn index 0a40be6..0d576fd 100644 --- a/world.tscn +++ b/world.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=57 format=2] +[gd_scene load_steps=58 format=2] [ext_resource path="res://World/Bush.tscn" type="PackedScene" id=1] [ext_resource path="res://Player/player.tscn" type="PackedScene" id=2] @@ -7,6 +7,7 @@ [ext_resource path="res://World/DirtTileset.png" type="Texture" id=5] [ext_resource path="res://World/CliffTileset.png" type="Texture" id=6] [ext_resource path="res://World/Grass.tscn" type="PackedScene" id=7] +[ext_resource path="res://Enemies/Bat.tscn" type="PackedScene" id=8] [sub_resource type="ConvexPolygonShape2D" id=1] points = PoolVector2Array( 0, 0, 32, 0, 32, 32, 0, 32 ) @@ -505,9 +506,6 @@ tile_data = PoolIntArray( 196614, 0, 131077, 327679, 0, 131074, 262144, 0, 13107 [node name="Ground" type="YSort" parent="."] -[node name="player" parent="Ground" instance=ExtResource( 2 )] -position = Vector2( 32, 88 ) - [node name="Tree" parent="Ground" instance=ExtResource( 4 )] position = Vector2( 248, 104 ) @@ -553,3 +551,14 @@ position = Vector2( 32, 128 ) [node name="Grass3" parent="Ground/Grass" instance=ExtResource( 7 )] position = Vector2( 16, 144 ) + +[node name="Enemies" type="YSort" parent="."] + +[node name="player" parent="Enemies" instance=ExtResource( 2 )] +position = Vector2( 32, 88 ) + +[node name="Bat" parent="Enemies" instance=ExtResource( 8 )] +position = Vector2( 112, 88 ) + +[node name="Bat2" parent="Enemies" instance=ExtResource( 8 )] +position = Vector2( 272, 120 )