ADD: actors animated sprite.
parent
f27c52e8ea
commit
c3a678513f
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 868 B |
|
@ -9,8 +9,8 @@ func _ready():
|
|||
pass
|
||||
|
||||
func _state_process(delta):
|
||||
var sprite : Sprite2D = this.get_node('Sprite2D')
|
||||
var ratio = 0.3
|
||||
var sprite : AnimatedSprite2D = this.get_node('Sprite2D')
|
||||
var ratio = 5
|
||||
|
||||
sprite.scale.x = max(0, sprite.scale.x - ratio * delta)
|
||||
sprite.scale.y = max(0, sprite.scale.y - ratio * delta)
|
||||
|
|
|
@ -3,8 +3,10 @@ extends Node
|
|||
var this = null
|
||||
var state_name = 'Jump'
|
||||
var m_ratio = 0.0
|
||||
var m_ratio_start = 1.5
|
||||
var m_ratio_end = 1.8
|
||||
var m_jump_state = null
|
||||
var m_speed = 0.7
|
||||
var m_speed = 1.2
|
||||
|
||||
func _ready():
|
||||
pass
|
||||
|
@ -13,7 +15,7 @@ func _state_process(delta):
|
|||
if m_jump_state != null:
|
||||
m_jump_state.call(delta)
|
||||
else:
|
||||
m_ratio = 0.25
|
||||
m_ratio = m_ratio_start
|
||||
m_jump_state = self.go_up
|
||||
|
||||
func go_up(delta):
|
||||
|
@ -22,7 +24,7 @@ func go_up(delta):
|
|||
sprite.scale.x = m_ratio
|
||||
sprite.scale.y = m_ratio
|
||||
|
||||
if m_ratio >= 0.38:
|
||||
if m_ratio >= m_ratio_end:
|
||||
m_jump_state = self.go_down
|
||||
|
||||
func go_down(delta):
|
||||
|
@ -31,7 +33,7 @@ func go_down(delta):
|
|||
sprite.scale.x = m_ratio
|
||||
sprite.scale.y = m_ratio
|
||||
|
||||
if m_ratio <= 0.25:
|
||||
if m_ratio <= m_ratio_start:
|
||||
this.to_normal()
|
||||
queue_free()
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://c0kqx6dsury58"]
|
||||
|
||||
[ext_resource type="Script" path="res://Actor/actor.gd" id="1_0612w"]
|
||||
[ext_resource type="Texture2D" uid="uid://blr8qcmuqs5vl" path="res://icon.svg" id="2_itibm"]
|
||||
[ext_resource type="SpriteFrames" uid="uid://o3tacari6pde" path="res://Actor/player.tres" id="2_1hnut"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_e2sef"]
|
||||
radius = 3.16228
|
||||
|
@ -9,9 +9,12 @@ radius = 3.16228
|
|||
[node name="Actor" type="CharacterBody2D" groups=["actors"]]
|
||||
script = ExtResource("1_0612w")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
scale = Vector2(0.25, 0.25)
|
||||
texture = ExtResource("2_itibm")
|
||||
[node name="Sprite2D" type="AnimatedSprite2D" parent="."]
|
||||
scale = Vector2(1.5, 1.5)
|
||||
sprite_frames = ExtResource("2_1hnut")
|
||||
animation = &"Walk"
|
||||
frame = 3
|
||||
frame_progress = 0.69616
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("CircleShape2D_e2sef")
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 868 B |
|
@ -0,0 +1,51 @@
|
|||
[gd_resource type="SpriteFrames" load_steps=7 format=3 uid="uid://o3tacari6pde"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://btxxm0joxgjtv" path="res://Actor/player.png" id="1_xo6xd"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_cvbhj"]
|
||||
atlas = ExtResource("1_xo6xd")
|
||||
region = Rect2(0, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_87gtp"]
|
||||
atlas = ExtResource("1_xo6xd")
|
||||
region = Rect2(0, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_xiss8"]
|
||||
atlas = ExtResource("1_xo6xd")
|
||||
region = Rect2(32, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_n3eh2"]
|
||||
atlas = ExtResource("1_xo6xd")
|
||||
region = Rect2(64, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_62teh"]
|
||||
atlas = ExtResource("1_xo6xd")
|
||||
region = Rect2(96, 0, 32, 32)
|
||||
|
||||
[resource]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_cvbhj")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"Idle",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_87gtp")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_xiss8")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_n3eh2")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_62teh")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"Walk",
|
||||
"speed": 10.0
|
||||
}]
|
|
@ -4,6 +4,11 @@ var m_world = null
|
|||
var m_shoot_time = 0.2
|
||||
var m_shoot_timer = 0.0
|
||||
|
||||
func _process(_delta):
|
||||
var to_mouse: Vector2 = get_global_mouse_position() - $Actor.global_position
|
||||
var angle: float = to_mouse.angle() - PI/2.0
|
||||
$Actor/Sprite2D.rotation = angle
|
||||
|
||||
func _physics_process(dt):
|
||||
var delta = Vector2(0, 0)
|
||||
if Input.is_action_just_pressed("player_jump") and $Actor.is_normal():
|
||||
|
@ -33,6 +38,9 @@ func _physics_process(dt):
|
|||
if delta.length_squared() > 0:
|
||||
delta = delta.normalized()
|
||||
$Actor.m_dir = delta
|
||||
$Actor/Sprite2D.play("Walk")
|
||||
else:
|
||||
$Actor/Sprite2D.play("Idle")
|
||||
|
||||
if $Actor.is_normal() or $Actor.is_jump():
|
||||
$Actor.velocity = delta * $Actor.m_speed
|
||||
|
|
Loading…
Reference in New Issue