Map generation.
This commit is contained in:
@@ -3,13 +3,18 @@ extends Node
|
|||||||
const CHUNK_SIZE: int = 12;
|
const CHUNK_SIZE: int = 12;
|
||||||
const CHUNK_DOUBLE: int = CHUNK_SIZE*2;
|
const CHUNK_DOUBLE: int = CHUNK_SIZE*2;
|
||||||
|
|
||||||
func _get_player_position() -> Vector2i:
|
const GREEN_TILE = Vector2i(1, 1)
|
||||||
return Vector2i(1, 1)
|
|
||||||
|
|
||||||
|
var tilemap: TileMap;
|
||||||
|
|
||||||
|
func _get_player_position() -> Vector2i:
|
||||||
|
var playerPosition: Vector2i = $Ground.local_to_map($Player/AnimatedSprite2D.global_position)
|
||||||
|
print("Playerposition is " + str(playerPosition))
|
||||||
|
return playerPosition
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
pass # Replace with function body.
|
_populate_terrain()
|
||||||
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
@@ -30,11 +35,31 @@ func _populate_terrain():
|
|||||||
for j in range(-CHUNK_DOUBLE, CHUNK_DOUBLE):
|
for j in range(-CHUNK_DOUBLE, CHUNK_DOUBLE):
|
||||||
var pos: Vector2i = player_position + Vector2i(i, j)
|
var pos: Vector2i = player_position + Vector2i(i, j)
|
||||||
if _is_empty(pos):
|
if _is_empty(pos):
|
||||||
_populate_cell(pos, _pick_random_tile())
|
_populate_cell(pos, 1, _pick_random_tile())
|
||||||
|
|
||||||
|
#func _populate_cell(pos: Vector2i, tile: Vector2i) -> void:
|
||||||
|
#$Ground.set_cell.call_deferet(pos, 1, tile, 0)
|
||||||
|
|
||||||
|
func _populate_cell(coords: Vector2i, source_id: int, atlas_coords: Vector2i) -> void:
|
||||||
|
var alternativeTilesCount: int = $Ground.tile_set.get_source(source_id).get_alternative_tiles_count(atlas_coords)
|
||||||
|
var alternativeTileId: int = 0
|
||||||
|
|
||||||
|
if alternativeTilesCount > 0:
|
||||||
|
alternativeTileId = randi_range(0, alternativeTilesCount-1)
|
||||||
|
|
||||||
|
# set_cell(coords: Vector2i, source_id: int = -1, atlas_coords: Vector2i = Vector2i(-1, -1), alternative_tile: int = 0)
|
||||||
|
$Ground.set_cell.call_deferred(coords, source_id, atlas_coords, alternativeTileId)
|
||||||
|
|
||||||
|
func _populate_cell_ds(layer_id: int, coords: Vector2i, source_id: int, atlas_coords: Vector2i) -> void:
|
||||||
|
var alternative_tiles_count = (
|
||||||
|
tilemap.tile_set.get_source(source_id).get_alternative_tiles_count(atlas_coords)
|
||||||
|
)
|
||||||
|
var alternative_tile_id = 0
|
||||||
|
if alternative_tiles_count > 0:
|
||||||
|
alternative_tile_id = randi_range(0, alternative_tiles_count - 1)
|
||||||
|
|
||||||
|
tilemap.set_cell.call_deferred(layer_id, coords, source_id, atlas_coords, alternative_tile_id)
|
||||||
|
|
||||||
func _populate_cell(pos: Vector2i, tile: Vector2i) -> void:
|
|
||||||
$Ground.set_cell.call_deferet(pos, 1, tile, 0)
|
|
||||||
|
|
||||||
func _pick_random_tile() -> Vector2i:
|
func _pick_random_tile() -> Vector2i:
|
||||||
# Make all Tiles green
|
# Make all Tiles green
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ position = Vector2(576, 324)
|
|||||||
rect = Rect2(0, 0, 32, 32)
|
rect = Rect2(0, 0, 32, 32)
|
||||||
|
|
||||||
[node name="Player" type="Area2D" parent="." groups=["Player"]]
|
[node name="Player" type="Area2D" parent="." groups=["Player"]]
|
||||||
|
position = Vector2(100, 100)
|
||||||
|
|
||||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="Player"]
|
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="Player"]
|
||||||
scale = Vector2(0.165, 0.165)
|
scale = Vector2(0.165, 0.165)
|
||||||
|
|||||||
Reference in New Issue
Block a user