summaryrefslogtreecommitdiff
path: root/Scenes/Player.gd
blob: 057a198e07d1b7577cd2fceb646af80417de1bae (plain)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
extends Entity

# Cube Layout:
# 0
# 1
# 5 3
#   4
# 	2

# Cardinals
#  0
# 1 3
#  2

const chart_side = [
	[4, 2, 1, 3],
	[0, 2, 5, 3],
	[4, 5, 1, 0],
	[1, 5, 4, 0],
	[3, 5, 2, 0],
	[1, 2, 4, 3],
]

const chart_spin = [
	[3, 0, 0, 2],
	[0, 1, 0, 1],
	[0, 2, 3, 0],
	[3, 0, 0, 2],
	[0, 1, 0, 1],
	[0, 2, 3, 0],
]

var symbols = ['1', '3', '5', '2', '4', '6']

var side = 0
var spin = 0
var idle = true

func get_top():
	return symbols[side]

func set_bottom(symbol : String):
	symbols[5 - side] = symbol

func roll(direction : Vector2):
	var cardinal = (get_cardinal(-direction) - spin) % 4

	spin = chart_spin[side][cardinal] + spin
	side = chart_side[side][cardinal]

func get_cardinal(direction: Vector2):
	if direction.y > 0:
		return 0

	if direction.x < 0:
		return 1

	if direction.y < 0:
		return 2

	if direction.x > 0:
		return 3

func get_upper_face():
	return get_top()

func cor_move(args : Array): # args = [Vector3]
	var new_pos = args[0]
	var dir = Vector2(new_pos.x - translation.x, new_pos.z - translation.z)
	$Mesh.roll(dir)

	yield(.cor_move(args), "completed")