Completely refractor the project so the code isn't so terrible #7
@ -1,121 +1,5 @@
|
|||||||
extends Node2D
|
extends Node
|
||||||
|
|
||||||
var movement_queue = []
|
|
||||||
|
|
||||||
var player_to_move : bool = false
|
|
||||||
var player_original_position : Vector2 = Vector2.ZERO
|
|
||||||
var player_movement_range = 5
|
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
# start with the DiceView being selected
|
$"%Battle".character = $Player
|
||||||
$UI/DiceView.selected = true
|
|
||||||
$UI/CardView.selected = false
|
|
||||||
self.player_to_move = false
|
|
||||||
|
|
||||||
$UI/CardView.draw_card("Broadsword")
|
|
||||||
$UI/CardView.draw_card("Sprint")
|
|
||||||
$UI/CardView.draw_card("Magic Carving Knife")
|
|
||||||
|
|
||||||
$UI/DiceView.roll_dice()
|
|
||||||
$UI/DiceView.roll_dice()
|
|
||||||
$UI/DiceView.roll_dice()
|
|
||||||
|
|
||||||
|
|
||||||
# generate all of the OnTile nodes's tile positions
|
|
||||||
for child in get_children():
|
|
||||||
if child.is_in_group("OnMap"):
|
|
||||||
child.map_position = $TileMap.world_to_map(child.position)
|
|
||||||
child.target_position = $TileMap.map_to_world(child.map_position)
|
|
||||||
child.target_position += $TileMap.cell_size/2
|
|
||||||
|
|
||||||
|
|
||||||
func do_damage_around_player(damage, damage_range):
|
|
||||||
for enemy in get_children():
|
|
||||||
|
|
||||||
if not enemy.is_in_group("Enemy"):
|
|
||||||
continue
|
|
||||||
|
|
||||||
if ($Player.map_position - enemy.map_position).length() > damage_range:
|
|
||||||
continue
|
|
||||||
|
|
||||||
enemy.take_damage(damage)
|
|
||||||
|
|
||||||
func do_effect_around_player(effect, effect_range):
|
|
||||||
pass
|
|
||||||
|
|
||||||
func set_player_to_move(movement_range : int = 0):
|
|
||||||
player_to_move = true
|
|
||||||
player_movement_range = movement_range
|
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(delta):
|
|
||||||
|
|
||||||
# player should carry on queued movements no matter what
|
|
||||||
player_movement()
|
|
||||||
|
|
||||||
# note down the player position before moving
|
|
||||||
if not player_to_move:
|
|
||||||
player_original_position = $Player.map_position
|
|
||||||
|
|
||||||
# if the player needs to move, allow the input to be for the player
|
|
||||||
if player_to_move:
|
|
||||||
player_movement_input()
|
|
||||||
return
|
|
||||||
|
|
||||||
# select the card chooser if dice is selected
|
|
||||||
if (Input.is_action_just_pressed("ui_accept")
|
|
||||||
and $UI/DiceView.selected == true):
|
|
||||||
yield(get_tree().create_timer(0.1), "timeout") #TODO BAD WORKAROUND
|
|
||||||
$UI/DiceView.selected = false
|
|
||||||
$UI/CardView.selected = true
|
|
||||||
|
|
||||||
# if all 3 parts are done, select the DiceView again
|
|
||||||
if ($UI/DiceView.selected == false and
|
|
||||||
$UI/CardView.selected == false and
|
|
||||||
self.player_to_move == false):
|
|
||||||
|
|
||||||
$UI/DiceView.selected = true
|
|
||||||
|
|
||||||
|
|
||||||
func player_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"):
|
|
||||||
player_to_move = false
|
|
||||||
|
|
||||||
|
|
||||||
func player_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 $Player.moving:
|
|
||||||
#if the player is moving too far, cancel movement and empty queue
|
|
||||||
if (($Player.map_position + movement_queue[0]
|
|
||||||
- player_original_position).length() > player_movement_range):
|
|
||||||
movement_queue = []
|
|
||||||
return
|
|
||||||
|
|
||||||
#move the character once space in the queue if not moving
|
|
||||||
$Player.map_position += movement_queue.pop_front()
|
|
||||||
$Player.target_position = $TileMap.map_to_world($Player.map_position)
|
|
||||||
$Player.target_position += $TileMap.cell_size/2
|
|
||||||
|
@ -1,93 +1,27 @@
|
|||||||
[gd_scene load_steps=9 format=2]
|
[gd_scene load_steps=7 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://icon.png" type="Texture" id=1]
|
[ext_resource path="res://Scenes/Battle.tscn" type="PackedScene" id=1]
|
||||||
[ext_resource path="res://Characters/Player.tscn" type="PackedScene" id=2]
|
[ext_resource path="res://Characters/Player.tscn" type="PackedScene" id=2]
|
||||||
[ext_resource path="res://Scenes/BattleScene.gd" type="Script" id=3]
|
[ext_resource path="res://Scenes/BattleScene.gd" type="Script" id=3]
|
||||||
[ext_resource path="res://UI/CardContainer.tscn" type="PackedScene" id=4]
|
[ext_resource path="res://UI/CardContainer.tscn" type="PackedScene" id=4]
|
||||||
[ext_resource path="res://UI/DiceView.tscn" type="PackedScene" id=5]
|
[ext_resource path="res://UI/DiceView.tscn" type="PackedScene" id=5]
|
||||||
[ext_resource path="res://Assets/TestTile.png" type="Texture" id=6]
|
[ext_resource path="res://Management/ActiveController.tscn" type="PackedScene" id=8]
|
||||||
[ext_resource path="res://Characters/Enemy.tscn" type="PackedScene" id=7]
|
|
||||||
|
|
||||||
[sub_resource type="TileSet" id=1]
|
[node name="BattleScene" type="Node"]
|
||||||
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( 6 )
|
|
||||||
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="BattleScene" type="Node2D"]
|
|
||||||
script = ExtResource( 3 )
|
script = ExtResource( 3 )
|
||||||
|
|
||||||
[node name="TileMap" type="TileMap" parent="."]
|
[node name="ActiveController" parent="." instance=ExtResource( 8 )]
|
||||||
mode = 2
|
|
||||||
tile_set = SubResource( 1 )
|
[node name="Battle" parent="ActiveController" instance=ExtResource( 1 )]
|
||||||
cell_size = Vector2( 128, 64 )
|
|
||||||
cell_custom_transform = Transform2D( 128, 0, 32, 64, 0, 0 )
|
[node name="DiceView" parent="ActiveController" instance=ExtResource( 5 )]
|
||||||
centered_textures = true
|
unique_name_in_owner = true
|
||||||
format = 1
|
margin_left = 782.0
|
||||||
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 )
|
margin_top = 375.0
|
||||||
|
|
||||||
|
[node name="CardContainer" parent="ActiveController" instance=ExtResource( 4 )]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
margin_top = 351.0
|
||||||
|
margin_right = -425.0
|
||||||
|
|
||||||
[node name="Player" parent="." instance=ExtResource( 2 )]
|
[node name="Player" parent="." instance=ExtResource( 2 )]
|
||||||
position = Vector2( 195, 283 )
|
|
||||||
|
|
||||||
[node name="Camera2D" type="Camera2D" parent="Player"]
|
|
||||||
offset = Vector2( 0, 200 )
|
|
||||||
current = true
|
|
||||||
drag_margin_h_enabled = true
|
|
||||||
drag_margin_v_enabled = true
|
|
||||||
drag_margin_left = 0.3
|
|
||||||
drag_margin_top = 0.05
|
|
||||||
drag_margin_right = 0.3
|
|
||||||
|
|
||||||
[node name="Enemy" parent="." instance=ExtResource( 7 )]
|
|
||||||
position = Vector2( 565, 218 )
|
|
||||||
|
|
||||||
[node name="Enemy2" parent="." instance=ExtResource( 7 )]
|
|
||||||
position = Vector2( 916, 218 )
|
|
||||||
|
|
||||||
[node name="Enemy3" parent="." instance=ExtResource( 7 )]
|
|
||||||
position = Vector2( 1140, 630 )
|
|
||||||
|
|
||||||
[node name="UI" type="CanvasLayer" parent="."]
|
|
||||||
|
|
||||||
[node name="CardView" parent="UI" instance=ExtResource( 4 )]
|
|
||||||
anchor_top = 0.509722
|
|
||||||
anchor_right = 0.754687
|
|
||||||
margin_top = -7.62939e-06
|
|
||||||
margin_right = 1.52588e-05
|
|
||||||
|
|
||||||
[node name="DiceView" parent="UI" instance=ExtResource( 5 )]
|
|
||||||
anchor_left = 0.754687
|
|
||||||
anchor_top = 0.509722
|
|
||||||
margin_left = 1.52588e-05
|
|
||||||
margin_top = -7.62939e-06
|
|
||||||
grow_horizontal = 0
|
|
||||||
|
|
||||||
[connection signal="do_damage" from="UI/CardView" to="." method="do_damage_around_player"]
|
|
||||||
[connection signal="do_effect" from="UI/CardView" to="." method="do_effect_around_player"]
|
|
||||||
[connection signal="do_movement" from="UI/CardView" to="." method="set_player_to_move"]
|
|
||||||
[connection signal="return_dice" from="UI/CardView" to="UI/DiceView" method="roll_dice"]
|
|
||||||
[connection signal="dice_selected" from="UI/DiceView" to="UI/CardView" method="set_currently_holding_dice"]
|
|
||||||
|
Loading…
Reference in New Issue
Block a user