Skip to content

Commit

Permalink
feat: added walking animation
Browse files Browse the repository at this point in the history
  • Loading branch information
chazzox committed Mar 3, 2024
1 parent bc89101 commit 4da4d83
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 72 deletions.
Binary file removed game-source/assets/tileset.png
Binary file not shown.
34 changes: 0 additions & 34 deletions game-source/assets/tileset.png.import

This file was deleted.

2 changes: 1 addition & 1 deletion game-source/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ WebSockets="*res://WebSockets.gd"

[display]

window/stretch/mode="viewport"
window/stretch/mode="canvas_items"

[input]

Expand Down
Binary file removed game-source/scenes/main/tileset.png
Binary file not shown.
34 changes: 0 additions & 34 deletions game-source/scenes/main/tileset.png.import

This file was deleted.

10 changes: 9 additions & 1 deletion game-source/scenes/player_character/player_character.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@ var inputs = {
"down": Vector2.DOWN
}

var inputs_rev = {
Vector2.RIGHT:"right",
Vector2.LEFT: "left",
Vector2.UP: "up",
Vector2.DOWN: "down"
}

func _ready():
position = position.snapped(Vector2.ONE * tile_size)
position += Vector2.ONE * tile_size / 2

func _input(event):
var vec = Input.get_vector("left", "right", "up", "down")
if !is_moving and vec.length()==1:
if vec.length() == 1:
position += vec*100
$AnimationPlayer.play(inputs_rev[vec])

72 changes: 70 additions & 2 deletions game-source/scenes/player_character/player_character.tscn
Original file line number Diff line number Diff line change
@@ -1,25 +1,93 @@
[gd_scene load_steps=4 format=3 uid="uid://xqoiyxrn10js"]
[gd_scene load_steps=8 format=3 uid="uid://xqoiyxrn10js"]

[ext_resource type="Script" path="res://scenes/player_character/player_character.gd" id="1_rmbqt"]
[ext_resource type="Texture2D" uid="uid://bdap4f6w37byq" path="res://assets/Illustration95.png" id="2_0gsa3"]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_nrvy8"]
size = Vector2(14, 15.5)

[sub_resource type="Animation" id="Animation_17yri"]
resource_name = "walk"
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("../Sprite2D:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0.00177135, 0.297301, 0.529481, 0.858887),
"transitions": PackedFloat32Array(1, 1, 1, 1),
"update": 1,
"values": [0, 1, 2, 0]
}

[sub_resource type="Animation" id="Animation_sndo4"]
resource_name = "up"
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("../Sprite2D:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0.00553417, 0.15295, 0.32358),
"transitions": PackedFloat32Array(1, 1, 1),
"update": 1,
"values": [3, 4, 5]
}

[sub_resource type="Animation" id="Animation_v72g0"]
resource_name = "left"
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("../Sprite2D:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0.0161553, 0.319068, 0.69064),
"transitions": PackedFloat32Array(1, 1, 1),
"update": 1,
"values": [6, 7, 8]
}

[sub_resource type="AnimationLibrary" id="AnimationLibrary_hbknw"]
_data = {
"down": SubResource("Animation_17yri"),
"right": SubResource("Animation_v72g0"),
"up": SubResource("Animation_sndo4")
}

[node name="PlayerCharacter" type="CharacterBody2D"]
script = ExtResource("1_rmbqt")

[node name="RayCast2D" type="RayCast2D" parent="."]
scale = Vector2(1, 1)
target_position = Vector2(0, 19)

[node name="Sprite2D" type="Sprite2D" parent="."]
scale = Vector2(0.458, 0.368)
texture = ExtResource("2_0gsa3")
hframes = 3
vframes = 3
frame = 3

[node name="Camera2D" type="Camera2D" parent="."]
position_smoothing_enabled = true
position_smoothing_speed = 10.0

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(0, 2.38419e-07)
scale = Vector2(-0.811343, 1.12881)
shape = SubResource("RectangleShape2D_nrvy8")

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
root_node = NodePath("../RayCast2D")
libraries = {
"": SubResource("AnimationLibrary_hbknw")
}

[node name="AnimationPlayer" type="AnimationPlayer" parent="AnimationPlayer"]
root_node = NodePath("../RayCast2D")
libraries = {
"": SubResource("AnimationLibrary_hbknw")
}

0 comments on commit 4da4d83

Please sign in to comment.