created basic building class
started building groups temp ui placed #11 #13 #6
This commit is contained in:
@@ -1,25 +1,25 @@
|
||||
extends Node2D
|
||||
class_name Base
|
||||
|
||||
@export var corruption_pattern: ExpansionBase
|
||||
@export var building_data: Building
|
||||
@export var world: World
|
||||
|
||||
@onready var expand_timer: Timer = $ExpandTimer
|
||||
var grid_loc: Vector2i
|
||||
|
||||
#Vector2i(17,7)
|
||||
var corruption_tiles: Array[Vector2i] = []
|
||||
|
||||
func _ready() -> void:
|
||||
grid_loc = world.grid_location(position)
|
||||
world.change_location_data(grid_loc, Constants.TilemapLayers.BUILDINGS, Vector2i(17,7))
|
||||
world.change_location_data(grid_loc, Constants.TilemapLayers.BUILDINGS, building_data.atlas_texture_region)
|
||||
corruption_tiles.append(grid_loc)
|
||||
world.corrupt_location(grid_loc)
|
||||
building_data.corruption_pattern.expansion_finished.connect(on_corruption_finished)
|
||||
|
||||
func _on_expand_timer_timeout() -> void:
|
||||
var corrupt_tile: Vector2i = corruption_pattern.expand_next_tile() + grid_loc
|
||||
if corrupt_tile:
|
||||
corruption_tiles.append(corrupt_tile)
|
||||
world.corrupt_location(corrupt_tile)
|
||||
var corrupt_tile: Vector2i = building_data.corruption_pattern.expand_next_tile() + grid_loc
|
||||
corruption_tiles.append(corrupt_tile)
|
||||
world.corrupt_location(corrupt_tile)
|
||||
|
||||
func on_corruption_finished() -> void:
|
||||
expand_timer.stop()
|
||||
|
||||
8
scripts/building.gd
Normal file
8
scripts/building.gd
Normal file
@@ -0,0 +1,8 @@
|
||||
class_name Building
|
||||
extends Resource
|
||||
|
||||
@export var corruption_pattern: ExpansionBase
|
||||
@export var atlas_texture_region: Vector2i
|
||||
@export var name: String
|
||||
@export var description: String
|
||||
@export var cost: Dictionary
|
||||
@@ -2,13 +2,13 @@ extends Node2D
|
||||
|
||||
@onready var world: World = $".."
|
||||
var base = preload("res://scene/base.tscn")
|
||||
var building = preload("res://data/buildings/hub.tres")
|
||||
|
||||
func _unhandled_input(event):
|
||||
if event is InputEventMouseButton and event.is_pressed() and event.button_index == MOUSE_BUTTON_LEFT:
|
||||
var build: Base = base.instantiate()
|
||||
build.position = get_global_mouse_position()
|
||||
build.world = world
|
||||
build.corruption_pattern = ExpansionSquarePattern.new()
|
||||
build.corruption_pattern.expansion_finished.connect(build.on_corruption_finished)
|
||||
build.building_data = building.duplicate(true)
|
||||
add_child(build)
|
||||
#world_grid.set_cell(2, world_grid.local_to_map(get_global_mouse_position()), 0, Vector2i(16,2))
|
||||
|
||||
18
scripts/expansion_patterns/expansion_random_pattern_large.gd
Normal file
18
scripts/expansion_patterns/expansion_random_pattern_large.gd
Normal file
@@ -0,0 +1,18 @@
|
||||
class_name ExpansionRandomPatternLarge extends ExpansionBase
|
||||
|
||||
const EXPANSION_DISTANCE: int = 8
|
||||
|
||||
var expansion_tiles: Array[Vector2i] = []
|
||||
|
||||
func expand_next_tile() -> Vector2i:
|
||||
if expansion_tiles.is_empty():
|
||||
for i in range(EXPANSION_DISTANCE, 0, -1):
|
||||
expansion_tiles.append(Vector2i(0, i))
|
||||
expansion_tiles.append(Vector2i(0, -i))
|
||||
expansion_tiles.append(Vector2i(i, 0))
|
||||
expansion_tiles.append(Vector2i(-i, 0))
|
||||
for ran in range(1, EXPANSION_DISTANCE):
|
||||
pass
|
||||
if expansion_tiles.size() == 1:
|
||||
expansion_finished.emit()
|
||||
return expansion_tiles.pop_back()
|
||||
@@ -15,5 +15,4 @@ func expand_next_tile() -> Vector2i:
|
||||
expansion_tiles.append(Vector2i(x, y))
|
||||
if expansion_stage == EXPANSION_STAGES and expansion_tiles.size() == 1:
|
||||
expansion_finished.emit()
|
||||
|
||||
return expansion_tiles.pop_at(randi_range(0, expansion_tiles.size() - 1))
|
||||
|
||||
Reference in New Issue
Block a user