Compare commits
2 commits
104e607cc7
...
8040d708e7
| Author | SHA1 | Date | |
|---|---|---|---|
| 8040d708e7 | |||
| b74b472573 |
6 changed files with 21 additions and 44 deletions
|
|
@ -154,7 +154,6 @@ func _on_request_timeout():
|
|||
# Clean up timer
|
||||
request_timer.queue_free()
|
||||
request_timer = null
|
||||
# Call your secondary processing function here
|
||||
write_log("HTTP Request failed, starting server process")
|
||||
write_log(server_path + "/index.js")
|
||||
server_process_id = OS.create_process("node", [server_path + "/index.js"])
|
||||
|
|
|
|||
|
|
@ -1,54 +1,37 @@
|
|||
class_name Game extends Node
|
||||
|
||||
# This script can be attached to your main Game node that contains both
|
||||
# the menu and the chess game components
|
||||
|
||||
@onready var menuContainer = $MenuContainer
|
||||
@onready var chessGame = $ChessGame
|
||||
@onready var stateMachine = $StateMachine
|
||||
|
||||
func _ready():
|
||||
# Show menu on startup
|
||||
if menuContainer:
|
||||
menuContainer.visible = true
|
||||
|
||||
# Hide chess game initially
|
||||
if chessGame:
|
||||
chessGame.visible = false
|
||||
|
||||
# Connect menu signals
|
||||
if menuContainer and menuContainer.has_signal("new_game_requested"):
|
||||
menuContainer.connect("new_game_requested", Callable(self, "_on_new_game_started"))
|
||||
|
||||
func _on_new_game_started():
|
||||
print("Starting new game...")
|
||||
|
||||
# Show chess game
|
||||
if chessGame:
|
||||
chessGame.visible = true
|
||||
|
||||
# You can add additional game initialization logic here if needed
|
||||
# For example, configuring game options based on menu selections
|
||||
|
||||
# Ensure the chess game is properly initialized
|
||||
if !chessGame.is_inside_tree():
|
||||
await chessGame.ready
|
||||
|
||||
# Start game logic
|
||||
_start_game_logic()
|
||||
|
||||
func _start_game_logic():
|
||||
# If StateMachine is already initialized in the Chess game, this may not be needed
|
||||
if stateMachine and stateMachine.has_method("transitionToNextState"):
|
||||
stateMachine.transitionToNextState(Constants.WHITE_TURN)
|
||||
|
||||
# Add any additional game start logic here
|
||||
|
||||
# If you need to open a specific scene or create nodes dynamically:
|
||||
# var chess_scene = load("res://Scenes/ChessGame.tscn").instantiate()
|
||||
# add_child(chess_scene)
|
||||
|
||||
# Handle escape key to show menu during game
|
||||
func _unhandled_input(event):
|
||||
if event is InputEventKey:
|
||||
if event.pressed and event.keycode == KEY_ESCAPE:
|
||||
|
|
@ -58,7 +41,5 @@ func _toggle_menu():
|
|||
if menuContainer:
|
||||
menuContainer.visible = !menuContainer.visible
|
||||
|
||||
# Optional: Pause game when menu is visible
|
||||
if menuContainer.visible and chessGame:
|
||||
# You might want to pause the game or disable input
|
||||
pass
|
||||
|
|
@ -103,7 +103,6 @@ func distance_to_line_segment(point: Vector2, line_start: Vector2, line_end: Vec
|
|||
# Return distance from point to projection
|
||||
return (point - projection).length()
|
||||
|
||||
# Call this when the map changes to update dot highlights
|
||||
func update_dots():
|
||||
if highlight_dots and map_screen != null:
|
||||
generate_dots()
|
||||
|
|
|
|||
|
|
@ -10,40 +10,34 @@ enum RoomType {
|
|||
SHOP,
|
||||
EVENT
|
||||
}
|
||||
|
||||
# Configuration
|
||||
|
||||
var min_levels = 6
|
||||
var max_levels = 12
|
||||
var max_levels = 15
|
||||
var min_nodes_per_level = 2
|
||||
var max_nodes_per_level = 4
|
||||
var positions_per_level = 7 # How many horizontal positions are available (0-6)
|
||||
var max_nodes_per_level = 6
|
||||
var positions_per_level = 6
|
||||
var starting_elo = 1000
|
||||
var final_elo = 2100
|
||||
|
||||
# Internal variables
|
||||
|
||||
var _rng = RandomNumberGenerator.new()
|
||||
var _next_id = 0
|
||||
|
||||
func _init(seed_value = null):
|
||||
# Set seed for reproducible maps if needed
|
||||
# Set seed for reproducible maps
|
||||
if seed_value != null:
|
||||
_rng.seed = seed_value
|
||||
else:
|
||||
_rng.randomize()
|
||||
|
||||
# Main function to generate the map
|
||||
func generate_map():
|
||||
var nodes = []
|
||||
var connections = []
|
||||
_next_id = 0
|
||||
|
||||
# Determine the number of levels
|
||||
var num_levels = _rng.randi_range(min_levels, max_levels)
|
||||
|
||||
# Calculate ELO for each level
|
||||
var elo_step = float(final_elo - starting_elo) / (num_levels - 1)
|
||||
|
||||
# Create starting node (always at position 3, level 0)
|
||||
var start_node = {
|
||||
"id": _get_next_id(),
|
||||
"type": RoomType.STARTING,
|
||||
|
|
@ -63,25 +57,18 @@ func generate_map():
|
|||
}
|
||||
nodes.append(final_node)
|
||||
|
||||
# Generate intermediate levels
|
||||
var levels_nodes = {0: [start_node], (num_levels - 1): [final_node]}
|
||||
|
||||
for level in range(1, num_levels - 1):
|
||||
var level_nodes = []
|
||||
|
||||
# Calculate ELO for this level
|
||||
var level_elo = starting_elo + (elo_step * level)
|
||||
|
||||
# Determine number of nodes for this level
|
||||
var num_nodes = _rng.randi_range(min_nodes_per_level, max_nodes_per_level)
|
||||
|
||||
# Generate available positions and shuffle them
|
||||
var available_positions = []
|
||||
for pos in range(positions_per_level):
|
||||
available_positions.append(pos)
|
||||
available_positions.shuffle()
|
||||
|
||||
# Create nodes for this level
|
||||
|
||||
for i in range(num_nodes):
|
||||
var node_type = _get_random_room_type(level, num_levels)
|
||||
var node = {
|
||||
|
|
@ -186,7 +173,6 @@ func _get_random_room_type(level, total_levels):
|
|||
boss_chance += 0.3
|
||||
|
||||
var roll = _rng.randf()
|
||||
print("_get_random_room_type ", roll, " ", boss_chance, " ", shop_chance, " ", event_chance)
|
||||
if roll < boss_chance:
|
||||
return RoomType.BOSS
|
||||
elif roll < boss_chance + shop_chance:
|
||||
|
|
|
|||
|
|
@ -301,7 +301,7 @@ func highlight_current_node(button):
|
|||
button.add_theme_stylebox_override("normal", style)
|
||||
|
||||
func _on_node_pressed(node_data):
|
||||
if is_node_accessible(node_data):
|
||||
if is_node_accessible(node_data) || is_node_path_accessible(node_data):
|
||||
# Update current node
|
||||
current_node = node_data
|
||||
traversed_node(node_data)
|
||||
|
|
@ -316,6 +316,19 @@ func _on_node_pressed(node_data):
|
|||
func traversed_node(node_data):
|
||||
traversed_map.append(node_data.id)
|
||||
|
||||
func is_node_path_accessible(node_data):
|
||||
if current_node == null:
|
||||
return node_data.type == RoomType.STARTING
|
||||
|
||||
# Check if there's a direct connection from current node to the path travelled
|
||||
for id in traversed_map:
|
||||
var cur = get_node_by_id(id)
|
||||
for connection in map_connections:
|
||||
if connection.from == cur.id and connection.to == node_data.id:
|
||||
return true
|
||||
|
||||
return false
|
||||
|
||||
func is_node_accessible(node_data):
|
||||
if current_node == null:
|
||||
return node_data.type == RoomType.STARTING
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ static func convert_algebraic_to_location(square: String) -> String:
|
|||
file_num = file_num
|
||||
var rank_num = 8 - rank
|
||||
|
||||
# Return location in your game's format
|
||||
return "%d-%d" % [file_num, rank_num]
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue