ADD: actors animated sprite.

main
bog 2023-10-01 16:11:38 +02:00
parent f27c52e8ea
commit c3a678513f
8 changed files with 74 additions and 10 deletions

BIN
assets/player.ase Normal file

Binary file not shown.

BIN
assets/player.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 868 B

View File

@ -9,8 +9,8 @@ func _ready():
pass pass
func _state_process(delta): func _state_process(delta):
var sprite : Sprite2D = this.get_node('Sprite2D') var sprite : AnimatedSprite2D = this.get_node('Sprite2D')
var ratio = 0.3 var ratio = 5
sprite.scale.x = max(0, sprite.scale.x - ratio * delta) sprite.scale.x = max(0, sprite.scale.x - ratio * delta)
sprite.scale.y = max(0, sprite.scale.y - ratio * delta) sprite.scale.y = max(0, sprite.scale.y - ratio * delta)

View File

@ -3,8 +3,10 @@ extends Node
var this = null var this = null
var state_name = 'Jump' var state_name = 'Jump'
var m_ratio = 0.0 var m_ratio = 0.0
var m_ratio_start = 1.5
var m_ratio_end = 1.8
var m_jump_state = null var m_jump_state = null
var m_speed = 0.7 var m_speed = 1.2
func _ready(): func _ready():
pass pass
@ -13,7 +15,7 @@ func _state_process(delta):
if m_jump_state != null: if m_jump_state != null:
m_jump_state.call(delta) m_jump_state.call(delta)
else: else:
m_ratio = 0.25 m_ratio = m_ratio_start
m_jump_state = self.go_up m_jump_state = self.go_up
func go_up(delta): func go_up(delta):
@ -22,7 +24,7 @@ func go_up(delta):
sprite.scale.x = m_ratio sprite.scale.x = m_ratio
sprite.scale.y = m_ratio sprite.scale.y = m_ratio
if m_ratio >= 0.38: if m_ratio >= m_ratio_end:
m_jump_state = self.go_down m_jump_state = self.go_down
func go_down(delta): func go_down(delta):
@ -31,7 +33,7 @@ func go_down(delta):
sprite.scale.x = m_ratio sprite.scale.x = m_ratio
sprite.scale.y = m_ratio sprite.scale.y = m_ratio
if m_ratio <= 0.25: if m_ratio <= m_ratio_start:
this.to_normal() this.to_normal()
queue_free() queue_free()

View File

@ -1,7 +1,7 @@
[gd_scene load_steps=4 format=3 uid="uid://c0kqx6dsury58"] [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="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"] [sub_resource type="CircleShape2D" id="CircleShape2D_e2sef"]
radius = 3.16228 radius = 3.16228
@ -9,9 +9,12 @@ radius = 3.16228
[node name="Actor" type="CharacterBody2D" groups=["actors"]] [node name="Actor" type="CharacterBody2D" groups=["actors"]]
script = ExtResource("1_0612w") script = ExtResource("1_0612w")
[node name="Sprite2D" type="Sprite2D" parent="."] [node name="Sprite2D" type="AnimatedSprite2D" parent="."]
scale = Vector2(0.25, 0.25) scale = Vector2(1.5, 1.5)
texture = ExtResource("2_itibm") sprite_frames = ExtResource("2_1hnut")
animation = &"Walk"
frame = 3
frame_progress = 0.69616
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_e2sef") shape = SubResource("CircleShape2D_e2sef")

BIN
src/Actor/player.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 868 B

51
src/Actor/player.tres Normal file
View File

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

View File

@ -4,6 +4,11 @@ var m_world = null
var m_shoot_time = 0.2 var m_shoot_time = 0.2
var m_shoot_timer = 0.0 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): func _physics_process(dt):
var delta = Vector2(0, 0) var delta = Vector2(0, 0)
if Input.is_action_just_pressed("player_jump") and $Actor.is_normal(): 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: if delta.length_squared() > 0:
delta = delta.normalized() delta = delta.normalized()
$Actor.m_dir = delta $Actor.m_dir = delta
$Actor/Sprite2D.play("Walk")
else:
$Actor/Sprite2D.play("Idle")
if $Actor.is_normal() or $Actor.is_jump(): if $Actor.is_normal() or $Actor.is_jump():
$Actor.velocity = delta * $Actor.m_speed $Actor.velocity = delta * $Actor.m_speed