@@ -19,10 +19,6 @@ config/icon="res://icon.svg"
|
||||
|
||||
gdscript/warnings/untyped_declaration=1
|
||||
|
||||
[display]
|
||||
|
||||
window/size/always_on_top=true
|
||||
|
||||
[gui]
|
||||
|
||||
theme/custom="res://data/world_theme.tres"
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
extends Node2D
|
||||
class_name Base
|
||||
|
||||
@export var corruption_pattern: ExpansionBase
|
||||
@export var world: World
|
||||
|
||||
@onready var expand_timer: Timer = $ExpandTimer
|
||||
var grid_loc: Vector2i
|
||||
|
||||
const curruption_directions := [Vector2i.LEFT, Vector2i.RIGHT, Vector2i.UP, Vector2i.DOWN]
|
||||
var corruption_tiles: Array[Vector2i] = []
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -14,8 +16,10 @@ func _ready() -> void:
|
||||
world.corrupt_location(grid_loc)
|
||||
|
||||
func _on_expand_timer_timeout() -> void:
|
||||
var corrupt_tile: Vector2i = corruption_tiles.pick_random() + self.curruption_directions.pick_random()
|
||||
while corruption_tiles.has(corrupt_tile):
|
||||
corrupt_tile = corruption_tiles.pick_random() + self.curruption_directions.pick_random()
|
||||
var corrupt_tile: Vector2i = corruption_pattern.expand_next_tile() + grid_loc
|
||||
if corrupt_tile:
|
||||
corruption_tiles.append(corrupt_tile)
|
||||
world.corrupt_location(corrupt_tile)
|
||||
|
||||
func on_corruption_finished() -> void:
|
||||
expand_timer.stop()
|
||||
|
||||
@@ -5,8 +5,10 @@ var base = preload("res://scene/base.tscn")
|
||||
|
||||
func _unhandled_input(event):
|
||||
if event is InputEventMouseButton and event.is_pressed() and event.button_index == MOUSE_BUTTON_LEFT:
|
||||
var build = base.instantiate()
|
||||
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)
|
||||
add_child(build)
|
||||
#world_grid.set_cell(2, world_grid.local_to_map(get_global_mouse_position()), 0, Vector2i(16,2))
|
||||
|
||||
6
scripts/expansion_patterns/expansion_base.gd
Normal file
6
scripts/expansion_patterns/expansion_base.gd
Normal file
@@ -0,0 +1,6 @@
|
||||
class_name ExpansionBase extends Resource
|
||||
|
||||
signal expansion_finished
|
||||
|
||||
func expand_next_tile() -> Vector2i:
|
||||
return Vector2i.ZERO
|
||||
19
scripts/expansion_patterns/expansion_square_pattern.gd
Normal file
19
scripts/expansion_patterns/expansion_square_pattern.gd
Normal file
@@ -0,0 +1,19 @@
|
||||
class_name ExpansionSquarePattern extends ExpansionBase
|
||||
|
||||
const EXPANSION_STAGES: int = 3
|
||||
|
||||
var expansion_stage: int = 0
|
||||
var expansion_tiles: Array[Vector2i] = []
|
||||
|
||||
func expand_next_tile() -> Vector2i:
|
||||
if expansion_tiles.is_empty():
|
||||
if expansion_stage < EXPANSION_STAGES:
|
||||
expansion_stage += 1
|
||||
for x in range(-expansion_stage, expansion_stage + 1):
|
||||
for y in range(-expansion_stage, expansion_stage + 1):
|
||||
if abs(x) == expansion_stage or abs(y) == expansion_stage:
|
||||
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))
|
||||
@@ -1,6 +1,6 @@
|
||||
extends Control
|
||||
|
||||
@onready var resource_container: GridContainer = $ResourceContainer/VBoxContainer/GridContainer
|
||||
@onready var resource_container: GridContainer = $ResourceContainer/MarginContainer/VBoxContainer/GridContainer
|
||||
const SCIFI_TILESHEET = preload("res://assets/scifi_tilesheet@2.png")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user