1
Fork 0
mirror of https://github.com/Steffo99/looping-for-loops.git synced 2024-11-21 23:54:23 +00:00

👋 Animate player

This commit is contained in:
Steffo 2020-10-05 15:14:17 +02:00
parent f5161186c7
commit 35f8210b69
6 changed files with 210 additions and 5 deletions

View file

@ -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()

View file

@ -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 )

59
Sprites/Gatto/Body.tres Normal file
View file

@ -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
} ]

23
Sprites/Gatto/Donut.tres Normal file
View file

@ -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
} ]

63
Sprites/Gatto/Legs.tres Normal file
View file

@ -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
} ]

View file

@ -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 )