basic piece animation

This commit is contained in:
mehbark 2025-05-02 20:42:32 -04:00
parent 1609fd4ac0
commit 350717a4ec
3 changed files with 27 additions and 3 deletions

View file

@ -3,7 +3,7 @@ extends Node3D
@onready var camera: Camera3D = $Camera
var hist := UndoRedo.new()
@onready var board := Board.from_string("")
@onready var board: Board = $Board
var player: Piece
var level_num := -1
var levels_src: PackedStringArray
@ -78,6 +78,7 @@ func won() -> bool:
return true
func advance_level():
hist.clear_history()
level_num += 1
if level_num >= levels_src.size():
print("you win")

View file

@ -1,6 +1,7 @@
[gd_scene load_steps=5 format=3 uid="uid://lrk2whqxl0w0"]
[gd_scene load_steps=6 format=3 uid="uid://lrk2whqxl0w0"]
[ext_resource type="Script" uid="uid://c707s0tgd88pg" path="res://main.gd" id="1_ig7tw"]
[ext_resource type="Script" uid="uid://c8ywa33v3jq7t" path="res://board.gd" id="2_0xm2m"]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_ig7tw"]
ground_bottom_color = Color(0.270778, 0.538085, 0.397052, 1)
@ -31,3 +32,7 @@ aabb = AABB(-0.25, 0, -0.25, 2, 2, 2)
[node name="BottomRight" type="VisibleOnScreenNotifier3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.25, 0, 0.25)
aabb = AABB(0, 0, 0, 2, 2, 2)
[node name="Board" type="Node3D" parent="."]
script = ExtResource("2_0xm2m")
metadata/_custom_type_script = "uid://c8ywa33v3jq7t"

View file

@ -13,16 +13,26 @@ enum Type {
Player,
}
## squares per second
@export_range(0.1, 100) var anim_speed := 10.0
# logical position
@export var lpos: Vector2i:
get:
return lpos
set(val):
lpos = val
position = Vector3(val.x, 0, val.y)
position = target_pos
start_pos = position
target_pos = Vector3(lpos.x, position.y, lpos.y)
anim_progress = 0
@export var type: Piece.Type
@onready var start_pos := position
@onready var target_pos := position
@onready var anim_progress := 1.0
func do_move(move: Vector2i) -> Callable:
return func():
lpos += move
@ -50,3 +60,11 @@ static func box(lpos: Vector2i) -> Piece:
static func player(lpos: Vector2i) -> Piece:
return make(lpos, Piece.Type.Player, PLAYER)
func _ready() -> void:
lpos = lpos
anim_progress = 1
func _process(delta: float) -> void:
anim_progress = min(1, anim_progress + anim_speed*delta)
position = start_pos.lerp(target_pos, anim_progress)