diff --git a/box.tres b/box.tres new file mode 100644 index 0000000..35813f1 --- /dev/null +++ b/box.tres @@ -0,0 +1,10 @@ +[gd_resource type="BoxMesh" load_steps=2 format=3 uid="uid://dlg5x0pi6xfnf"] + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ig7tw"] +transparency = 1 +albedo_color = Color(0.858824, 0.52549, 0.32549, 0.784314) +metallic_specular = 0.0 + +[resource] +lightmap_size_hint = Vector2i(9, 13) +material = SubResource("StandardMaterial3D_ig7tw") diff --git a/goal.tres b/goal.tres new file mode 100644 index 0000000..22644ad --- /dev/null +++ b/goal.tres @@ -0,0 +1,22 @@ +[gd_resource type="QuadMesh" load_steps=4 format=3 uid="uid://qxdm8y8lm754"] + +[sub_resource type="Gradient" id="Gradient_qb4hq"] +interpolation_mode = 1 +offsets = PackedFloat32Array(0, 0.373134) +colors = PackedColorArray(0.345925, 0.659465, 0.817842, 1, 1, 1, 1, 1) + +[sub_resource type="GradientTexture2D" id="GradientTexture2D_5y0qn"] +gradient = SubResource("Gradient_qb4hq") +width = 512 +height = 512 +fill = 1 +fill_from = Vector2(0.5, 0.5) +fill_to = Vector2(1, 1) + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_66cou"] +albedo_texture = SubResource("GradientTexture2D_5y0qn") +metallic_specular = 0.0 + +[resource] +material = SubResource("StandardMaterial3D_66cou") +orientation = 1 diff --git a/main.gd b/main.gd index 696aef7..ce2e3c9 100644 --- a/main.gd +++ b/main.gd @@ -12,11 +12,33 @@ var microban_1 := " var states: Array[State] = [State.from_string(microban_1)] +const WALL = preload("res://wall.tres") +const GOAL = preload("res://goal.tres") +const BOX = preload("res://box.tres") + +@onready var board: Node3D = $Board + func _ready() -> void: render() +func add_mesh(pos: Vector2i, mesh: Mesh): + var offset := -current_state().dims/2.0 + var meshinst := MeshInstance3D.new() + meshinst.position = Vector3(pos.x + offset.x, 0, pos.y + offset.y) + meshinst.mesh = mesh + board.add_child(meshinst) + func render() -> void: - print(current_state()) + var state := current_state() + for child in board.get_children(): + child.free() + + for y in state.dims.y: + for x in state.dims.x: + var pos := Vector2i(x, y) + if state.goal_at(pos): add_mesh(pos, GOAL) + if state.box_at(pos): add_mesh(pos, BOX) + if state.wall_at(pos) or pos == state.player_pos: add_mesh(pos, WALL) func _input(event: InputEvent) -> void: if event.is_action_pressed("u"): diff --git a/main.tscn b/main.tscn index f205375..2e3e903 100644 --- a/main.tscn +++ b/main.tscn @@ -1,15 +1,25 @@ -[gd_scene load_steps=3 format=3 uid="uid://lrk2whqxl0w0"] +[gd_scene load_steps=5 format=3 uid="uid://lrk2whqxl0w0"] [ext_resource type="Script" uid="uid://c707s0tgd88pg" path="res://main.gd" id="1_ig7tw"] -[sub_resource type="BoxMesh" id="BoxMesh_0xm2m"] -size = Vector3(0.5, 0.5, 0.5) +[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_ig7tw"] +ground_bottom_color = Color(0.270778, 0.538085, 0.397052, 1) + +[sub_resource type="Sky" id="Sky_0xm2m"] +sky_material = SubResource("ProceduralSkyMaterial_ig7tw") + +[sub_resource type="Environment" id="Environment_ig7tw"] +background_mode = 2 +sky = SubResource("Sky_0xm2m") [node name="Main" type="Node3D"] script = ExtResource("1_ig7tw") [node name="Camera3D" type="Camera3D" parent="."] -transform = Transform3D(1, 0, 0, 0, 0.707107, 0.707107, 0, -0.707107, 0.707107, 0, 2.56036, 1.68081) +transform = Transform3D(1, 0, 0, 0, 0.258819, 0.965926, 0, -0.965926, 0.258819, 0, 3.48438, 1.16423) +fov = 90.0 -[node name="MeshInstance3D" type="MeshInstance3D" parent="."] -mesh = SubResource("BoxMesh_0xm2m") +[node name="WorldEnvironment" type="WorldEnvironment" parent="."] +environment = SubResource("Environment_ig7tw") + +[node name="Board" type="Node3D" parent="."] diff --git a/project.godot b/project.godot index e7cb3c5..0bfe01b 100644 --- a/project.godot +++ b/project.godot @@ -15,6 +15,11 @@ run/main_scene="uid://lrk2whqxl0w0" config/features=PackedStringArray("4.4", "GL Compatibility") config/icon="res://icon.svg" +[display] + +window/size/viewport_width=1280 +window/size/viewport_height=720 + [input] u={ diff --git a/state.gd b/state.gd index 6fcf9c8..969b2bd 100644 --- a/state.gd +++ b/state.gd @@ -45,7 +45,13 @@ static func from_string(src: String) -> State: return state func solid_at(pos: Vector2i) -> bool: - return walls.get_bitv(pos) or boxes.get_bitv(pos) + return wall_at(pos) or box_at(pos) + +func wall_at(pos: Vector2i) -> bool: + return walls.get_bitv(pos) + +func goal_at(pos: Vector2i) -> bool: + return goals.get_bitv(pos) func box_at(pos: Vector2i) -> bool: return boxes.get_bitv(pos) diff --git a/wall.tres b/wall.tres new file mode 100644 index 0000000..f48455a --- /dev/null +++ b/wall.tres @@ -0,0 +1,11 @@ +[gd_resource type="BoxMesh" load_steps=2 format=3 uid="uid://b36l7brqc2lml"] + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ig7tw"] +transparency = 1 +albedo_color = Color(0.458824, 0.34902, 0.317647, 0.784314) +metallic_specular = 0.0 + +[resource] +lightmap_size_hint = Vector2i(9, 13) +material = SubResource("StandardMaterial3D_ig7tw") +size = Vector3(1, 1.2, 1)