Skip to content

Commit

Permalink
added animations for elite guard
Browse files Browse the repository at this point in the history
  • Loading branch information
kneghtmare committed Dec 20, 2020
1 parent 580fa69 commit 2125198
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 29 deletions.
2 changes: 2 additions & 0 deletions Src/Dog/Dog.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
45 changes: 21 additions & 24 deletions Src/Dog/Dog.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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")
Expand All @@ -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"
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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 )
Expand All @@ -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 )
Expand All @@ -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
19 changes: 15 additions & 4 deletions Src/Guard/EliteGuard/EliteGuard.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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")

Expand Down
1 change: 1 addition & 0 deletions Src/Guard/EliteGuard/EliteGuard.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
6 changes: 5 additions & 1 deletion Src/Levels/TestLevel.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 )
Expand All @@ -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 )
Expand Down

0 comments on commit 2125198

Please sign in to comment.