Skip to content

Commit c972af3

Browse files
committed
Re-add the proper Grid.gd and Pawn.gd files
1 parent a318ea1 commit c972af3

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
extends TileMap
2+
3+
enum CELL_TYPES { ACTOR, OBSTACLE, OBJECT }
4+
export(NodePath) var dialogue_ui
5+
6+
func _ready():
7+
for child in get_children():
8+
set_cellv(world_to_map(child.position), child.type)
9+
10+
11+
func get_cell_pawn(cell, type = ACTOR):
12+
for node in get_children():
13+
if node.type != type:
14+
continue
15+
if world_to_map(node.position) == cell:
16+
return(node)
17+
18+
19+
func request_move(pawn, direction):
20+
var cell_start = world_to_map(pawn.position)
21+
var cell_target = cell_start + direction
22+
23+
var cell_tile_id = get_cellv(cell_target)
24+
match cell_tile_id:
25+
-1:
26+
set_cellv(cell_target, ACTOR)
27+
set_cellv(cell_start, -1)
28+
return map_to_world(cell_target) + cell_size / 2
29+
OBJECT, ACTOR:
30+
var target_pawn = get_cell_pawn(cell_target, cell_tile_id)
31+
print("Cell %s contains %s" % [cell_target, target_pawn.name])
32+
33+
if not target_pawn.has_node("DialoguePlayer"):
34+
return
35+
get_node(dialogue_ui).show_dialogue(pawn, target_pawn.get_node("DialoguePlayer"))
36+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
extends Node2D
2+
3+
enum CELL_TYPES { ACTOR, OBSTACLE, OBJECT }
4+
export(CELL_TYPES) var type = ACTOR
5+
6+
var active = true setget set_active
7+
8+
func set_active(value):
9+
active = value
10+
set_process(value)
11+
set_process_input(value)

0 commit comments

Comments
 (0)