summaryrefslogtreecommitdiff
path: root/Scenes
diff options
context:
space:
mode:
authorHenrique Alves <henriquelalves@gmail.com>2022-07-15 23:24:51 -0300
committerHenrique Alves <henriquelalves@gmail.com>2022-07-15 23:24:51 -0300
commit85c76d146775a5495585584925397828d12bc840 (patch)
tree4e0f79e2d8484ea034e108acc0809bf21bdda386 /Scenes
parentf45f5d0417caaf91e5f781b2ac9d2fabefe4f56f (diff)
parent8ab8de00a9f542ca9dbcbd927d6824575d02e740 (diff)
downloadgamejam-gmtk-2022-85c76d146775a5495585584925397828d12bc840.tar.gz
gamejam-gmtk-2022-85c76d146775a5495585584925397828d12bc840.tar.bz2
gamejam-gmtk-2022-85c76d146775a5495585584925397828d12bc840.zip
Merge remote-tracking branch 'origin/main'
Diffstat (limited to 'Scenes')
-rw-r--r--Scenes/Dungeon.gd87
-rw-r--r--Scenes/Entity.gd35
-rw-r--r--Scenes/Player.gd18
3 files changed, 71 insertions, 69 deletions
diff --git a/Scenes/Dungeon.gd b/Scenes/Dungeon.gd
index f49770a..00cee84 100644
--- a/Scenes/Dungeon.gd
+++ b/Scenes/Dungeon.gd
@@ -4,22 +4,18 @@ const Player = preload("res://Scenes/Player.tscn")
const Obstacle = preload("res://Scenes/Obstacle.tscn")
const Monster = preload("res://Scenes/Monster.tscn")
-onready var player : Entity = null
onready var camera = $Pitch
-onready var idle = true
+onready var player : Entity = null
-onready var tiles_entities = {
-}
+var input : Vector2
-onready var tiles_floor = {
-}
+var tiles_entities = {}
+var tiles_floor = {}
-# Called when the node enters the scene tree for the first time.
func _ready():
randomize()
build_floor()
-
func build_floor():
player = Player.instance()
add_child(player)
@@ -44,50 +40,44 @@ func build_floor():
camera.follow(player)
-func tile_to_pos(tile : Vector2):
- return Vector3(tile.x, 0, -tile.y)
-
-func pos_to_tile(pos: Vector3):
- return Vector2(round(pos.x), round(-pos.z))
-
func _process(delta):
- idle = true
var actionables = get_tree().get_nodes_in_group("actionables")
#TODO O T I M I Z A R
+ var idle = true
+
for actionable in actionables:
var entity : Entity = actionable
if entity.actions_queue.size() > 0:
idle = false
break
-func check_tile(entity):
- pass
+ if not idle or input == Vector2.ZERO:
+ return
+
+ move_player(input)
+ input = Vector2.ZERO
+
+ for actionable in actionables:
+ actionable.play_actions()
func _input(event):
- if not idle: return
-
- var turn = false
-
- if event is InputEventKey and event.is_pressed() and not event.is_echo():
- if event.scancode == KEY_UP:
- turn = true
- move_player(Vector2(0,1))
- elif event.scancode == KEY_DOWN:
- turn = true
- move_player(Vector2(0,-1))
- elif event.scancode == KEY_RIGHT:
- turn = true
- move_player(Vector2(1,0))
- elif event.scancode == KEY_LEFT:
- turn = true
- move_player(Vector2(-1,0))
-
- if turn:
- var actionables = get_tree().get_nodes_in_group("actionables")
- for actionable in actionables:
- actionable.play_actions()
+ if input != Vector2.ZERO:
+ return
+
+ if not (event is InputEventKey) or not event.is_pressed() or event.is_echo():
+ return
+
+ match event.scancode:
+ KEY_UP:
+ input = Vector2(0,+1)
+ KEY_DOWN:
+ input = Vector2(0,-1)
+ KEY_RIGHT:
+ input = Vector2(+1,0)
+ KEY_LEFT:
+ input = Vector2(-1,0)
func player_check_attack(tile):
pass
@@ -102,16 +92,23 @@ func player_check_attack(tile):
# monsters move+attack
# check tile monsters
-
-func move_player(dir: Vector2):
- var curr_tile = pos_to_tile(player.translation)
- var new_tile = curr_tile + dir
+func move_player(dir : Vector2):
+ var cur_tile = pos_to_tile(player.translation)
+ var new_tile = cur_tile + dir
if tiles_entities.has(new_tile):
return
- tiles_entities.erase(curr_tile)
+ tiles_entities.erase(cur_tile)
tiles_entities[new_tile] = player
- player.actions_queue.append(["cor_move_entity", [tile_to_pos(new_tile)]])
+ #player_check_attack(new_tile)
+
+ player.add_action("cor_move", [tile_to_pos(new_tile)])
player.roll(dir)
+
+func tile_to_pos(tile : Vector2):
+ return Vector3(tile.x, 0, -tile.y)
+
+func pos_to_tile(pos: Vector3):
+ return Vector2(round(pos.x), round(-pos.z))
diff --git a/Scenes/Entity.gd b/Scenes/Entity.gd
index 3984c24..49aa823 100644
--- a/Scenes/Entity.gd
+++ b/Scenes/Entity.gd
@@ -7,26 +7,31 @@ export(bool) var actionable
var actions_queue : Array = []
func _ready():
- if actionable: add_to_group("actionables")
+ if actionable:
+ add_to_group("actionables")
+
+func add_action(name : String, args : Array):
+ actions_queue.append([name, args])
func play_actions():
- while actions_queue.size() > 0:
- var action = actions_queue[0] # action => [ "cor_name", X ]
- yield(call(action[0], action[1]), "completed")
- actions_queue.pop_front()
+ while not actions_queue.empty():
+ var action = actions_queue[0]
-func cor_move_entity(args : Array): # args = [Vector3]
- var new_pos = args[0]
+ var name = action[0]
+ var args = action[1]
+
+ yield(call(name, args), "completed")
+ actions_queue.pop_front()
- var finished = false
+func cor_move(args : Array): # args = [Vector3]
+ var next_pos = args[0]
- while not finished:
- var cur_pos = translation
+ while true:
var delta = get_process_delta_time()
- translation = lerp(cur_pos, new_pos, delta * 14)
+ translation = lerp(translation, next_pos, delta * 14)
- if abs((cur_pos - new_pos).length()) <= 10e-3:
- translation = new_pos
- finished = true
+ if abs((translation - next_pos).length()) <= 10e-3:
+ translation = next_pos
+ break
- yield(get_tree(),"idle_frame")
+ yield(get_tree(), "idle_frame")
diff --git a/Scenes/Player.gd b/Scenes/Player.gd
index 2e587bc..1666ba2 100644
--- a/Scenes/Player.gd
+++ b/Scenes/Player.gd
@@ -39,22 +39,15 @@ var idle = true
func get_top():
return symbols[side]
-func set_bottom(symbol: String):
+func set_bottom(symbol : String):
symbols[5 - side] = symbol
-func roll(direction: Vector2):
+func roll(direction : Vector2):
var cardinal = (get_cardinal(-direction) - spin) % 4
spin = chart_spin[side][cardinal] + spin
side = chart_side[side][cardinal]
-func cor_move_entity(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_entity(args), "completed")
-
func get_cardinal(direction: Vector2):
if direction.y > 0:
return 0
@@ -70,3 +63,10 @@ func get_cardinal(direction: Vector2):
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")