-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.gd
83 lines (69 loc) · 2.61 KB
/
main.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
extends Node
# The Main is the root scene. It is resposible for setting up and holding references to the other major scenes (UI, GameWorld, etc.). It also (tbd) directs the high-level game logic between major scenes when needed (e.g. main menu to playing game).
# The code for initial players and units is here temporarily. It seems like it would be better in a godot resource(?) file of some kind. However, I don't understand how to use those yet.
onready var collision_flag_manager = get_node("/root/CollisionFlagManager")
onready var game_world = get_node("/root/GameWorld")
var init_players = {
# {player_id : {players kwargs}}
1 : {
'base_position' : Vector2(200, 800), # world coordinates
'facing_angle' : 0, # radians
},
2 : {
'base_position' : Vector2(2200, 800), # world coordinates
'facing_angle' : PI, # radians
},
}
var init_unit_location_scaling = 150 # to scale the relative locations below
var init_units = {
# {"type" : [relative_location, ...] }
'swordsman' : [
Vector2( 1, -1),
Vector2( 1, 0),
Vector2( 1, 1),
],
'archer' : [
Vector2( 0, -1),
Vector2( 0, 0),
Vector2( 0, 1),
],
'cavalry' : [
Vector2( 0, 2),
Vector2( 0, -2),
]
}
func _ready():
game_world.connect("unit_deleted", $ActionSelectionSystem, "_on_unit_deleted")
# Create players and their initial set of units.
for player_id in init_players:
game_world.create_player(player_id)
$HUD.add_new_player(player_id)
$HUD.connect("switch_player", $ActionSelectionSystem, "_on_switch_player")
$HUD/SelectPlayerButton.select(0)
for player_id in init_players:
# Must create units after players for the collision flags
create_player_init_units(player_id)
func create_player_init_units(player_id):
""" Create the initial set of units for a player. """
# Get some info about the player
var p_info = init_players[player_id]
var base_position = p_info['base_position']
var facing_angle = p_info['facing_angle']
# Create all the units
for unit_type in init_units:
for loc in init_units[unit_type]:
# Calculate the unit's position in world coordinates
var direction = loc.rotated(facing_angle)
var relative_position = direction * init_unit_location_scaling
var unit_position = base_position + relative_position
var new_unit = game_world.create_unit(unit_type, unit_position, player_id)
new_unit.connect("mouse_entered_unit",
$ActionSelectionSystem, "_on_GenericUnit_mouse_entered_unit"
)
new_unit.connect("mouse_exited_unit",
$ActionSelectionSystem, "_on_GenericUnit_mouse_exited_unit"
)
func _process(_delta):
#collision_flag_manager.print_physics_layer_info()
#assert(false)
pass