diff --git a/Main.tscn b/Main.tscn index 0ef1d1c..4a6b194 100644 --- a/Main.tscn +++ b/Main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=30 format=2] +[gd_scene load_steps=31 format=2] [ext_resource path="res://res/level/neighbor.png" type="Texture" id=1] [ext_resource path="res://res/character/girl.png" type="Texture" id=2] @@ -108,26 +108,36 @@ flags = 4 atlas = ExtResource( 2 ) region = Rect2( 0, 200, 33, 50 ) +[sub_resource type="AtlasTexture" id=23] +flags = 4 +atlas = ExtResource( 2 ) +region = Rect2( 0, 0, 33, 50 ) + [sub_resource type="SpriteFrames" id=21] animations = [ { "frames": [ SubResource( 1 ), SubResource( 2 ), SubResource( 3 ), SubResource( 4 ), SubResource( 5 ) ], "loop": true, "name": "WalkRight", -"speed": 5.0 +"speed": 10.0 }, { "frames": [ SubResource( 6 ), SubResource( 7 ), SubResource( 8 ), SubResource( 9 ), SubResource( 10 ) ], "loop": true, "name": "WalkLeft", -"speed": 5.0 +"speed": 10.0 }, { "frames": [ SubResource( 11 ), SubResource( 12 ), SubResource( 13 ), SubResource( 14 ), SubResource( 15 ) ], "loop": true, "name": "WalkUp", -"speed": 5.0 +"speed": 10.0 }, { "frames": [ SubResource( 16 ), SubResource( 17 ), SubResource( 18 ), SubResource( 19 ), SubResource( 20 ) ], "loop": true, "name": "WalkDown", +"speed": 10.0 +}, { +"frames": [ SubResource( 23 ) ], +"loop": true, +"name": "Idle", "speed": 5.0 } ] @@ -156,7 +166,7 @@ script = ExtResource( 5 ) [node name="AnimatedSprite" type="AnimatedSprite" parent="World/Enter/Girl/KinematicBody2D"] frames = SubResource( 21 ) -animation = "WalkDown" +animation = "Idle" [node name="CollisionShape2D" type="CollisionShape2D" parent="World/Enter/Girl/KinematicBody2D"] position = Vector2( 1, -2 ) diff --git a/entity/AI/Player.gd b/entity/AI/Player.gd index 0a9dcbd..ddd2ba7 100644 --- a/entity/AI/Player.gd +++ b/entity/AI/Player.gd @@ -41,15 +41,19 @@ func movement_key_pressed(direction): if direction == 1: # right velocity_sum.x = 0 velocity_sum.x += 1 + get_user().animate("WalkRight") elif direction == 2: # left velocity_sum.x = 0 velocity_sum.x -= 1 + get_user().animate("WalkLeft") elif direction == 3: # up velocity_sum.y = 0 velocity_sum.y -= 1 + get_user().animate("WalkUp") elif direction == 4: # down velocity_sum.y = 0 velocity_sum.y += 1 + get_user().animate("WalkDown") # Velocity cannot be faster with more vectors get_user().set_internal_velocity(velocity_sum) @@ -58,9 +62,10 @@ func movement_key_released(direction): velocity_sum.x = 0 elif direction == 3 or direction == 4: # up/down velocity_sum.y = 0 + get_user().animate("Idle") get_user().set_internal_velocity(velocity_sum) # Physics Process -func _physics_process(delta): +func _physics_process(_delta): ## Keyboard Movement get_input() diff --git a/entity/Girl.gd b/entity/Girl.gd index b31be79..0eee16b 100644 --- a/entity/Girl.gd +++ b/entity/Girl.gd @@ -3,6 +3,9 @@ extends Node ## Nodes func get_body_node(): return $KinematicBody2D +func get_sprite_node(): + return $KinematicBody2D/AnimatedSprite + ## Parameters func set_gpos(new_pos): return get_body_node().set_gpos(new_pos) @@ -10,3 +13,7 @@ func get_gpos(): return get_body_node().get_gpos() func set_internal_velocity(new_vel): get_body_node().set_internal_velocity(new_vel) + +## Logic +func animate(animation): + get_sprite_node().play(animation) diff --git a/events/moved/Moved.gd b/events/moved/Moved.gd index a8bdd97..a5e2d7c 100644 --- a/events/moved/Moved.gd +++ b/events/moved/Moved.gd @@ -26,7 +26,7 @@ func track_pos(new_pos): positions.pop_front() # Handle -func handle(character): +func handle(_character): return # var current_pos = character.get_gpos() # track_pos(current_pos)