updates
This commit is contained in:
parent
0cba7f5ee0
commit
32ed347b58
172 changed files with 5464 additions and 582 deletions
161
table/card_3d.gd
161
table/card_3d.gd
|
|
@ -11,8 +11,16 @@ const BACK := 1
|
|||
const EDGE := 2
|
||||
## Half the card's thickness: a card at this height lies on the table.
|
||||
const REST_HEIGHT := 0.005
|
||||
## Seconds a card takes to slide to a new spot.
|
||||
const GLIDE_TIME := 0.28
|
||||
## Seconds a card takes to slide to a new spot (at normal speed; see Motion).
|
||||
const GLIDE_TIME := 0.26
|
||||
## Speed trails: ghosts left per unit moved, how fast a card must move to leave them, how long one
|
||||
## lasts.
|
||||
const TRAIL_DENSITY := 2.5
|
||||
const TRAIL_MIN_SPEED := 10.0
|
||||
const TRAIL_LIFE := 0.15
|
||||
## Most ghosts a card keeps at once.
|
||||
const TRAIL_MAX := 14
|
||||
const TRAIL_SHADER := preload("res://present/trail.gdshader")
|
||||
|
||||
## Every card jumps instead of sliding (for tests).
|
||||
static var instant := false
|
||||
|
|
@ -61,15 +69,28 @@ var pick_key := "":
|
|||
var _mesh: MeshInstance3D
|
||||
var _body: StaticBody3D
|
||||
var _tween: Tween
|
||||
var _flash_tween: Tween
|
||||
var _flash := Color(0, 0, 0, 0)
|
||||
## Speed trail: whether one is on, its color, where the card was last frame, and the live ghosts.
|
||||
var _trail := false
|
||||
var _trail_color := Color("#22d3ee")
|
||||
var _trail_from := Vector3.ZERO
|
||||
var _ghosts: Array = []
|
||||
static var _ghost_mesh: PlaneMesh
|
||||
static var _ghost_material: ShaderMaterial
|
||||
## Where the last glide was headed, so an unchanged target doesn't restart it.
|
||||
var _goal := Transform3D()
|
||||
var _goal_set := false
|
||||
## On its way out of sight (into a hidden pile): freed when it gets there.
|
||||
var _leaving := false
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_mesh = $Model.find_children("*", "MeshInstance3D")[0]
|
||||
_apply_materials()
|
||||
_apply_uniforms()
|
||||
# Only while a trail is on or fading (see _process).
|
||||
set_process(false)
|
||||
if not Engine.is_editor_hint():
|
||||
_body = StaticBody3D.new()
|
||||
var shape := CollisionShape3D.new()
|
||||
|
|
@ -101,11 +122,140 @@ func glide(xf: Transform3D, instant := false) -> void:
|
|||
_goal_set = true
|
||||
if _tween != null:
|
||||
_tween.kill()
|
||||
if instant or Card3D.instant or not is_inside_tree():
|
||||
if instant or Motion.instant() or not is_inside_tree():
|
||||
transform = xf
|
||||
return
|
||||
_tween = create_tween().set_trans(Tween.TRANS_CUBIC).set_ease(Tween.EASE_OUT)
|
||||
_tween.tween_property(self, "transform", xf, GLIDE_TIME)
|
||||
_tween = create_tween()
|
||||
Motion.rush_in(_tween, self, "transform", xf, GLIDE_TIME)
|
||||
|
||||
|
||||
## Sends the card along `path` (transforms in its parent's space, the goal last) on the motion
|
||||
## curve (gameplay-plan.md §B6): it starts at path[0], rushes to path[1], drifts to path[2] and
|
||||
## rushes out to the goal. Shorter paths skip the drift. `times` are each leg's seconds, `delay`
|
||||
## waits first (at path[0]), and `trail` leaves a speed trail in the rushes.
|
||||
func travel(path: Array, times: Array, delay := 0.0, trail := true, color := Color("#22d3ee"), leave := false) -> void:
|
||||
var goal: Transform3D = path.back()
|
||||
_goal = goal
|
||||
_goal_set = true
|
||||
_leaving = leave
|
||||
if _tween != null:
|
||||
_tween.kill()
|
||||
if Motion.instant() or not is_inside_tree():
|
||||
transform = goal
|
||||
if leave:
|
||||
queue_free()
|
||||
return
|
||||
transform = path[0]
|
||||
_tween = create_tween()
|
||||
if delay > 0.0:
|
||||
_tween.tween_interval(Motion.secs(delay))
|
||||
_tween.tween_callback(func(): _start_trail(trail, color))
|
||||
var legs := path.size() - 1
|
||||
for i in legs:
|
||||
var t: float = times[mini(i, times.size() - 1)]
|
||||
if legs >= 3 and i == 1:
|
||||
Motion.drift(_tween, self, "transform", path[i + 1], t)
|
||||
elif i == legs - 1 and legs > 1:
|
||||
Motion.rush_out(_tween, self, "transform", path[i + 1], t)
|
||||
else:
|
||||
Motion.rush_in(_tween, self, "transform", path[i + 1], t)
|
||||
_tween.tween_callback(func(): _trail = false)
|
||||
if leave:
|
||||
_tween.tween_callback(queue_free)
|
||||
|
||||
|
||||
## Whether the card is still on its way somewhere.
|
||||
func moving() -> bool:
|
||||
return _tween != null and _tween.is_valid() and _tween.is_running()
|
||||
|
||||
|
||||
## Jumps to where the card is headed (skipping its animation).
|
||||
func finish() -> void:
|
||||
if moving():
|
||||
_tween.kill()
|
||||
transform = _goal
|
||||
_trail = false
|
||||
if _leaving:
|
||||
queue_free()
|
||||
if _flash_tween != null:
|
||||
_flash_tween.kill()
|
||||
_set_flash(Color(0, 0, 0, 0))
|
||||
|
||||
|
||||
## A flash of `color` that fades out over `t` seconds, after `delay`.
|
||||
func flash(color: Color, t := 0.5, delay := 0.0) -> void:
|
||||
if Motion.instant() or not is_inside_tree():
|
||||
return
|
||||
if _flash_tween != null:
|
||||
_flash_tween.kill()
|
||||
_flash_tween = create_tween()
|
||||
if delay > 0.0:
|
||||
_flash_tween.tween_interval(Motion.secs(delay))
|
||||
_flash_tween.tween_method(_set_flash, Color(color, 2.2), Color(color, 0.0), Motion.secs(t)).set_trans(Tween.TRANS_EXPO).set_ease(Tween.EASE_OUT)
|
||||
|
||||
|
||||
func _set_flash(c: Color) -> void:
|
||||
_flash = c
|
||||
if _mesh != null:
|
||||
_mesh.set_instance_shader_parameter("flash", c)
|
||||
|
||||
|
||||
func _start_trail(on: bool, color: Color) -> void:
|
||||
_trail = on
|
||||
_trail_color = color
|
||||
_trail_from = position
|
||||
if on:
|
||||
set_process(true)
|
||||
|
||||
|
||||
## Leaves ghosts along the way while the card rushes, and fades the old ones.
|
||||
func _process(delta: float) -> void:
|
||||
if Engine.is_editor_hint():
|
||||
return
|
||||
if _trail and get_parent() != null:
|
||||
var step := position - _trail_from
|
||||
var dist := step.length()
|
||||
if delta > 0.0 and dist / delta >= TRAIL_MIN_SPEED:
|
||||
var n := mini(3, ceili(dist * TRAIL_DENSITY))
|
||||
for i in n:
|
||||
_spawn_ghost(_trail_from.lerp(position, float(i + 1) / n), float(i + 1) / n)
|
||||
_trail_from = position
|
||||
var now := Time.get_ticks_msec() / 1000.0
|
||||
while not _ghosts.is_empty() and now - _ghosts[0].born > TRAIL_LIFE:
|
||||
_ghosts.pop_front().node.queue_free()
|
||||
for g in _ghosts:
|
||||
var k: float = 1.0 - (now - g.born) / TRAIL_LIFE
|
||||
(g.node as GeometryInstance3D).set_instance_shader_parameter("fade", k * k * g.strength)
|
||||
if not _trail and _ghosts.is_empty():
|
||||
set_process(false)
|
||||
|
||||
|
||||
func _spawn_ghost(at: Vector3, strength: float) -> void:
|
||||
if _ghost_mesh == null:
|
||||
_ghost_mesh = PlaneMesh.new()
|
||||
_ghost_mesh.size = Vector2(1.27, 1.778)
|
||||
_ghost_material = ShaderMaterial.new()
|
||||
_ghost_material.shader = TRAIL_SHADER
|
||||
var g := MeshInstance3D.new()
|
||||
g.mesh = _ghost_mesh
|
||||
g.material_override = _ghost_material
|
||||
g.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
|
||||
get_parent().add_child(g)
|
||||
g.transform = Transform3D(transform.basis, at)
|
||||
g.set_instance_shader_parameter("tint", _trail_color)
|
||||
g.set_instance_shader_parameter("fade", strength)
|
||||
# Cards held near the camera (your hand) leave fainter ghosts: they're large on screen.
|
||||
var near := 0.35 if get_parent() is Node3D and get_parent().get_parent() is Camera3D else 1.0
|
||||
_ghosts.append({"node": g, "born": Time.get_ticks_msec() / 1000.0, "strength": (0.15 + 0.35 * strength) * near})
|
||||
if _ghosts.size() > TRAIL_MAX:
|
||||
_ghosts.pop_front().node.queue_free()
|
||||
|
||||
|
||||
func _exit_tree() -> void:
|
||||
for g in _ghosts:
|
||||
if is_instance_valid(g.node):
|
||||
g.node.queue_free()
|
||||
_ghosts = []
|
||||
|
||||
|
||||
func _apply_materials() -> void:
|
||||
|
|
@ -121,3 +271,4 @@ func _apply_uniforms() -> void:
|
|||
return
|
||||
_mesh.set_instance_shader_parameter("highlight", highlight)
|
||||
_mesh.set_instance_shader_parameter("dim", dim)
|
||||
_mesh.set_instance_shader_parameter("flash", _flash)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue