Skip to content

Commit

Permalink
players and enemy animations
Browse files Browse the repository at this point in the history
using animation for transform properties without additional sprites
using Particle system for animating enemy death with variations
  • Loading branch information
KartikWatts committed Jan 16, 2024
1 parent 674ad09 commit 1b3f878
Show file tree
Hide file tree
Showing 6 changed files with 300 additions and 4 deletions.
21 changes: 21 additions & 0 deletions 2d-survivors-course/scenes/components/death_component.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
extends Node2D

@export var health_component: Node
@export var sprite: Sprite2D

func _ready():
$GPUParticles2D.texture = sprite.texture
health_component.died.connect(on_died)


func on_died():
if owner == null or not owner is Node2D:
return

var spawn_position = owner.global_position

var entities = get_tree().get_first_node_in_group("entities_layer")
get_parent().remove_child(self)
entities.add_child(self)
global_position = spawn_position
$AnimationPlayer.play("default")
90 changes: 90 additions & 0 deletions 2d-survivors-course/scenes/components/death_component.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
[gd_scene load_steps=9 format=3 uid="uid://ccr2pyjml5e3f"]

[ext_resource type="Texture2D" uid="uid://c4wr81m8ifp8g" path="res://scenes/game_object/basic_enemy/basic_enemy.png" id="1_uqrhc"]
[ext_resource type="Script" path="res://scenes/components/death_component.gd" id="1_ytloj"]

[sub_resource type="Animation" id="Animation_gqtrg"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("GPUParticles2D:emitting")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [false]
}

[sub_resource type="Animation" id="Animation_6ydj7"]
resource_name = "default"
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("GPUParticles2D:emitting")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [true]
}
tracks/1/type = "method"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath(".")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(1),
"transitions": PackedFloat32Array(1),
"values": [{
"args": [],
"method": &"queue_free"
}]
}

[sub_resource type="AnimationLibrary" id="AnimationLibrary_hf1dk"]
_data = {
"RESET": SubResource("Animation_gqtrg"),
"default": SubResource("Animation_6ydj7")
}

[sub_resource type="Curve" id="Curve_t1e56"]
_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(0.6, 1), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0]
point_count = 3

[sub_resource type="CurveTexture" id="CurveTexture_sj25v"]
curve = SubResource("Curve_t1e56")

[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_fki2r"]
particle_flag_disable_z = true
direction = Vector3(0, -1, 0)
spread = 30.0
initial_velocity_min = 175.0
initial_velocity_max = 250.0
angular_velocity_min = -1440.0
angular_velocity_max = 1440.0
gravity = Vector3(0, 800, 0)
scale_curve = SubResource("CurveTexture_sj25v")

[node name="DeathComponent" type="Node2D"]
script = ExtResource("1_ytloj")

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
"": SubResource("AnimationLibrary_hf1dk")
}

[node name="GPUParticles2D" type="GPUParticles2D" parent="."]
emitting = false
amount = 1
process_material = SubResource("ParticleProcessMaterial_fki2r")
texture = ExtResource("1_uqrhc")
lifetime = 0.5
one_shot = true
fixed_fps = 0
interpolate = false
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ extends CharacterBody2D
const MAX_SPEED = 40

@onready var health_component: HealthComponent = $HealthComponent
@onready var visuals = $Visuals


func _process(_delta):
var direction = get_direction_to_player()
velocity = direction * MAX_SPEED
move_and_slide()

var move_sign = sign(velocity.x)
if move_sign != 0:
visuals.scale = Vector2(-move_sign, 1)


func get_direction_to_player():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,73 @@
[gd_scene load_steps=8 format=3 uid="uid://dlsoablcbbnbn"]
[gd_scene load_steps=12 format=3 uid="uid://dlsoablcbbnbn"]

[ext_resource type="Script" path="res://scenes/game_object/basic_enemy/basic_enemy.gd" id="1_btoq0"]
[ext_resource type="Texture2D" uid="uid://c4wr81m8ifp8g" path="res://scenes/game_object/basic_enemy/basic_enemy.png" id="1_tp3eb"]
[ext_resource type="PackedScene" uid="uid://gquv3s5nw6xd" path="res://scenes/components/health_component.tscn" id="2_8ku87"]
[ext_resource type="PackedScene" uid="uid://buus3vhc8c05j" path="res://scenes/components/vial_drop_component.tscn" id="3_2q644"]
[ext_resource type="PackedScene" uid="uid://cjvydmwd1w4f6" path="res://scenes/components/hurt_box_component.tscn" id="4_dclov"]
[ext_resource type="PackedScene" uid="uid://ccr2pyjml5e3f" path="res://scenes/components/death_component.tscn" id="4_ghoxd"]

[sub_resource type="Animation" id="Animation_u4rlb"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Visuals/Sprite2D:position")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector2(0, 0)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Visuals/Sprite2D:rotation")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [0.0]
}

[sub_resource type="Animation" id="Animation_b3l7f"]
resource_name = "walk"
length = 0.4
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Visuals/Sprite2D:position")
tracks/0/interp = 2
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.1, 0.3),
"transitions": PackedFloat32Array(1, 1, 1),
"update": 0,
"values": [Vector2(0, 0), Vector2(1, 0), Vector2(-1, 0)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Visuals/Sprite2D:rotation")
tracks/1/interp = 2
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 0.1, 0.2, 0.3),
"transitions": PackedFloat32Array(1, 1, 1, 1),
"update": 0,
"values": [0.174533, -0.174533, 0.174533, -0.174533]
}

[sub_resource type="AnimationLibrary" id="AnimationLibrary_wkuht"]
_data = {
"RESET": SubResource("Animation_u4rlb"),
"walk": SubResource("Animation_b3l7f")
}

[sub_resource type="CircleShape2D" id="CircleShape2D_jomo2"]
radius = 12.0
Expand All @@ -18,19 +81,31 @@ collision_mask = 9
motion_mode = 1
script = ExtResource("1_btoq0")

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
"": SubResource("AnimationLibrary_wkuht")
}
autoplay = "walk"

[node name="HealthComponent" parent="." instance=ExtResource("2_8ku87")]

[node name="VialDropComponent" parent="." node_paths=PackedStringArray("health_component") instance=ExtResource("3_2q644")]
health_component = NodePath("../HealthComponent")

[node name="DeathComponent" parent="." node_paths=PackedStringArray("health_component", "sprite") instance=ExtResource("4_ghoxd")]
health_component = NodePath("../HealthComponent")
sprite = NodePath("../Visuals/Sprite2D")

[node name="HurtBoxComponent" parent="." node_paths=PackedStringArray("health_component") instance=ExtResource("4_dclov")]
health_component = NodePath("../HealthComponent")

[node name="CollisionShape2D" type="CollisionShape2D" parent="HurtBoxComponent"]
position = Vector2(0, -5)
shape = SubResource("CircleShape2D_jomo2")

[node name="Sprite2D" type="Sprite2D" parent="."]
[node name="Visuals" type="Node2D" parent="."]

[node name="Sprite2D" type="Sprite2D" parent="Visuals"]
texture = ExtResource("1_tp3eb")
offset = Vector2(0, -4)

Expand Down
11 changes: 11 additions & 0 deletions 2d-survivors-course/scenes/game_object/player/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ extends CharacterBody2D
@onready var _damage_interval_timer: Timer = $DamageIntervalTimer
@onready var _health_bar: ProgressBar = $HealthBar
@onready var _abilities = $Abilities
@onready var _animation_player = $AnimationPlayer
@onready var _visuals = $Visuals

const MAX_SPEED = 125
const ACCELERATION_SMOOTHING = 25
Expand All @@ -28,6 +30,15 @@ func _process(delta):
velocity = velocity.lerp(target_velocity, 1 - exp(-delta * ACCELERATION_SMOOTHING))
move_and_slide()

if movement_vector.x !=0 or movement_vector.y!=0:
_animation_player.play("walk")
else:
_animation_player.play("RESET")

var move_sign = sign(movement_vector.x)
if move_sign != 0:
_visuals.scale = Vector2(move_sign, 1)


func get_movement_vector():
#var movement_vector = Vector2.ZERO
Expand Down
97 changes: 95 additions & 2 deletions 2d-survivors-course/scenes/game_object/player/player.tscn
Original file line number Diff line number Diff line change
@@ -1,10 +1,96 @@
[gd_scene load_steps=10 format=3 uid="uid://c2o7ggmbuyq3b"]
[gd_scene load_steps=13 format=3 uid="uid://c2o7ggmbuyq3b"]

[ext_resource type="Script" path="res://scenes/game_object/player/player.gd" id="1_6ggdr"]
[ext_resource type="Texture2D" uid="uid://c3oci8ridauxg" path="res://scenes/game_object/player/player.png" id="2_1v84t"]
[ext_resource type="Script" path="res://scenes/components/health_component.gd" id="2_lfgfj"]
[ext_resource type="PackedScene" uid="uid://crwtyhsq062wk" path="res://scenes/ability/sword_ability_controller/sword_ability_controller.tscn" id="2_moccb"]

[sub_resource type="Animation" id="Animation_q62fd"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Visuals/Sprite2D:position")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector2(0, 0)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Visuals/Sprite2D:rotation")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [0.0]
}
tracks/2/type = "value"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath("Visuals/Sprite2D:scale")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector2(1, 1)]
}

[sub_resource type="Animation" id="Animation_uo2vj"]
resource_name = "walk"
length = 0.4
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Visuals/Sprite2D:position")
tracks/0/interp = 2
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.1, 0.3),
"transitions": PackedFloat32Array(1, 1, 1),
"update": 0,
"values": [Vector2(0, 0), Vector2(0, -5), Vector2(0, 0)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Visuals/Sprite2D:rotation")
tracks/1/interp = 2
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 0.1, 0.2, 0.4),
"transitions": PackedFloat32Array(1, 1, 1, 1),
"update": 0,
"values": [0.0, -0.261799, 0.261799, 0.0]
}
tracks/2/type = "value"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath("Visuals/Sprite2D:scale")
tracks/2/interp = 2
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(0, 0.1, 0.3, 0.4),
"transitions": PackedFloat32Array(0.732043, 3.605, 2.73208, 1),
"update": 0,
"values": [Vector2(1, 1), Vector2(0.8, 1.1), Vector2(1.5, 0.7), Vector2(1, 1)]
}

[sub_resource type="AnimationLibrary" id="AnimationLibrary_u1xbg"]
_data = {
"RESET": SubResource("Animation_q62fd"),
"walk": SubResource("Animation_uo2vj")
}

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_bkthj"]
bg_color = Color(0.247059, 0.14902, 0.192157, 1)

Expand All @@ -30,6 +116,11 @@ collision_layer = 0
motion_mode = 1
script = ExtResource("1_6ggdr")

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
"": SubResource("AnimationLibrary_u1xbg")
}

[node name="HealthComponent" type="Node" parent="."]
script = ExtResource("2_lfgfj")

Expand Down Expand Up @@ -62,7 +153,9 @@ collision_mask = 0
[node name="CollisionShape2D" type="CollisionShape2D" parent="PickupArea2D"]
shape = SubResource("CircleShape2D_3mwpg")

[node name="Sprite2D" type="Sprite2D" parent="."]
[node name="Visuals" type="Node2D" parent="."]

[node name="Sprite2D" type="Sprite2D" parent="Visuals"]
texture = ExtResource("2_1v84t")
offset = Vector2(0, -8)

Expand Down

0 comments on commit 1b3f878

Please sign in to comment.