-
Notifications
You must be signed in to change notification settings - Fork 0
/
JunkPiece.gd
58 lines (47 loc) · 1.4 KB
/
JunkPiece.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
extends RigidBody3D
var meshInst : GeometryInstance3D
var mouseTime
@export var pieceType : GlobalEnum.PieceType
var data : PieceData
func _ready():
# var cs = CollisionShape3D.new()
# var s = SphereShape3D.new()
# s.radius = 0.1
# cs.shape = s
# self.add_child(cs)
var kids = self.get_children()
meshInst = kids.filter(func(node): return node.get_class() == "MeshInstance3D")[0]
func _mouse_enter():
mouseTime = Time.get_ticks_msec()
sleeping = false
Engine.set_meta("LastTouched", self)
func _mouse_exit():
if self.freeze:
pass
if self == Engine.get_meta("LastTouched"):
Engine.set_meta("LastTouched", null)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
if data == null:
return
# Emission
var emitCol = Color.BLACK
var colorCached = PieceData.getColorCached(data.colorIdx)
if self.freeze:
var c1 = colorCached
var c2 = colorCached
c1.h -= 0.01
c2.h += 0.01
emitCol = lerp(c1,c2, sin(Time.get_ticks_msec() / 100.0))
elif mouseTime != null:
var emitVal = 0.0
var mt = Time.get_ticks_msec() - mouseTime
if 1000.0 > mt:
emitVal = (1000.0 - mt) / 1000.0
else:
mouseTime = null
emitCol = lerp(Color.BLACK, colorCached, emitVal)
meshInst.set_instance_shader_parameter("Color", colorCached)
meshInst.set_instance_shader_parameter("Emission", emitCol)
if transform.origin.y < -5.0:
transform = Transform3D.IDENTITY