summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenrique Alves <henriquelalves@gmail.com>2022-07-15 19:18:53 -0300
committerHenrique Alves <henriquelalves@gmail.com>2022-07-15 19:18:53 -0300
commitf35b9a8925610ef73b1ccca77c5a301e631cc988 (patch)
tree32b84360283b8e23942dae1b66d99098cd79cd91
parentd8b55a90a940187aef89b9842e88a31b1b600746 (diff)
downloadgamejam-gmtk-2022-f35b9a8925610ef73b1ccca77c5a301e631cc988.tar.gz
gamejam-gmtk-2022-f35b9a8925610ef73b1ccca77c5a301e631cc988.tar.bz2
gamejam-gmtk-2022-f35b9a8925610ef73b1ccca77c5a301e631cc988.zip
add rolling dice
-rw-r--r--Scenes/Dungeon.gd19
-rw-r--r--Scenes/Dungeon.tscn2
-rw-r--r--Scenes/Mesh.gd12
-rw-r--r--Scenes/Player.gd1
-rw-r--r--Scenes/Player.tscn4
5 files changed, 34 insertions, 4 deletions
diff --git a/Scenes/Dungeon.gd b/Scenes/Dungeon.gd
index d8aeb36..d20fcc4 100644
--- a/Scenes/Dungeon.gd
+++ b/Scenes/Dungeon.gd
@@ -22,6 +22,7 @@ func build_floor():
var rand_pos = Vector2(-5, 0)
tiles_entities[rand_pos] = player
+ player.target_position = Vector3()
for i in range(4):
rand_pos = Vector2(randi()%6 - 3, randi()%6 - 3)
@@ -31,6 +32,8 @@ func build_floor():
for key in tiles_entities:
tiles_entities[key].translation = tile_to_pos(key)
+ if tiles_entities[key].get("target_position") != null:
+ tiles_entities[key].target_position = tile_to_pos(key)
func tile_to_pos(tile : Vector2):
return Vector3(tile.x, 0, -tile.y)
@@ -38,6 +41,14 @@ func tile_to_pos(tile : Vector2):
func pos_to_tile(pos: Vector3):
return Vector2(round(pos.x), round(-pos.z))
+func _process(delta):
+ for tile in tiles_entities.keys():
+ if tiles_entities[tile].get("target_position") != null:
+ var entity = tiles_entities[tile]
+ var new_pos = entity.target_position
+ var cur_pos = entity.translation
+ entity.translation = lerp(cur_pos, new_pos, delta * 8)
+
func _input(event):
if event is InputEventKey and event.is_pressed() and not event.is_echo():
if event.scancode == KEY_UP:
@@ -50,12 +61,16 @@ func _input(event):
move_player(Vector2(-1,0))
func move_player(dir: Vector2):
- var curr_tile = pos_to_tile(player.translation)
+ var curr_tile = pos_to_tile(player.target_position)
var new_tile = curr_tile + dir
+ print(new_tile)
+
if tiles_entities.has(new_tile):
return
tiles_entities.erase(curr_tile)
tiles_entities[new_tile] = player
- player.translation = tile_to_pos(new_tile)
+
+ player.target_position = tile_to_pos(new_tile)
+ player.get_node("Mesh").roll(dir)
diff --git a/Scenes/Dungeon.tscn b/Scenes/Dungeon.tscn
index b2369de..dca3c18 100644
--- a/Scenes/Dungeon.tscn
+++ b/Scenes/Dungeon.tscn
@@ -13,4 +13,4 @@ mesh = SubResource( 1 )
material/0 = null
[node name="Camera" type="Camera" parent="."]
-transform = Transform( 0.999945, 0.0103301, -0.00192307, 0, 0.183018, 0.98311, 0.0105076, -0.983055, 0.183008, -0.265683, 23.6788, 4.79274 )
+transform = Transform( 0.999945, 0.0103301, -0.00192307, 0, 0.183018, 0.98311, 0.0105076, -0.983055, 0.183008, -0.265683, 13.015, 5.46677 )
diff --git a/Scenes/Mesh.gd b/Scenes/Mesh.gd
new file mode 100644
index 0000000..3a30c36
--- /dev/null
+++ b/Scenes/Mesh.gd
@@ -0,0 +1,12 @@
+extends MeshInstance
+
+var target_basis : Basis
+
+func _ready():
+ target_basis = transform.basis
+
+func _process(delta):
+ transform.basis = transform.basis.slerp(target_basis, delta*8)
+
+func roll(dir : Vector2):
+ target_basis = target_basis.rotated(Vector3(-dir.y,0,-dir.x), deg2rad(90))
diff --git a/Scenes/Player.gd b/Scenes/Player.gd
index d25de1c..7632d8d 100644
--- a/Scenes/Player.gd
+++ b/Scenes/Player.gd
@@ -1,5 +1,6 @@
extends Spatial
+var target_position : Vector3
func get_upper_face():
return 1
diff --git a/Scenes/Player.tscn b/Scenes/Player.tscn
index cec4af0..8bfbdd1 100644
--- a/Scenes/Player.tscn
+++ b/Scenes/Player.tscn
@@ -1,6 +1,7 @@
-[gd_scene load_steps=4 format=2]
+[gd_scene load_steps=5 format=2]
[ext_resource path="res://Scenes/Player.gd" type="Script" id=1]
+[ext_resource path="res://Scenes/Mesh.gd" type="Script" id=2]
[sub_resource type="CubeMesh" id=2]
size = Vector3( 1, 1, 1 )
@@ -16,3 +17,4 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0 )
mesh = SubResource( 2 )
skeleton = NodePath("../..")
material/0 = SubResource( 4 )
+script = ExtResource( 2 )