diff --git a/assets/resources/fence_fortified.png b/assets/resources/fence_fortified.png new file mode 100644 index 0000000..72a9fa5 Binary files /dev/null and b/assets/resources/fence_fortified.png differ diff --git a/assets/resources/fence_fortified.png.import b/assets/resources/fence_fortified.png.import new file mode 100644 index 0000000..08653b0 --- /dev/null +++ b/assets/resources/fence_fortified.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cx3x4l20q17xh" +path="res://.godot/imported/fence_fortified.png-1ae65c603e478020bc26d4e987d66517.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/resources/fence_fortified.png" +dest_files=["res://.godot/imported/fence_fortified.png-1ae65c603e478020bc26d4e987d66517.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/assets/scene_props/fence_fortified.tscn b/assets/resources/fence_fortified.tscn similarity index 100% rename from assets/scene_props/fence_fortified.tscn rename to assets/resources/fence_fortified.tscn diff --git a/data/items/fence_fortified.tres b/data/items/fence_fortified.tres new file mode 100644 index 0000000..5d97213 --- /dev/null +++ b/data/items/fence_fortified.tres @@ -0,0 +1,12 @@ +[gd_resource type="Resource" script_class="Item" load_steps=4 format=3 uid="uid://c714vj3s6cnqg"] + +[ext_resource type="Texture2D" uid="uid://cx3x4l20q17xh" path="res://assets/resources/fence_fortified.png" id="1_hyv8l"] +[ext_resource type="Script" path="res://model/item.gd" id="1_u43c0"] +[ext_resource type="PackedScene" uid="uid://dv60qx8nqw3vg" path="res://assets/resources/fence_fortified.tscn" id="2_8ttdv"] + +[resource] +script = ExtResource("1_u43c0") +name = "" +scene = ExtResource("2_8ttdv") +icon = ExtResource("1_hyv8l") +max_stack_size = 64 diff --git a/data/recipes/fence_fortified.tres b/data/recipes/fence_fortified.tres new file mode 100644 index 0000000..761ed30 --- /dev/null +++ b/data/recipes/fence_fortified.tres @@ -0,0 +1,12 @@ +[gd_resource type="Resource" script_class="Recipe" load_steps=5 format=3 uid="uid://dtlb5wp5shlm3"] + +[ext_resource type="Script" path="res://model/recipe.gd" id="1_h0rj4"] +[ext_resource type="Resource" uid="uid://bn5j38jbwlj1f" path="res://data/items/stick.tres" id="1_i6g7d"] +[ext_resource type="Resource" uid="uid://dmjr6pmb17l2y" path="res://data/items/woodplanks.tres" id="2_d54b6"] +[ext_resource type="Resource" uid="uid://c714vj3s6cnqg" path="res://data/items/fence_fortified.tres" id="3_bsd6g"] + +[resource] +script = ExtResource("1_h0rj4") +name = "Fence Fortified" +ingredients = Array[Resource("res://model/item.gd")]([ExtResource("1_i6g7d"), ExtResource("1_i6g7d"), ExtResource("2_d54b6")]) +results = Array[Resource("res://model/item.gd")]([ExtResource("3_bsd6g")]) diff --git a/objects/player.gd b/objects/player.gd index 46280c8..f2552cd 100644 --- a/objects/player.gd +++ b/objects/player.gd @@ -1,12 +1,13 @@ class_name Player extends CharacterBody3D -const SPEED = 4.0 +const SPEED = 3.0 const JUMP_VELOCITY = 2.5 @onready var geometry:Node3D = %Geometry @onready var actionable_detector = %ActionableDetector @onready var animation_tree:AnimationTree = $Geometry/Rogue/AnimationTree +@onready var build_location:Node3D = %BuildLocation # Get the gravity from the project settings to be synced with RigidBody nodes. var gravity = ProjectSettings.get_setting("physics/3d/default_gravity") @@ -65,7 +66,7 @@ func on_item_picked_up(item:Item): func get_actionable_global_transform() -> Vector3: - return actionable_detector.global_position + return build_location.global_position func _unhandled_input(_event: InputEvent) -> void: if Input.is_action_just_pressed("ui_accept"): diff --git a/objects/player.tscn b/objects/player.tscn index e513e79..185dd41 100644 --- a/objects/player.tscn +++ b/objects/player.tscn @@ -45,7 +45,11 @@ collision_mask = 16 [node name="CollisionShape3D" type="CollisionShape3D" parent="Geometry/ActionableDetector"] shape = SubResource("SphereShape3D_wrkyq") +[node name="BuildLocation" type="Node3D" parent="Geometry"] +unique_name_in_owner = true +transform = Transform3D(2.5, 0, 0, 0, 2.5, 0, 0, 0, 2.5, 0, 0, 2.4682) + [node name="Camera3D" type="Camera3D" parent="."] unique_name_in_owner = true -transform = Transform3D(1, 0, 0, 0, 0.460138, 0.887848, 0, -0.887848, 0.460138, 0, 2.91421, 1.186) +transform = Transform3D(1, 0, 0, 0, 0.639707, 0.768619, 0, -0.768619, 0.639707, 0, 2.23862, 1.4653) current = true diff --git a/scenes/game.tscn b/scenes/game.tscn index e3a6662..60d6ded 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=8 format=3 uid="uid://cqie4cy0uy1t0"] +[gd_scene load_steps=9 format=3 uid="uid://cqie4cy0uy1t0"] [ext_resource type="PackedScene" uid="uid://ch0s3dxx3rpir" path="res://objects/player.tscn" id="2_rjgxk"] [ext_resource type="Script" path="res://systems/QuestSystem.gd" id="4_8oxap"] [ext_resource type="Script" path="res://systems/BuildSystem.gd" id="4_iqdys"] +[ext_resource type="Resource" uid="uid://c714vj3s6cnqg" path="res://data/items/fence_fortified.tres" id="5_ii2f8"] [ext_resource type="PackedScene" uid="uid://dmagdl5pi6jdj" path="res://world/level.tscn" id="6_svjo8"] [sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_y65pc"] @@ -35,5 +36,12 @@ script = ExtResource("4_8oxap") [node name="BuildSystem" type="Node" parent="."] script = ExtResource("4_iqdys") +build_item = ExtResource("5_ii2f8") + +[node name="BuildPreview" type="Node3D" parent="BuildSystem"] +unique_name_in_owner = true + +[node name="BuiltStructures" type="Node" parent="BuildSystem"] +unique_name_in_owner = true [editable path="Player"] diff --git a/systems/BuildSystem.gd b/systems/BuildSystem.gd index b3e5ab1..f625599 100644 --- a/systems/BuildSystem.gd +++ b/systems/BuildSystem.gd @@ -1,14 +1,37 @@ class_name BuildSystem extends Node +@onready var build_preview = %BuildPreview @onready var player = %Player +@onready var built_structures = %BuiltStructures + +@export var build_item:Item = null # Called when the node enters the scene tree for the first time. func _ready(): pass # Replace with function body. +func update_build_preview_item() -> void: + for child in build_preview.get_children(): + if build_item == null or child.scene_file_path != build_item.scene.resource_path: + child.get_parent().remove_child(child) + child.queue_free() + + if build_preview.get_child_count() == 0 and build_item != null: + build_preview.add_child(build_item.scene.instantiate()) + # Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(delta): +func _physics_process(_delta): + update_build_preview_item() + var build_location:Vector3 = player.get_actionable_global_transform() - build_location = Vector3(roundf(build_location.x), build_location.y, roundf(build_location.z)) + build_location = Vector3(roundf(build_location.x * 2), build_location.y, roundf(build_location.z * 2)) * 0.5 + build_preview.global_position = build_location + + if build_item != null and Input.is_action_just_pressed("interaction"): + var new_structure:Node3D = build_item.scene.instantiate() + new_structure.transform = build_preview.transform + built_structures.add_child(new_structure) + get_viewport().set_input_as_handled() + return