From 212519835dec95ddb5581b23b5570e16d40bacfa Mon Sep 17 00:00:00 2001 From: Allen Davis Date: Sun, 20 Dec 2020 11:30:28 +0530 Subject: [PATCH] added animations for elite guard --- Src/Dog/Dog.gd | 2 ++ Src/Dog/Dog.tscn | 45 +++++++++++++--------------- Src/Guard/EliteGuard/EliteGuard.gd | 19 +++++++++--- Src/Guard/EliteGuard/EliteGuard.tscn | 1 + Src/Levels/TestLevel.tscn | 6 +++- 5 files changed, 44 insertions(+), 29 deletions(-) diff --git a/Src/Dog/Dog.gd b/Src/Dog/Dog.gd index b4ded50..8d6f4ec 100644 --- a/Src/Dog/Dog.gd +++ b/Src/Dog/Dog.gd @@ -153,6 +153,8 @@ func feed() -> void: func onPathLineNextPointReached() -> void: if state == Types.DogStates.Detection: return + if pathLine.stopOnReachedPoint: + $AnimationPlayer.play("look_around") if state == Types.DogStates.MovingToSnack: setState(Types.DogStates.Roaming) if isMovingToPlayer and not playerInLOS: diff --git a/Src/Dog/Dog.tscn b/Src/Dog/Dog.tscn index b1c8afa..ef930d0 100644 --- a/Src/Dog/Dog.tscn +++ b/Src/Dog/Dog.tscn @@ -4,15 +4,14 @@ [ext_resource path="res://Src/Dog/Dog.gd" type="Script" id=2] [ext_resource path="res://Src/Notifier/Notifier.tscn" type="PackedScene" id=3] -[sub_resource type="RectangleShape2D" id=10] -extents = Vector2( 25, 10 ) - [sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 25, 10 ) [sub_resource type="RectangleShape2D" id=2] -[sub_resource type="Animation" id=3] -resource_name = "alarm" +[sub_resource type="RectangleShape2D" id=3] + +[sub_resource type="Animation" id=4] length = 0.6 loop = true tracks/0/type = "value" @@ -28,8 +27,7 @@ tracks/0/keys = { "values": [ 2, 3 ] } -[sub_resource type="Animation" id=4] -resource_name = "eat" +[sub_resource type="Animation" id=5] length = 0.4 tracks/0/type = "value" tracks/0/path = NodePath("Flippable/Sprite:frame") @@ -44,8 +42,7 @@ tracks/0/keys = { "values": [ 4, 6 ] } -[sub_resource type="Animation" id=5] -resource_name = "get_up" +[sub_resource type="Animation" id=6] length = 4.0 step = 0.05 tracks/0/type = "value" @@ -61,7 +58,7 @@ tracks/0/keys = { "values": [ 5, 4, 2, 0, 1, 0 ] } -[sub_resource type="Animation" id=6] +[sub_resource type="Animation" id=7] length = 0.1 tracks/0/type = "value" tracks/0/path = NodePath("Flippable/Sprite:frame") @@ -76,8 +73,7 @@ tracks/0/keys = { "values": [ 2 ] } -[sub_resource type="Animation" id=7] -resource_name = "laying_down" +[sub_resource type="Animation" id=8] length = 0.8 tracks/0/type = "value" tracks/0/path = NodePath("Flippable/Sprite:frame") @@ -92,7 +88,7 @@ tracks/0/keys = { "values": [ 2, 4, 5 ] } -[sub_resource type="Animation" id=8] +[sub_resource type="Animation" id=9] length = 1.5 tracks/0/type = "value" tracks/0/path = NodePath("Flippable/Sprite:frame") @@ -131,7 +127,7 @@ tracks/2/keys = { "values": [ Vector2( 1, 1 ), Vector2( -1, 1 ) ] } -[sub_resource type="Animation" id=9] +[sub_resource type="Animation" id=10] length = 1.2 loop = true tracks/0/type = "value" @@ -174,6 +170,7 @@ tracks/2/keys = { [node name="Dog" type="KinematicBody2D" groups=[ "Dog", ]] +z_index = 20 collision_layer = 112 collision_mask = 16 script = ExtResource( 2 ) @@ -191,14 +188,14 @@ frame = 12 [node name="CollisionShape2D" type="CollisionShape2D" parent="Flippable/LOSArea"] position = Vector2( -36, -10 ) -shape = SubResource( 10 ) +shape = SubResource( 1 ) [node name="DogArea" type="Area2D" parent="Flippable"] [node name="CollisionShape2D" type="CollisionShape2D" parent="Flippable/DogArea"] visible = false position = Vector2( 0, -10 ) -shape = SubResource( 1 ) +shape = SubResource( 2 ) [node name="Notifier" parent="." instance=ExtResource( 3 )] position = Vector2( 0, -32 ) @@ -212,19 +209,19 @@ wait_time = 10.0 [node name="CollisionShape2D" type="CollisionShape2D" parent="."] visible = false position = Vector2( 0, -10 ) -shape = SubResource( 2 ) +shape = SubResource( 3 ) [node name="DetectionDelay" type="Timer" parent="."] wait_time = 1.6 [node name="AnimationPlayer" type="AnimationPlayer" parent="."] -anims/alarm = SubResource( 3 ) -anims/eat = SubResource( 4 ) -anims/get_up = SubResource( 5 ) -anims/grr = SubResource( 6 ) -anims/laying_down = SubResource( 7 ) -anims/look_around = SubResource( 8 ) -anims/walk = SubResource( 9 ) +anims/alarm = SubResource( 4 ) +anims/eat = SubResource( 5 ) +anims/get_up = SubResource( 6 ) +anims/grr = SubResource( 7 ) +anims/laying_down = SubResource( 8 ) +anims/look_around = SubResource( 9 ) +anims/walk = SubResource( 10 ) [node name="BarkTimer" type="Timer" parent="."] wait_time = 5.0 diff --git a/Src/Guard/EliteGuard/EliteGuard.gd b/Src/Guard/EliteGuard/EliteGuard.gd index 18c0524..2572b2e 100644 --- a/Src/Guard/EliteGuard/EliteGuard.gd +++ b/Src/Guard/EliteGuard/EliteGuard.gd @@ -19,12 +19,17 @@ func _ready() -> void: losRay.set_deferred("enabled", false) $Flippable/LineOfSight.connect("body_entered", self, "onLOSBodyEntered") $Flippable/TaserRange.connect("body_entered", self, "onTaserRangeBodyEntered") + $AnimationPlayer.connect("animation_finished", self, "onAnimationFinished") func _physics_process(delta: float) -> void: velocity = direction * speed velocity = move_and_slide(velocity) updateFlip() + if direction.x != 0: + $AnimationPlayer.play("walk") + elif direction.x == 0: + $AnimationPlayer.play("idle") func _process(delta: float) -> void: @@ -42,11 +47,11 @@ func onTaserRangeBodyEntered(body: Node) -> void: player = body flipTowards(player.global_position) Events.emit_signal("play_sound", "taser_hit") - print("start tasing player animation") - pathLine.stopAllMovement() - Events.emit_signal("game_over") - + set_physics_process(false) + $AnimationPlayer.play("taser") + Events.emit_signal("block_player_movement") + func onLOSBodyEntered(body: Node) -> void: if body.is_in_group("Player"): losRay.set_deferred("enabled", true) @@ -55,6 +60,12 @@ func onLOSBodyEntered(body: Node) -> void: $Notifier.popup(Types.NotifierTypes.Exclamation) +func onAnimationFinished(animName: String) -> void: + if animName == "taser": + pathLine.stopAllMovement() + Events.emit_signal("game_over") + + func losRayIsCollidingWithPlayer() -> bool: return losRay.is_colliding() and losRay.get_collider().is_in_group("Player") diff --git a/Src/Guard/EliteGuard/EliteGuard.tscn b/Src/Guard/EliteGuard/EliteGuard.tscn index d7100a7..0caae98 100644 --- a/Src/Guard/EliteGuard/EliteGuard.tscn +++ b/Src/Guard/EliteGuard/EliteGuard.tscn @@ -69,6 +69,7 @@ script = ExtResource( 2 ) position = Vector2( 0, -16 ) texture = ExtResource( 1 ) hframes = 11 +frame = 5 [node name="LineOfSight" type="Area2D" parent="Flippable"] diff --git a/Src/Levels/TestLevel.tscn b/Src/Levels/TestLevel.tscn index d70a783..37e67d6 100644 --- a/Src/Levels/TestLevel.tscn +++ b/Src/Levels/TestLevel.tscn @@ -145,9 +145,11 @@ __meta__ = { [node name="Light" parent="LevelObjects/Lights" instance=ExtResource( 3 )] position = Vector2( 216, 200 ) +flicker = false [node name="Light2" parent="LevelObjects/Lights" instance=ExtResource( 3 )] position = Vector2( -241.923, 213.091 ) +flicker = false [node name="LaserDetector" parent="LevelObjects" instance=ExtResource( 4 )] position = Vector2( 152, 208 ) @@ -216,6 +218,8 @@ script = ExtResource( 15 ) [node name="Closet" parent="." instance=ExtResource( 23 )] position = Vector2( -240, 256 ) +canHidePlayer = true +canBeOpened = true [node name="Guard" parent="." instance=ExtResource( 22 )] position = Vector2( -362.162, 254.294 ) @@ -228,7 +232,7 @@ script = ExtResource( 15 ) position = Vector2( 118.538, 238.544 ) [node name="EliteGuard" parent="." instance=ExtResource( 25 )] -position = Vector2( -349, 233 ) +position = Vector2( -415.742, 257.695 ) [node name="PathLine" type="Line2D" parent="EliteGuard"] points = PoolVector2Array( -27.6506, -0.834763, -82.0978, -0.834763, -123.11, 0.579453 )