Compare commits

...

3 Commits

5 changed files with 165 additions and 8 deletions

View File

@ -11,21 +11,28 @@ func _process(_delta):
func the_pausing(): func the_pausing():
# iterate through the children, allowing only the current active node to run # iterate through the children, allowing only the current active node to run
for i in len(get_children()): for i in len(get_children()):
get_child(i).pause_mode = 0 if i == current_active else 1 if get_child(i).has_signal("scene_finished"): # only change if active var should exist
get_child(i).active = true if i == current_active else false
func the_connecting(): func the_connecting():
# iterate through the children and connect up the child_finished method # iterate through the children and connect up the child_finished method
for i in len(get_children()): for i in len(get_children()):
# don't connect the signal if it doesn't exist
if not get_child(i).has_signal("finished_active"):
continue
# don't connect the signal if already connected # connect the finished signal if it exists and
if get_child(i).get_signal_connection_list("finished_active") == []: # if the failed finished isn't already connected
continue if (get_child(i).has_signal("scene_finished") and
get_child(i).get_signal_connection_list("scene_finished") == []):
get_child(i).connect("scene_finished", self, "child_finished")
get_child(i).connect("finished_active", self, child_finished())
# connect the failed signal if it exists and
# if the failed signal isn't already connected
if (get_child(i).has_signal("scene_failed") and
get_child(i).get_signal_connection_list("scene_failed") == []):
get_child(i).connect("scene_failed", self, "child_failed")
func child_finished(): func child_finished():
@ -33,3 +40,10 @@ func child_finished():
current_active += 1 current_active += 1
if current_active >= len(get_children()): if current_active >= len(get_children()):
current_active = 0 current_active = 0
func child_failed():
# designed to be called from a signal
current_active -= 1
if current_active < 0:
current_active = len(get_children()) - 1

86
Scenes/Battle.gd Normal file
View File

@ -0,0 +1,86 @@
extends Node2D
signal scene_finished
signal scene_failed
var active : bool = false
var character = null setget new_character
var movement_queue = []
var character_original_position : Vector2 = Vector2.ZERO
var character_movement_range = 5
func new_character(chara):
# don't allow non-character characters
if not chara.is_in_group("OnMap"):
return
# clear the movement queue upon a change in character
movement_queue = []
# set the character's map postiton
chara.map_position = $TileMap.world_to_map(chara.position)
chara.target_position = $TileMap.map_to_world(chara.map_position)
chara.target_position += $TileMap.cell_size/2
# set the original_position
character_original_position = chara.map_position
character = chara
func character_movement_input():
if Input.is_action_just_pressed("ui_up"):
movement_queue.append(Vector2.UP)
if Input.is_action_just_pressed("ui_down"):
movement_queue.append(Vector2.DOWN)
if Input.is_action_just_pressed("ui_left"):
movement_queue.append(Vector2.LEFT)
if Input.is_action_just_pressed("ui_right"):
movement_queue.append(Vector2.RIGHT)
if Input.is_action_just_pressed("ui_accept"):
emit_signal("scene_finished")
func character_movement():
#remove uneeded inputs from the queue
for i in len(movement_queue) - 1:
#remove if adjacent values are opposites
if (movement_queue[i].x * movement_queue[i+1].x == -1 or
movement_queue[i].y * movement_queue[i+1].y == -1):
movement_queue[i] = Vector2.ZERO
movement_queue[i+1] = Vector2.ZERO
#remove null values
for i in len(movement_queue):
if movement_queue.find(Vector2.ZERO) != -1:
movement_queue.remove(movement_queue.find(Vector2.ZERO))
if len(movement_queue) == 0:
return
if not character.moving:
var total_distance = character.map_position + movement_queue[0]
total_distance -= character_original_position
#if the character is moving too far, cancel movement and empty queue
if total_distance.length() > character_movement_range:
movement_queue = []
return
#move the character once space in the queue if not moving
character.map_position += movement_queue.pop_front()
character.target_position = $TileMap.map_to_world(character.map_position)
character.target_position += $TileMap.cell_size/2
func _physics_process(_delta):
if not active:
return
character_movement()
character_movement_input()

48
Scenes/Battle.tscn Normal file
View File

@ -0,0 +1,48 @@
[gd_scene load_steps=5 format=2]
[ext_resource path="res://icon.png" type="Texture" id=1]
[ext_resource path="res://Assets/TestTile.png" type="Texture" id=2]
[ext_resource path="res://Scenes/Battle.gd" type="Script" id=3]
[sub_resource type="TileSet" id=1]
0/name = "icon.png 0"
0/texture = ExtResource( 1 )
0/tex_offset = Vector2( 0, 0 )
0/modulate = Color( 1, 1, 1, 1 )
0/region = Rect2( 8, 4, 51, 19 )
0/tile_mode = 0
0/occluder_offset = Vector2( 0, 0 )
0/navigation_offset = Vector2( 0, 0 )
0/shape_offset = Vector2( 0, 0 )
0/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
0/shape_one_way = false
0/shape_one_way_margin = 0.0
0/shapes = [ ]
0/z_index = 0
1/name = "TestTile.png 1"
1/texture = ExtResource( 2 )
1/tex_offset = Vector2( 16, 0 )
1/modulate = Color( 1, 1, 1, 1 )
1/region = Rect2( 0, 0, 160, 64 )
1/tile_mode = 0
1/occluder_offset = Vector2( 0, 0 )
1/navigation_offset = Vector2( 0, 0 )
1/shape_offset = Vector2( 0, 0 )
1/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
1/shape_one_way = false
1/shape_one_way_margin = 0.0
1/shapes = [ ]
1/z_index = 0
[node name="Battle" type="Node2D"]
unique_name_in_owner = true
script = ExtResource( 3 )
[node name="TileMap" type="TileMap" parent="."]
mode = 2
tile_set = SubResource( 1 )
cell_size = Vector2( 128, 64 )
cell_custom_transform = Transform2D( 128, 0, 32, 64, 0, 0 )
centered_textures = true
format = 1
tile_data = PoolIntArray( 65538, 1, 0, 65539, 1, 0, 65540, 1, 0, 65541, 1, 0, 131074, 1, 0, 131075, 1, 0, 131076, 1, 0, 131077, 1, 0, 131078, 0, 0, 196610, 1, 0, 196611, 1, 0, 196612, 1, 0, 196613, 1, 0, 196614, 0, 0, 262144, 0, 0, 262145, 0, 0, 262146, 1, 0, 262147, 1, 0, 262148, 1, 0, 262149, 0, 0, 262150, 0, 0, 327681, 0, 0, 327682, 0, 0, 327683, 0, 0, 327684, 0, 0, 327685, 0, 0, 327686, 0, 0, 393217, 0, 0, 393218, 0, 0, 393219, 0, 0, 393220, 0, 0, 393221, 0, 0, 393222, 0, 0, 458754, 0, 0, 458755, 0, 0, 458756, 0, 0, 458757, 0, 0, 524291, 0, 0, 524292, 0, 0 )

View File

@ -1,5 +1,10 @@
extends Control extends Control
signal scene_finished
signal scene_failed
var active : bool = false
const card_view_scene = preload("res://UI/CardView.tscn") const card_view_scene = preload("res://UI/CardView.tscn")
var character : Character = Character.new() setget update_cards_shown var character : Character = Character.new() setget update_cards_shown

View File

@ -1,6 +1,10 @@
extends Control extends Control
signal dice_selected (dice_value) signal dice_selected (dice_value)
signal scene_finished
signal scene_failed
var active : bool = false
const dice = preload("res://UI/Dice.tscn") const dice = preload("res://UI/Dice.tscn")