mirror of
https://codeberg.org/ProgramSnail/konkr_game_3d.git
synced 2025-12-27 08:48:45 +00:00
fixes
This commit is contained in:
parent
5408d75267
commit
a795665b54
7 changed files with 462 additions and 366 deletions
|
|
@ -2,8 +2,6 @@ extends Spatial
|
|||
|
||||
# TODO: create something like Vector3i
|
||||
|
||||
var building_destruction_scene = preload("res://scenes/destruction.tscn")
|
||||
|
||||
onready var characters = get_node("/root/Level/Map/Characters")
|
||||
onready var money = get_node("/root/Level/Map/Money")
|
||||
onready var utils = get_node("/root/Level/Map/Utils")
|
||||
|
|
@ -77,9 +75,13 @@ func start_player_turn(player : int):
|
|||
money.pay_tower_salaries(player)
|
||||
money.pay_character_salaries(player)
|
||||
|
||||
func are_tiles_connected(start_position : Vector3, end_position : Vector3, between_tile_cell : int):
|
||||
if start_position.is_equal_approx(end_position):
|
||||
return true
|
||||
func is_tile_connected_to_tiles(start_position : Vector3, end_positions : Array, between_tile_cell : int):
|
||||
var end_positions_dict = {}
|
||||
for end_position in end_positions:
|
||||
end_positions_dict[utils.position_to_string(end_position)] = null
|
||||
|
||||
if end_positions_dict.has(utils.position_to_string(start_position)):
|
||||
return true
|
||||
|
||||
var visited = {}
|
||||
|
||||
|
|
@ -88,7 +90,7 @@ func are_tiles_connected(start_position : Vector3, end_position : Vector3, betwe
|
|||
|
||||
for current_position in to_visit:
|
||||
for direction in directions:
|
||||
if (current_position + direction).is_equal_approx(end_position):
|
||||
if end_positions_dict.has(utils.position_to_string(current_position + direction)):
|
||||
return true
|
||||
if get_tile_cell(current_position + direction) == between_tile_cell and \
|
||||
not visited.has(utils.position_to_string(current_position + direction)):
|
||||
|
|
@ -96,6 +98,9 @@ func are_tiles_connected(start_position : Vector3, end_position : Vector3, betwe
|
|||
to_visit.append(current_position + direction)
|
||||
|
||||
return false
|
||||
|
||||
func are_tiles_connected(start_position : Vector3, end_position : Vector3, between_tile_cell : int):
|
||||
return is_tile_connected_to_tiles(start_position, [end_position], between_tile_cell)
|
||||
|
||||
func is_connected_to_house(start_position : Vector3, tile_cell : int):
|
||||
var visited = {}
|
||||
|
|
@ -131,62 +136,12 @@ func tile_block_level(position : Vector3, inviding_player : int):
|
|||
|
||||
return block_level
|
||||
|
||||
func move_to_tile(position : Vector3):
|
||||
var tile_cell = get_tile_cell(position)
|
||||
var building_cell = get_building_cell(position)
|
||||
var world_position = utils.grid_to_world_position(position)
|
||||
|
||||
# tile to move should be connected with current character tile
|
||||
if not are_tiles_connected(utils.world_to_grid_position(characters.current_character_obj().translation), position, current_player_tile()):
|
||||
return
|
||||
|
||||
# can't go on tile, blocked with >= level, except characters with MAX_LEVEL
|
||||
if tile_block_level(position, characters.current_player) >= characters.current_character_obj().level and \
|
||||
characters.current_character_obj().level != characters.current_character_obj().MAX_LEVEL:
|
||||
return
|
||||
|
||||
if tile_cell == GridMap.INVALID_CELL_ITEM:
|
||||
return
|
||||
|
||||
# move without action (to current player tile)
|
||||
if tile_cell == current_player_tile() and \
|
||||
building_cell == GridMap.INVALID_CELL_ITEM:
|
||||
|
||||
if characters.destroy_other_player_characters(position, characters.current_player) > 0:
|
||||
utils.spawn_on_position(building_destruction_scene, position)
|
||||
|
||||
characters.current_character_obj().translation = world_position
|
||||
|
||||
# move with action (to tile of other player)
|
||||
elif tile_cell != GridMap.INVALID_CELL_ITEM and \
|
||||
tile_cell != current_player_tile() and \
|
||||
has_neighbour_tile_cell(position, current_player_tile()):
|
||||
|
||||
set_tile_cell(position, current_player_tile())
|
||||
|
||||
if building_cell != GridMap.INVALID_CELL_ITEM or \
|
||||
characters.destroy_other_player_characters(position, characters.current_player) > 0:
|
||||
utils.spawn_on_position(building_destruction_scene, position)
|
||||
|
||||
if building_cell != GridMap.INVALID_CELL_ITEM:
|
||||
money.destroy_house(position)
|
||||
|
||||
set_building_cell(position, GridMap.INVALID_CELL_ITEM)
|
||||
|
||||
characters.current_character_obj().translation = world_position
|
||||
|
||||
characters.turn_characters_into_rogues()
|
||||
|
||||
characters.set_next_character()
|
||||
|
||||
func current_player_tile():
|
||||
return player_tiles[characters.current_player]
|
||||
|
||||
func remove_active_player_color(player : int):
|
||||
print("Player tile: ", player_tiles[player])
|
||||
for tile_position in tiles.get_used_cells():
|
||||
if get_tile_cell(tile_position) == ACTIVE_PLAYER_TILES[player]:
|
||||
print("Active tile removed")
|
||||
set_tile_cell(tile_position, DEFAULT_PLAYER_TILES[player])
|
||||
|
||||
func set_active_player_color(player : int):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue