Skip to content

Commit

Permalink
anims
Browse files Browse the repository at this point in the history
  • Loading branch information
maggardJosh committed Apr 13, 2024
1 parent 3a328b7 commit 02450b7
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 23 deletions.
1 change: 1 addition & 0 deletions DebugMessageContainer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ func _ready() -> void:
GameEvents.add_message.connect(add_message)

func add_message(message):
print(message)
var new_label: Label = label_scene.instantiate()
new_label.text = message
add_child(new_label)
2 changes: 1 addition & 1 deletion OxygenComponent.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ func _physics_process(delta: float) -> void:
else:
if count >= 0:
count = clamp(count - replenish_rate * delta, 0, max_oxygen_seconds)
oxygen_bar.value = max_oxygen_seconds - count
oxygen_bar.max_value = max_oxygen_seconds
oxygen_bar.value = max_oxygen_seconds - count
1 change: 1 addition & 0 deletions main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ shape = SubResource("RectangleShape2D_wau00")
debug_color = Color(0.666667, 0.933333, 1, 0.419608)

[node name="UI" parent="." instance=ExtResource("3_0cdyn")]
visible = false

[node name="Water" type="Polygon2D" parent="." node_paths=PackedStringArray("default_biome")]
z_index = 1
Expand Down
Binary file modified player.aseprite
Binary file not shown.
14 changes: 11 additions & 3 deletions player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func enter_water():
else:
swim_target_angle = 0
swim_angle = 0
animation_player.play("swim")
float_component.set_in_water(true)
motion_mode = CharacterBody2D.MOTION_MODE_FLOATING
floor_constant_speed = false
Expand Down Expand Up @@ -89,7 +88,10 @@ func _physics_process(delta):
if velocity.y > max_fall_speed:
velocity.y = max_fall_speed
else:
animation_player.play("idle")
if direction_input:
animation_player.play("walk")
else:
animation_player.play("idle")

if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = jump_vel
Expand Down Expand Up @@ -129,14 +131,20 @@ func _physics_process(delta):
velocity.y = move_toward(velocity.y, 0, water_friction_speed * delta)
if direction_input:
swim_target_angle = direction_input.angle()
swim_angle = rotate_toward(swim_angle, swim_target_angle, swim_rotation_speed * delta)
else:
swim_target_angle = 0 if sprite.scale.x == -1 else PI
swim_angle = lerp_angle(swim_angle, swim_target_angle, .1)
GameEvents.add_debug_obj.emit("swim_angle", swim_angle)
var currently_flipped = sprite.scale.x == -1
var dot_value = Vector2.RIGHT.dot(Vector2.from_angle(swim_angle))
var is_flipped = dot_value > 0.1 if not currently_flipped else dot_value > -.1
GameEvents.add_debug_obj.emit("is_flipped", is_flipped)
sprite.rotation = swim_angle if is_flipped else swim_angle + PI
sprite.scale.x = -1 if is_flipped else 1
if direction_input:
animation_player.play("swim")
else:
animation_player.play("swim_idle")



Expand Down
104 changes: 97 additions & 7 deletions player.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,121 @@
{ "frames": {
"player 0.aseprite": {
"frame": { "x": 30, "y": 2, "w": 20, "h": 21 },
"frame": { "x": 41, "y": 46, "w": 17, "h": 21 },
"rotated": false,
"trimmed": true,
"spriteSourceSize": { "x": 9, "y": 8, "w": 16, "h": 17 },
"spriteSourceSize": { "x": 11, "y": 8, "w": 13, "h": 17 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 100
},
"player 1.aseprite": {
"frame": { "x": 2, "y": 2, "w": 26, "h": 21 },
"frame": { "x": 77, "y": 2, "w": 17, "h": 22 },
"rotated": false,
"trimmed": true,
"spriteSourceSize": { "x": 8, "y": 8, "w": 22, "h": 17 },
"spriteSourceSize": { "x": 10, "y": 8, "w": 13, "h": 18 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 100
"duration": 200
},
"player 2.aseprite": {
"frame": { "x": 21, "y": 64, "w": 17, "h": 20 },
"rotated": false,
"trimmed": true,
"spriteSourceSize": { "x": 10, "y": 9, "w": 13, "h": 16 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 200
},
"player 3.aseprite": {
"frame": { "x": 50, "y": 22, "w": 17, "h": 22 },
"rotated": false,
"trimmed": true,
"spriteSourceSize": { "x": 10, "y": 8, "w": 13, "h": 18 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 200
},
"player 4.aseprite": {
"frame": { "x": 21, "y": 42, "w": 18, "h": 20 },
"rotated": false,
"trimmed": true,
"spriteSourceSize": { "x": 10, "y": 9, "w": 14, "h": 16 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 200
},
"player 5.aseprite": {
"frame": { "x": 2, "y": 47, "w": 17, "h": 21 },
"rotated": false,
"trimmed": true,
"spriteSourceSize": { "x": 11, "y": 8, "w": 13, "h": 17 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 400
},
"player 6.aseprite": {
"frame": { "x": 2, "y": 23, "w": 17, "h": 22 },
"rotated": false,
"trimmed": true,
"spriteSourceSize": { "x": 11, "y": 9, "w": 13, "h": 18 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 200
},
"player 7.aseprite": {
"frame": { "x": 60, "y": 50, "w": 17, "h": 21 },
"rotated": false,
"trimmed": true,
"spriteSourceSize": { "x": 11, "y": 8, "w": 13, "h": 17 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 400
},
"player 8.aseprite": {
"frame": { "x": 69, "y": 26, "w": 17, "h": 22 },
"rotated": false,
"trimmed": true,
"spriteSourceSize": { "x": 11, "y": 9, "w": 13, "h": 18 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 200
},
"player 9.aseprite": {
"frame": { "x": 26, "y": 22, "w": 22, "h": 18 },
"rotated": false,
"trimmed": true,
"spriteSourceSize": { "x": 9, "y": 8, "w": 18, "h": 14 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 250
},
"player 10.aseprite": {
"frame": { "x": 26, "y": 2, "w": 23, "h": 18 },
"rotated": false,
"trimmed": true,
"spriteSourceSize": { "x": 9, "y": 9, "w": 19, "h": 14 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 200
},
"player 11.aseprite": {
"frame": { "x": 2, "y": 2, "w": 22, "h": 19 },
"rotated": false,
"trimmed": true,
"spriteSourceSize": { "x": 9, "y": 8, "w": 18, "h": 15 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 250
},
"player 12.aseprite": {
"frame": { "x": 51, "y": 2, "w": 23, "h": 18 },
"rotated": false,
"trimmed": true,
"spriteSourceSize": { "x": 9, "y": 9, "w": 19, "h": 14 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 200
}
},
"meta": {
"app": "https://www.aseprite.org/",
"version": "1.3.6-x64",
"image": "player.png",
"format": "RGBA8888",
"size": { "w": 52, "h": 25 },
"size": { "w": 96, "h": 86 },
"scale": "1",
"frameTags": [
{ "name": "idle", "from": 0, "to": 0, "direction": "forward", "color": "#000000ff" },
{ "name": "swim", "from": 1, "to": 1, "direction": "forward", "color": "#000000ff" }
{ "name": "walk", "from": 1, "to": 4, "direction": "forward", "color": "#000000ff" },
{ "name": "swim_idle", "from": 5, "to": 8, "direction": "forward", "color": "#000000ff" },
{ "name": "swim", "from": 9, "to": 12, "direction": "forward", "color": "#000000ff" }
],
"layers": [
{ "name": "Layer 1", "opacity": 255, "blendMode": "normal" }
Expand Down
Binary file modified player.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 69 additions & 11 deletions player.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=12 format=3 uid="uid://mnaxd41w2loc"]
[gd_scene load_steps=14 format=3 uid="uid://mnaxd41w2loc"]

[ext_resource type="Script" path="res://player.gd" id="1_b3cg5"]
[ext_resource type="Texture2D" uid="uid://c4etptninfkid" path="res://player.png" id="2_7u1va"]
Expand Down Expand Up @@ -29,7 +29,7 @@ tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Rect2(30, 2, 20, 21)]
"values": [Rect2(41, 46, 17, 21)]
}
tracks/1/type = "value"
tracks/1/imported = false
Expand All @@ -41,22 +41,22 @@ tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector2(1, 0.5)]
"values": [Vector2(1.5, 0.5)]
}

[sub_resource type="Animation" id="Animation_vou52"]
length = 0.1
length = 0.9
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite:region_rect")
tracks/0/interp = 0
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"times": PackedFloat32Array(0, 0.25, 0.45, 0.7),
"transitions": PackedFloat32Array(1, 1, 1, 1),
"update": 0,
"values": [Rect2(2, 2, 26, 21)]
"values": [Rect2(26, 22, 22, 18), Rect2(26, 2, 23, 18), Rect2(2, 2, 22, 19), Rect2(51, 2, 23, 18)]
}
tracks/1/type = "value"
tracks/1/imported = false
Expand All @@ -65,16 +65,73 @@ tracks/1/path = NodePath("Sprite:offset")
tracks/1/interp = 0
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"times": PackedFloat32Array(0, 0.25, 0.45, 0.7),
"transitions": PackedFloat32Array(1, 1, 1, 1),
"update": 0,
"values": [Vector2(2, -1), Vector2(2.5, 0), Vector2(2, -0.5), Vector2(2.5, 0)]
}

[sub_resource type="Animation" id="Animation_dnhxd"]
length = 0.8
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite:region_rect")
tracks/0/interp = 0
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.2, 0.4, 0.6),
"transitions": PackedFloat32Array(1, 1, 1, 1),
"update": 0,
"values": [Rect2(77, 2, 17, 22), Rect2(21, 64, 17, 20), Rect2(50, 22, 17, 22), Rect2(21, 42, 18, 20)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Sprite:offset")
tracks/1/interp = 0
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 0.2, 0.4, 0.6),
"transitions": PackedFloat32Array(1, 1, 1, 1),
"update": 0,
"values": [Vector2(0.5, 1), Vector2(0.5, 1), Vector2(0.5, 1), Vector2(1, 1)]
}

[sub_resource type="Animation" id="Animation_krkgp"]
length = 1.2
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite:region_rect")
tracks/0/interp = 0
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.4, 0.6, 1),
"transitions": PackedFloat32Array(1, 1, 1, 1),
"update": 0,
"values": [Rect2(2, 47, 17, 21), Rect2(2, 23, 17, 22), Rect2(60, 50, 17, 21), Rect2(69, 26, 17, 22)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Sprite:offset")
tracks/1/interp = 0
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 0.4, 0.6, 1),
"transitions": PackedFloat32Array(1, 1, 1, 1),
"update": 0,
"values": [Vector2(3, 0.5)]
"values": [Vector2(1.5, 0.5), Vector2(1.5, 2), Vector2(1.5, 0.5), Vector2(1.5, 2)]
}

[sub_resource type="AnimationLibrary" id="AnimationLibrary_781fc"]
_data = {
"idle": SubResource("Animation_woum7"),
"swim": SubResource("Animation_vou52")
"swim": SubResource("Animation_vou52"),
"swim_idle": SubResource("Animation_krkgp"),
"walk": SubResource("Animation_dnhxd")
}

[node name="Player" type="CharacterBody2D"]
Expand Down Expand Up @@ -144,3 +201,4 @@ float_target = NodePath("../Sprite")
libraries = {
"": SubResource("AnimationLibrary_781fc")
}
autoplay = "idle"
4 changes: 4 additions & 0 deletions ui.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
extends CanvasLayer

func _ready():
visible = true
5 changes: 4 additions & 1 deletion ui.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[gd_scene load_steps=7 format=3 uid="uid://cjiok5o0qam3w"]
[gd_scene load_steps=8 format=3 uid="uid://cjiok5o0qam3w"]

[ext_resource type="Script" path="res://DeathRect.gd" id="1_e1oy5"]
[ext_resource type="Script" path="res://DebugLabel.gd" id="1_f57q1"]
[ext_resource type="Script" path="res://ui.gd" id="1_xy1r8"]
[ext_resource type="Script" path="res://DebugMessageContainer.gd" id="2_n2sie"]
[ext_resource type="PackedScene" uid="uid://b5jq1hyurpv6l" path="res://debug_messages.tscn" id="3_o0xii"]
[ext_resource type="Script" path="res://VersionLabel.gd" id="4_5o7bk"]
Expand All @@ -11,6 +12,8 @@ _data = [Vector2(0, 0), 0.0, 0.76295, 0, 0, Vector2(1, 1), 0.0, 0.0, 0, 0]
point_count = 2

[node name="UI" type="CanvasLayer"]
visible = false
script = ExtResource("1_xy1r8")

[node name="DeathRect" type="ColorRect" parent="."]
anchors_preset = 15
Expand Down

0 comments on commit 02450b7

Please sign in to comment.