Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified project/assets/tilemap/dark_forest/forest_border.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 7 additions & 4 deletions project/modules/level/level.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ class_name Level
extends Node2D

const CORPSE_ITEM_COUNT = 5
const BORDER_TILE_SOURCE_ID = 3
const NUM_GRASS_VARIATIONS = 3
const SAFE_ZONE_SOURCE_ID = 4

@export var size: Vector2i = Vector2i(50, 50)

@export var terrain: TileMapLayer
@export var terrain_border: TileMapLayer
@export var player_scene: PackedScene

var item_library = []
Expand Down Expand Up @@ -42,15 +43,17 @@ func build():
for y in size.y:
var walkable: bool = MazeGenerator.map[x][y]
var pos := Vector2i(x, y)
terrain.set_cell(pos, randi() % BORDER_TILE_SOURCE_ID if walkable else BORDER_TILE_SOURCE_ID, Vector2.ZERO)
terrain.set_cell(pos, randi() % NUM_GRASS_VARIATIONS, Vector2.ZERO)
if not walkable:
terrain_border.set_cell(pos, 0, Vector2i.ZERO)

for tile in safezones:
terrain.set_cell(tile, SAFE_ZONE_SOURCE_ID, Vector2i.ZERO)

func find_nearest_walkable_tile(pos: Vector2)-> Vector2i:
var nearest = null
for tile in terrain.get_used_cells():
if terrain.get_cell_tile_data(tile).get_custom_data("border"):
if tile in terrain_border.get_used_cells():
continue
if not nearest or pos.distance_to(terrain.map_to_local(tile)) < pos.distance_to(terrain.map_to_local(nearest)):
nearest= tile
Expand All @@ -68,7 +71,7 @@ func spawn_enemies():
enemies.append(load(enemy_path + "/" + res_file))

for tile in terrain.get_used_cells():
if terrain.get_cell_source_id(tile) < BORDER_TILE_SOURCE_ID:
if tile in terrain_border.get_used_cells():
continue
for enemy in enemies:
if randf() * 100 < enemy.spawn_chance:
Expand Down
20 changes: 18 additions & 2 deletions project/modules/level/level.tscn
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
[gd_scene load_steps=5 format=3 uid="uid://cs7lmwh0o3s0u"]
[gd_scene load_steps=8 format=3 uid="uid://cs7lmwh0o3s0u"]

[ext_resource type="Script" uid="uid://bdgvj6g6iojvq" path="res://modules/level/level.gd" id="1_lsyog"]
[ext_resource type="PackedScene" uid="uid://h2lk2e0pam0g" path="res://modules/player/player.tscn" id="2_hetbt"]
[ext_resource type="TileSet" uid="uid://o8taylafv3nk" path="res://modules/level/terrain_tile_set.tres" id="3_ktxx3"]
[ext_resource type="PackedScene" uid="uid://6s5vq2qeopxv" path="res://modules/hud/hud.tscn" id="4_hetbt"]
[ext_resource type="Texture2D" uid="uid://7462qckh0dm0" path="res://assets/tilemap/dark_forest/forest_border.png" id="4_ktxx3"]

[node name="Level" type="Node2D" node_paths=PackedStringArray("terrain")]
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_es54h"]
texture = ExtResource("4_ktxx3")
texture_region_size = Vector2i(384, 384)
0:0/0 = 0
0:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-128, -128, 128, -128, 128, 128, -128, 128)

[sub_resource type="TileSet" id="TileSet_m45tf"]
tile_size = Vector2i(256, 256)
physics_layer_0/collision_layer = 2
sources/0 = SubResource("TileSetAtlasSource_es54h")

[node name="Level" type="Node2D" node_paths=PackedStringArray("terrain", "terrain_border")]
script = ExtResource("1_lsyog")
terrain = NodePath("Terrain")
terrain_border = NodePath("Terrain Border")
player_scene = ExtResource("2_hetbt")

[node name="Terrain" type="TileMapLayer" parent="."]
tile_set = ExtResource("3_ktxx3")

[node name="Terrain Border" type="TileMapLayer" parent="."]
tile_set = SubResource("TileSet_m45tf")

[node name="Hud" parent="." instance=ExtResource("4_hetbt")]
13 changes: 1 addition & 12 deletions project/modules/level/terrain_tile_set.tres
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
[gd_resource type="TileSet" load_steps=11 format=3 uid="uid://o8taylafv3nk"]
[gd_resource type="TileSet" load_steps=9 format=3 uid="uid://o8taylafv3nk"]

[ext_resource type="Texture2D" uid="uid://wgxu371svj7a" path="res://assets/tilemap/dark_forest/ground_tile_forest.png" id="1_c27w2"]
[ext_resource type="Texture2D" uid="uid://ddxbiuy8h5xfc" path="res://assets/tilemap/dark_forest/ground_tile_forest_2.png" id="2_wot7k"]
[ext_resource type="Texture2D" uid="uid://cda1dv18ntql7" path="res://assets/tilemap/dark_forest/ground_tile_forest_3.png" id="3_qtvd6"]
[ext_resource type="Texture2D" uid="uid://7462qckh0dm0" path="res://assets/tilemap/dark_forest/forest_border.png" id="4_qyqqg"]
[ext_resource type="Texture2D" uid="uid://cx38e3i56ehqr" path="res://assets/tilemap/dark_forest/radio_tower.png" id="5_wot7k"]

[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_xgu0i"]
Expand All @@ -21,13 +20,6 @@ texture = ExtResource("3_qtvd6")
texture_region_size = Vector2i(256, 256)
0:0/0 = 0

[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_8rxff"]
texture = ExtResource("4_qyqqg")
texture_region_size = Vector2i(256, 256)
0:0/0 = 0
0:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-128, -128, 128, -128, 128, 128, -128, 128)
0:0/0/custom_data_0 = true

[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_qtvd6"]
texture = ExtResource("5_wot7k")
texture_region_size = Vector2i(256, 256)
Expand All @@ -37,10 +29,7 @@ texture_region_size = Vector2i(256, 256)
[resource]
tile_size = Vector2i(256, 256)
physics_layer_0/collision_layer = 2
custom_data_layer_0/name = "border"
custom_data_layer_0/type = 1
sources/0 = SubResource("TileSetAtlasSource_xgu0i")
sources/1 = SubResource("TileSetAtlasSource_8t3po")
sources/2 = SubResource("TileSetAtlasSource_g0o67")
sources/3 = SubResource("TileSetAtlasSource_8rxff")
sources/4 = SubResource("TileSetAtlasSource_qtvd6")