diff options
author | David Luevano Alvarado <david@luevano.xyz> | 2022-06-05 04:38:44 -0600 |
---|---|---|
committer | David Luevano Alvarado <david@luevano.xyz> | 2022-06-05 04:38:44 -0600 |
commit | e4423cc8490b7f5ec3449f568bf64e81f4d03248 (patch) | |
tree | 167f178e1197c21260f70eaffd0a3375742f3447 /src/tools | |
parent | 36abc689d783774ce4f2d7b5a1bb621d8684be45 (diff) |
add more food types, refactored code and tidy up stuff
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/score_manager/scenes/ScoreLabel.tscn | 2 | ||||
-rw-r--r-- | src/tools/score_manager/scripts/score_label.gd | 3 | ||||
-rw-r--r-- | src/tools/score_manager/scripts/score_manager.gd | 26 | ||||
-rw-r--r-- | src/tools/world_generator/scenes/WorldGenerator.tscn | 1 | ||||
-rw-r--r-- | src/tools/world_generator/scripts/walker_head.gd | 42 | ||||
-rw-r--r-- | src/tools/world_generator/scripts/world_generator.gd | 10 |
6 files changed, 65 insertions, 19 deletions
diff --git a/src/tools/score_manager/scenes/ScoreLabel.tscn b/src/tools/score_manager/scenes/ScoreLabel.tscn index 365aff1..0a078e1 100644 --- a/src/tools/score_manager/scenes/ScoreLabel.tscn +++ b/src/tools/score_manager/scenes/ScoreLabel.tscn @@ -18,7 +18,7 @@ margin_right = 12.0 margin_bottom = 13.0 custom_colors/font_color_shadow = Color( 0, 0, 0, 1 ) custom_fonts/font = ExtResource( 1 ) -text = "x1" +text = "+1" [node name="Timer" type="Timer" parent="Hbox/Label"] one_shot = true diff --git a/src/tools/score_manager/scripts/score_label.gd b/src/tools/score_manager/scripts/score_label.gd index f1ccb9d..13a34c8 100644 --- a/src/tools/score_manager/scripts/score_label.gd +++ b/src/tools/score_manager/scripts/score_label.gd @@ -14,7 +14,7 @@ var texture: Dictionary = { } var alive_time: float = 2.0 -var fmt: String = "x%s" +var fmt: String = "+%s" var points: int @@ -25,7 +25,6 @@ func _ready(): func set_properties(_points: int, color: Color, location: Vector2, type: int=-1) -> void: - print("Constructing") points = _points label.text = fmt % points label.add_color_override("font_color", color) diff --git a/src/tools/score_manager/scripts/score_manager.gd b/src/tools/score_manager/scripts/score_manager.gd index 27a8dd4..492ceb5 100644 --- a/src/tools/score_manager/scripts/score_manager.gd +++ b/src/tools/score_manager/scripts/score_manager.gd @@ -11,6 +11,7 @@ var mutation_stats: Array = [ ] var last_snake_pos: Vector2 = Vector2.ZERO +var snake_location_offset: Vector2 = Vector2(8.0, 8.0) func _ready(): @@ -55,7 +56,7 @@ func _spawn_added_segment_text(amount: int) -> void: if amount > 0: var label: ScoreLabel = SCORE_LABEL.instance() add_child(label) - label.set_properties(amount, Color.green, last_snake_pos, ScoreLabel.Type.BODY_SEGMENT) + label.set_properties(amount, Color.green, last_snake_pos + snake_location_offset, ScoreLabel.Type.BODY_SEGMENT) func _on_snake_path_new_point(coordinates: Vector2) -> void: @@ -63,5 +64,26 @@ func _on_snake_path_new_point(coordinates: Vector2) -> void: func _on_game_over() -> void: - print("Show comparison.") + var max_stats: Stats = _get_max_stats() + SaveData.save_data(max_stats) Event.emit_signal("display_stats", initial_stats, stats, mutation_stats) + + +func _get_max_stats() -> Stats: + var old_stats_dict: Dictionary = initial_stats.get_stats() + var new_stats_dict: Dictionary = stats.get_stats() + var max_stats: Stats = Stats.new() + var max_stats_dict: Dictionary = max_stats.get_stats() + var bool_stats: Array = [ + "trait_dash", + "trait_slow", + "trait_jump" + ] + + for i in old_stats_dict: + if bool_stats.has(i): + max_stats_dict[i] = old_stats_dict[i] or new_stats_dict[i] + else: + max_stats_dict[i] = max(old_stats_dict[i], new_stats_dict[i]) + max_stats.set_stats(max_stats_dict) + return max_stats diff --git a/src/tools/world_generator/scenes/WorldGenerator.tscn b/src/tools/world_generator/scenes/WorldGenerator.tscn index 32ed939..824d298 100644 --- a/src/tools/world_generator/scenes/WorldGenerator.tscn +++ b/src/tools/world_generator/scenes/WorldGenerator.tscn @@ -48,7 +48,6 @@ points = PoolVector2Array( 16, 16, 0, 16, 0, 0, 16, 0 ) [node name="WorldGenerator" type="Node2D"] script = ExtResource( 5 ) -TILEMAP_NP = NodePath("TileMap") [node name="TileMap" type="TileMap" parent="."] tile_set = SubResource( 1 ) diff --git a/src/tools/world_generator/scripts/walker_head.gd b/src/tools/world_generator/scripts/walker_head.gd index dc71db1..2ad9650 100644 --- a/src/tools/world_generator/scripts/walker_head.gd +++ b/src/tools/world_generator/scripts/walker_head.gd @@ -2,8 +2,8 @@ extends Node2D export(NodePath) var TILEMAP_NP: NodePath export(PackedScene) var WALKER_UNIT_NP: PackedScene -export(int, 5, 100, 1) var STARTING_UNIT_COUNT: int = 5 -export(int, 3, 10, 1) var INITIAL_SAFE_ZONE_SIZE: int = 3 +export(int, 4, 100, 1) var STARTING_UNIT_COUNT: int = 6 +export(int, 2, 10, 1) var INITIAL_SAFE_ZONE_SIZE: int = 2 onready var tilemap: TileMap = get_node(TILEMAP_NP) @@ -23,6 +23,15 @@ func _ready() -> void: _fill_empty_space() +func get_cells_around(size: int=INITIAL_SAFE_ZONE_SIZE) -> Array: + var locations: Array = [] + for i in range(-size, size): + for j in range(-size, size): + locations.append(Vector2(i, j)) + + return locations + + func _place_safe_zone() -> void: var size: int = INITIAL_SAFE_ZONE_SIZE for i in range(-size, size): @@ -44,27 +53,40 @@ func _spawn_walker_unit(spawn_position: Vector2) -> void: func _fill_empty_space() -> void: + var locations: Array = _get_empty_cells_location() + for location in locations: + tilemap.set_cellv(location, Global.WORLD_TILE_WALL) + + +func _get_empty_cells_location() -> Array: + var locations: Array = [] var rect: Rect2 = tilemap.get_used_rect() var margin: int = map_margin for x in range(-margin, rect.size.x + margin): - for y in range (-margin, rect.size.y + margin ): - var poses: Vector2= Vector2(rect.position.x + x, rect.position.y + y) - if tilemap.get_cell(int(poses.x), int(poses.y)) == TileMap.INVALID_CELL: - tilemap.set_cellv(poses, Global.WORLD_TILE_WALL) + for y in range (-margin, rect.size.y + margin): + var location: Vector2 = Vector2(rect.position.x + x, rect.position.y + y) + if tilemap.get_cell(int(location.x), int(location.y)) == TileMap.INVALID_CELL: + locations.append(location) + + return locations func _on_world_gen_walker_started(id: int) -> void: - print("Walker unit %s started." % id) + # print("Walker unit %s started." % id) + pass func _on_world_gen_walker_finished(id: int) -> void: - print("Walker unit %s finished." % id) + # print("Walker unit %s finished." % id) + pass func _on_world_gen_walker_died(id: int) -> void: - print("Walker unit %s died." % id) + # print("Walker unit %s died." % id) + pass func _on_world_gen_spawn_walker_unit(location: Vector2) -> void: - print("Spawning new walking unit.") + # print("Spawning new walking unit.") + pass _spawn_walker_unit(location) diff --git a/src/tools/world_generator/scripts/world_generator.gd b/src/tools/world_generator/scripts/world_generator.gd index 5e8626b..5de84ea 100644 --- a/src/tools/world_generator/scripts/world_generator.gd +++ b/src/tools/world_generator/scripts/world_generator.gd @@ -1,11 +1,15 @@ extends Node2D -export(NodePath) var TILEMAP_NP: NodePath -onready var tilemap: TileMap = get_node(TILEMAP_NP) +onready var tilemap: TileMap = $TileMap +onready var walker_head: Node2D = $WalkerHead func get_valid_map_coords() -> Array: - return tilemap.get_used_cells_by_id(Global.WORLD_TILE_PATH) + var safe_area: Array = walker_head.get_cells_around() + var cells_used: Array = tilemap.get_used_cells_by_id(Global.WORLD_TILE_PATH) + for location in safe_area: + cells_used.erase(location) + return cells_used func get_centered_world_position(location: Vector2) -> Vector2: |