-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor weapon and chunk instantiation (#32)
- Loading branch information
1 parent
797cd4a
commit f14647d
Showing
4 changed files
with
26 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,26 @@ | ||
class_name OuterWorldChunkGen | ||
extends Marker2D | ||
|
||
const CHUNK_SIZE = 16 | ||
const TILE_SIZE = 64 | ||
const CHUNK_WIDTH = CHUNK_SIZE * TILE_SIZE | ||
const CHUNK_SCENE: PackedScene = preload("res://src/world/chunks/chunk.tscn") | ||
|
||
@export var player: Player | ||
|
||
var _chunks: Dictionary = {} | ||
|
||
|
||
func _process(_delta: float) -> void: | ||
var player_chunk: Vector2i = Vector2i(floor(player.global_position / CHUNK_WIDTH)) | ||
var player_chunk: Vector2i = Vector2i(floor(player.global_position / Chunk.CHUNK_WIDTH)) | ||
|
||
for dx in [-1, 0, 1]: | ||
for dy in [-1, 0, 1]: | ||
var chunk_coord: Vector2i = player_chunk + Vector2i(dx, dy) | ||
var chunk_coordinates: Vector2i = player_chunk + Vector2i(dx, dy) | ||
|
||
if not _chunks.has(chunk_coord): | ||
var chunk: Chunk = CHUNK_SCENE.instantiate() | ||
chunk.position = chunk_coord * CHUNK_WIDTH | ||
if not _chunks.has(chunk_coordinates): | ||
var chunk: Chunk = Chunk.instantiate(chunk_coordinates) | ||
add_child(chunk) | ||
_chunks[chunk_coord] = chunk | ||
_chunks[chunk_coordinates] = chunk | ||
|
||
for chunk_coord in _chunks: | ||
if (chunk_coord - player_chunk).length() >= 3: | ||
var chunk: Chunk = _chunks.get(chunk_coord) | ||
for chunk_coordinates in _chunks: | ||
if (chunk_coordinates - player_chunk).length() >= 3: | ||
var chunk: Chunk = _chunks.get(chunk_coordinates) | ||
|
||
if _chunks.erase(chunk_coord): | ||
if _chunks.erase(chunk_coordinates): | ||
chunk.queue_free() |