From 35f8210b69c9c310e84c03637a5ce3066441e789 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 5 Oct 2020 15:14:17 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8B=20Animate=20player?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Objects/SpecialObjects/Player.gd | 43 ++++++++++++++++++++ Objects/SpecialObjects/Player.tscn | 26 +++++++++--- Sprites/Gatto/Body.tres | 59 ++++++++++++++++++++++++++++ Sprites/Gatto/Donut.tres | 23 +++++++++++ Sprites/Gatto/Legs.tres | 63 ++++++++++++++++++++++++++++++ project.godot | 1 + 6 files changed, 210 insertions(+), 5 deletions(-) create mode 100644 Sprites/Gatto/Body.tres create mode 100644 Sprites/Gatto/Donut.tres create mode 100644 Sprites/Gatto/Legs.tres diff --git a/Objects/SpecialObjects/Player.gd b/Objects/SpecialObjects/Player.gd index df7b90e..592edac 100644 --- a/Objects/SpecialObjects/Player.gd +++ b/Objects/SpecialObjects/Player.gd @@ -27,6 +27,49 @@ func get_floor(): func up_normal(): return -gravity.normalized() +func _process(delta): + var actual_speed = speed.y - gravity.y + print("Actual speed: %s" % actual_speed) + if Input.is_action_pressed("plr_left"): + if actual_speed < 0: + $Body.animation = "up_left" + $Donut.animation = "up" + $Legs.animation = "up_left" + elif actual_speed > 0: + $Body.animation = "down_left" + $Donut.animation = "down" + $Legs.animation = "down_left" + else: + $Body.animation = "neutral_left" + $Donut.animation = "neutral" + $Legs.animation = "neutral_left" + elif Input.is_action_pressed("plr_right"): + if actual_speed < 0: + $Body.animation = "up_right" + $Donut.animation = "up" + $Legs.animation = "up_right" + elif actual_speed > 0: + $Body.animation = "down_right" + $Donut.animation = "down" + $Legs.animation = "down_right" + else: + $Body.animation = "neutral_right" + $Donut.animation = "neutral" + $Legs.animation = "neutral_right" + else: + if actual_speed < 0: + $Body.animation = "up" + $Donut.animation = "up" + $Legs.animation = "up" + elif actual_speed > 0: + $Body.animation = "down" + $Donut.animation = "down" + $Legs.animation = "down" + else: + $Body.animation = "neutral" + $Donut.animation = "neutral" + $Legs.animation = "neutral" + func _physics_process(_delta): var up_normal = up_normal() diff --git a/Objects/SpecialObjects/Player.tscn b/Objects/SpecialObjects/Player.tscn index fc9d3fd..05d347b 100644 --- a/Objects/SpecialObjects/Player.tscn +++ b/Objects/SpecialObjects/Player.tscn @@ -1,10 +1,12 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=6 format=2] -[ext_resource path="res://Sprites/player_danny_devito.png" type="Texture" id=1] +[ext_resource path="res://Sprites/Gatto/Donut.tres" type="SpriteFrames" id=1] [ext_resource path="res://Objects/SpecialObjects/Player.gd" type="Script" id=2] +[ext_resource path="res://Sprites/Gatto/Body.tres" type="SpriteFrames" id=3] +[ext_resource path="res://Sprites/Gatto/Legs.tres" type="SpriteFrames" id=4] [sub_resource type="RectangleShape2D" id=1] -extents = Vector2( 16, 16 ) +extents = Vector2( 18, 18 ) [node name="Player" type="KinematicBody2D"] collision_layer = 2 @@ -12,8 +14,22 @@ collision_mask = 2147483677 script = ExtResource( 2 ) jump_speed = 493.0 -[node name="Sprite" type="Sprite" parent="."] -texture = ExtResource( 1 ) +[node name="Body" type="AnimatedSprite" parent="."] +frames = ExtResource( 3 ) +animation = "up" +playing = true + +[node name="Donut" type="AnimatedSprite" parent="."] +z_index = 1 +frames = ExtResource( 1 ) +animation = "neutral" +playing = true + +[node name="Legs" type="AnimatedSprite" parent="."] +z_index = 2 +frames = ExtResource( 4 ) +animation = "neutral" +playing = true [node name="CollisionShape2D" type="CollisionShape2D" parent="."] shape = SubResource( 1 ) diff --git a/Sprites/Gatto/Body.tres b/Sprites/Gatto/Body.tres new file mode 100644 index 0000000..20fbb10 --- /dev/null +++ b/Sprites/Gatto/Body.tres @@ -0,0 +1,59 @@ +[gd_resource type="SpriteFrames" load_steps=10 format=2] + +[ext_resource path="res://Sprites/Gatto/gatto_alto_dx.png" type="Texture" id=1] +[ext_resource path="res://Sprites/Gatto/gatto_basso.png" type="Texture" id=2] +[ext_resource path="res://Sprites/Gatto/gatto_alto_lato.png" type="Texture" id=3] +[ext_resource path="res://Sprites/Gatto/gatto_lato.png" type="Texture" id=4] +[ext_resource path="res://Sprites/Gatto/gatto_alto.png" type="Texture" id=5] +[ext_resource path="res://Sprites/Gatto/gatto_basso_dx.png" type="Texture" id=6] +[ext_resource path="res://Sprites/Gatto/gatto_dx.png" type="Texture" id=7] +[ext_resource path="res://Sprites/Gatto/gatto_basso_lato.png" type="Texture" id=8] +[ext_resource path="res://Sprites/Gatto/gatto_centro.png" type="Texture" id=9] + +[resource] +animations = [ { +"frames": [ ExtResource( 5 ) ], +"loop": true, +"name": "up", +"speed": 5.0 +}, { +"frames": [ ExtResource( 2 ) ], +"loop": true, +"name": "down", +"speed": 5.0 +}, { +"frames": [ ExtResource( 9 ) ], +"loop": true, +"name": "neutral", +"speed": 5.0 +}, { +"frames": [ ExtResource( 6 ) ], +"loop": true, +"name": "down_right", +"speed": 5.0 +}, { +"frames": [ ExtResource( 8 ) ], +"loop": true, +"name": "down_left", +"speed": 5.0 +}, { +"frames": [ ExtResource( 7 ) ], +"loop": true, +"name": "neutral_right", +"speed": 5.0 +}, { +"frames": [ ExtResource( 4 ) ], +"loop": true, +"name": "neutral_left", +"speed": 5.0 +}, { +"frames": [ ExtResource( 1 ) ], +"loop": true, +"name": "up_right", +"speed": 1.0 +}, { +"frames": [ ExtResource( 3 ) ], +"loop": true, +"name": "up_left", +"speed": 5.0 +} ] diff --git a/Sprites/Gatto/Donut.tres b/Sprites/Gatto/Donut.tres new file mode 100644 index 0000000..a763b2d --- /dev/null +++ b/Sprites/Gatto/Donut.tres @@ -0,0 +1,23 @@ +[gd_resource type="SpriteFrames" load_steps=4 format=2] + +[ext_resource path="res://Sprites/Gatto/loop_centro.png" type="Texture" id=1] +[ext_resource path="res://Sprites/Gatto/loop_basso.png" type="Texture" id=2] +[ext_resource path="res://Sprites/Gatto/loop_alto.png" type="Texture" id=3] + +[resource] +animations = [ { +"frames": [ ExtResource( 3 ) ], +"loop": true, +"name": "up", +"speed": 5.0 +}, { +"frames": [ ExtResource( 2 ) ], +"loop": true, +"name": "down", +"speed": 5.0 +}, { +"frames": [ ExtResource( 1 ) ], +"loop": true, +"name": "neutral", +"speed": 5.0 +} ] diff --git a/Sprites/Gatto/Legs.tres b/Sprites/Gatto/Legs.tres new file mode 100644 index 0000000..37b9c64 --- /dev/null +++ b/Sprites/Gatto/Legs.tres @@ -0,0 +1,63 @@ +[gd_resource type="SpriteFrames" load_steps=14 format=2] + +[ext_resource path="res://Sprites/Gatto/zampe_dx_3.png" type="Texture" id=1] +[ext_resource path="res://Sprites/Gatto/zampe_basso.png" type="Texture" id=2] +[ext_resource path="res://Sprites/Gatto/zampe_alto.png" type="Texture" id=3] +[ext_resource path="res://Sprites/Gatto/zampe_dx_2.png" type="Texture" id=4] +[ext_resource path="res://Sprites/Gatto/zampe_centro.png" type="Texture" id=5] +[ext_resource path="res://Sprites/Gatto/zampe_lato_2.png" type="Texture" id=6] +[ext_resource path="res://Sprites/Gatto/zampe_alto_dx.png" type="Texture" id=7] +[ext_resource path="res://Sprites/Gatto/zampe_basso_dx.png" type="Texture" id=8] +[ext_resource path="res://Sprites/Gatto/zampe_lato_1.png" type="Texture" id=9] +[ext_resource path="res://Sprites/Gatto/zampe_lato_3.png" type="Texture" id=10] +[ext_resource path="res://Sprites/Gatto/zampe_basso_lato.png" type="Texture" id=11] +[ext_resource path="res://Sprites/Gatto/zampe_dx_1.png" type="Texture" id=12] +[ext_resource path="res://Sprites/Gatto/zampe_alto_lato.png" type="Texture" id=13] + +[resource] +animations = [ { +"frames": [ ExtResource( 3 ) ], +"loop": true, +"name": "up", +"speed": 5.0 +}, { +"frames": [ ExtResource( 2 ) ], +"loop": true, +"name": "down", +"speed": 5.0 +}, { +"frames": [ ExtResource( 5 ) ], +"loop": true, +"name": "neutral", +"speed": 5.0 +}, { +"frames": [ ExtResource( 8 ) ], +"loop": true, +"name": "down_right", +"speed": 5.0 +}, { +"frames": [ ExtResource( 11 ) ], +"loop": true, +"name": "down_left", +"speed": 5.0 +}, { +"frames": [ ExtResource( 12 ), ExtResource( 4 ), ExtResource( 1 ) ], +"loop": true, +"name": "neutral_right", +"speed": 8.0 +}, { +"frames": [ ExtResource( 9 ), ExtResource( 6 ), ExtResource( 10 ) ], +"loop": true, +"name": "neutral_left", +"speed": 8.0 +}, { +"frames": [ ExtResource( 7 ) ], +"loop": true, +"name": "up_right", +"speed": 5.0 +}, { +"frames": [ ExtResource( 13 ) ], +"loop": true, +"name": "up_left", +"speed": 5.0 +} ] diff --git a/project.godot b/project.godot index 0eeba73..4a8a39b 100644 --- a/project.godot +++ b/project.godot @@ -157,3 +157,4 @@ plr_right={ quality/driver/driver_name="GLES2" vram_compression/import_etc=true vram_compression/import_etc2=false +environment/default_clear_color=Color( 0.235294, 0.2, 0.168627, 1 )